FunctionRacerProblemsRace

Bookcase With Gaps

HardClassesPython, JavaScript, TypeScript, Java, C++

Implement a class Bookcase. It has endless shelves numbered 0, 1, 2, ... from the top, and each shelf holds at most capacity books, standing in a row. Books are 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

Bookcase(2)
add(10) returns 0
add(20) returns 0
add(30) returns 1
take_from(0) returns 20
add(40) returns 0
take() returns 30
count_books() returns 2

With room for two per shelf, the books 10 and 20 fill shelf 0 and 30 goes to shelf 1. Taking from shelf 0 removes 20 and leaves a gap there, which the next book, 40, fills. The last book on the highest used shelf is still 30.

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