Music Player Operation Sequence
Problem statement
Simulate a music player over a finite ordered command sequence. initialQueue[0] is initially selected, the remaining tracks wait in order, and playback starts paused.
PLAYandPAUSEchange the playback state when a track is selected.NEXTadvances to the first waiting track. With looping enabled, the previous current track moves to the end of the waiting queue; otherwise it is discarded. If no track remains, the player becomes paused with current trackNONE.LOOP_ONandLOOP_OFFchange the loop setting.SHUFFLE:seedreorders only the waiting queue with Fisher-Yates. Starting withstate = seed, forifrom the last index down to 1, setstate = (state * 1103515245 + 12345) mod 2^31and swap positionsiandstate mod (i + 1).
After every command, return current|PLAYING_OR_PAUSED|comma-separated-waiting-queue.
Function
simulatePlayer(initialQueue: String[], operations: String[]) → String[]Examples
Example 1
initialQueue = ["A","B","C"]operations = ["PLAY","NEXT","LOOP_ON","NEXT"]return = ["A|PLAYING|B,C","B|PLAYING|C","B|PLAYING|C","C|PLAYING|B"]The first NEXT discards A. After looping is enabled, advancing from B moves B to the back.
Example 2
initialQueue = ["A","B","C","D"]operations = ["SHUFFLE:1","NEXT","PAUSE"]return = ["A|PAUSED|D,C,B","D|PAUSED|C,B","D|PAUSED|C,B"]The deterministic shuffle reorders only B, C, and D. NEXT selects D without changing the paused state.
Constraints
1 <= initialQueue.length <= 5000.1 <= operations.length <= 5000.- Track names are nonempty, unique, printable ASCII strings without
|or commas. - Every command is one of the documented forms.
0 <= seed < 2^31.