FunctionRacerProblemsRace

Course Enrollment With a Waitlist

MediumClassesPython, JavaScript, TypeScript, Java, C++

Implement a class Course that enrolls students up to a capacity and keeps everyone else on a waitlist. Whenever fewer than capacity students are enrolled and someone is waiting, the first student on the waitlist is enrolled. 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

Course(1)
join("ana") returns "enrolled"
join("ben") returns "waitlisted"
join("cy") returns "waitlisted"
join("ben") returns "already"
drop("ana") returns "ben"
change_capacity(3) returns 1
get_roster() returns ["ben","cy"]
waitlist_spot("ana") returns -1

When ana drops, ben moves up from the waitlist. Raising the capacity to 3 makes room for cy as well, and ana is no longer in the course at all.

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