Dsa
Sorting
Warm-up
Color Sorter
You are given a list of colors represented as strings. Your task is to sort these colors in the order of their appearance based on a predefined priority: ['red', 'green', 'blue']. If a color is not in the priority list, it should be placed at the end in the order of their first appearance. Print the sorted colors as a single line of space-separated values.
Example Input:
red
green
blue
yellow
red
orange
blue
Example Output:
red green blue red yellow orange
Key concepts
sortingarrayscounting
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now