FunctionRacerProblemsRace

To-Do List by Priority

EasyClassesPython, JavaScript, TypeScript, Java, C++

Implement a class TodoList that hands out tasks by priority. Write these methods:

add_task is never called with the name of a task that is still on the list, but a name may be added again after its task is gone. The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor.

Example 1

TodoList()
add_task("mail", 2) returns 1
add_task("cook", 5) returns 2
add_task("gym", 5) returns 3
peek_task() returns "cook"
next_task() returns "cook"
drop_task("mail") returns true
drop_task("mail") returns false
next_task() returns "gym"
next_task() returns ""

cook and gym share the top priority 5; cook was added first, so it goes first. After mail is dropped, gym is next, and then the list is empty.

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