Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

Order Colors A string str contains a ist of color names that are separated by a single space. Colors in str are mixed up, but each color has ts original position at the end of the color name, positions are 1-indexed. For example, the string black1 gold2 w

Amjad Saeed answered on January 27, 2023 Popularity 2/10 Helpfulness 1/10

Contents


More Related Answers


Order Colors A string str contains a ist of color names that are separated by a single space. Colors in str are mixed up, but each color has ts original position at the end of the color name, positions are 1-indexed. For example, the string black1 gold2 w

0

You can solve this problem by first splitting the input string into a list of color strings. Then, you can create a dictionary where the keys are the positions and the values are the corresponding color names. Iterate through the list of color strings and extract the position from each string, using it as the key to store the color name in the dictionary. Finally, iterate through the dictionary in order of the keys and concatenate the color names to build the final string.

Popularity 2/10 Helpfulness 1/10 Language javascript
Source: Grepper
Link to this answer
Share Copy Link
Contributed on Jan 27 2023
Amjad Saeed
0 Answers  Avg Quality 2/10


X

Continue with Google

By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
X
Grepper Account Login Required

Oops, You will need to install Grepper and log-in to perform this action.