FastPrepMusic Player Operation Sequence

Music Player Operation Sequence

Atlassian logoAtlassian● MediumFULLTIMEPHONE SCREEN
Learn

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.

  • PLAY and PAUSE change the playback state when a track is selected.
  • NEXT advances 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 track NONE.
  • LOOP_ON and LOOP_OFF change the loop setting.
  • SHUFFLE:seed reorders only the waiting queue with Fisher-Yates. Starting with state = seed, for i from the last index down to 1, set state = (state * 1103515245 + 12345) mod 2^31 and swap positions i and state 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.

More Atlassian problems

See Atlassian hiring insights
public String[] simulatePlayer(String[] initialQueue, String[] operations) {
    // Write your code here.
}
initialQueue["A","B","C"]
operations["PLAY","NEXT","LOOP_ON","NEXT"]
expected["A|PLAYING|B,C", "B|PLAYING|C", "B|PLAYING|C", "C|PLAYING|B"]
Checking account…