A playlist is a row of n track codes. You want to demote every copy of one specific code x to the very end of the playlist, while every other track keeps its original relative order. Output the resulting playlist. (All the demoted copies of x sit together at the end.)
Line 1: an integer n.
Line 2: n space-separated integers, the track codes in order.
Line 3: an integer x, the code to demote.
One line: the n track codes after moving every x to the end, space-separated.
Example 1
Input
6 4 1 4 2 4 3 4
Expected
1 2 3 4 4 4
Explanation
Non-4 codes keep their order (1, 2, 3) and the three 4s move to the end: 1 2 3 4 4 4.
Example 2
Input
4 7 8 9 5 6
Expected
7 8 9 5
Explanation
The code 6 does not appear, so the playlist is unchanged: 7 8 9 5.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →