FunctionRacerProblemsRace

Take a Number

BeginnerClassesPython, JavaScript, TypeScript, Java, C++

Implement a class TicketDesk for a waiting room in which people take numbered tickets and are called in the order of their numbers. Write these methods:

The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor.

Example 1

TicketDesk()
take() returns 1
take() returns 2
count_waiting() returns 2
call_next() returns 1
is_waiting(1) returns false
is_waiting(2) returns true
call_next() returns 2
call_next() returns -1

Tickets 1 and 2 are handed out, so two people wait. Ticket 1 is called: it is not waiting any more, but ticket 2 still is. Then ticket 2 is called, and after that nobody is left, so the last call returns -1.

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