Dsa
Linked List
Easy
Circular Playlist Manager
You are designing a music player. The playlist is a circular singly linked list where the 'next' of the last song points back to the first. You start at the first song. You must process a series of commands:
- 'NEXT': Move the current pointer to the next song.
- 'PREV': Move the current pointer to the previous song (requires traversing the circle).
- 'REMOVE': Remove the current song from the list. The new current song becomes the one that was 'next' to the removed one. If the list becomes empty, further commands are ignored.
Input:
1. A line of space-separated strings (song titles).
2. An integer N (number of commands).
3. N lines each containing one command.
Output:
The final playlist starting from the current song, space-separated. If the list is empty, print 'EMPTY'.
Example:
Input:
A B C D
3
NEXT
REMOVE
PREV
Output:
D A C
Key concepts
linked_listcircular_pointersstate_simulation
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