Given a queue of songs(array of size n). A random value k is passed which can be less than or equal to n. You need to play(print) song at kth position, remove it and add it at the end of the queue.
Example:
Song Queue(Array): [A, B, C, D, E, F, G, H, I, J]
1. k = 3
Song at 3rd position, C played(Print) then added at the end of the Queue. Queue becomes
[A, B, D, E, F, G, H, I, J, C]
2. k = 5
F played. Queue becomes
[A, B, D, E, G, H, I, J, C, F]
3. k = 2
B played. Queue becomes
[A, D, E, G, H, I, J, C, F, B]
4. k = 8
C played. Queue becomes
[A, D, E, G, H, I, J, F, B, C]
5. k = 10
C played. Queue becomes
[A, D, E, G, H, I, J, F, B, C]
Time Expectations:
O(1) when selecting a song
O(1) when removing a song from the queue.
O(1) when adding a song back to end of the queue.