FunctionRacerProblemsRace

Playlist With Skip and Back

MediumClassesPython, JavaScript, TypeScript, Java, C++

Implement a class Playlist that plays songs from a queue and remembers what has been played. Write these methods:

The same song may appear more than once in the queue and in the history. The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor.

Example 1

Playlist()
enqueue("intro") returns 1
enqueue("blue") returns 2
enqueue("coda") returns 3
play_next() returns "intro"
skip() returns "blue"
play_next() returns "coda"
go_back() returns "intro"
get_current() returns "intro"
play_next() returns "coda"
go_back() returns "intro"
go_back() returns ""

blue is skipped, so the history holds intro and coda. Going back puts coda at the front of the queue and makes intro current; playing next brings coda back. The last go_back finds only one song in the history.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Classes problems