Parking Lot With Spot Sizes
Implement a class ParkingLot with three kinds of spots: "small", "medium" and "large". Write these methods:
ParkingLot(small, medium, large)makes a lot with that many empty spots of each kind.park(plate, size)parks the car with licence plateplate, wheresizeis"small","medium"or"large". A small car fits any spot, a medium car fits a medium or a large spot, and a large car fits only a large spot. The car takes a spot of the smallest kind that fits it and still has room. Returns the kind of spot it took, or""if no spot that fits is free (then nothing changes).leave(plate)lets the car with that plate drive away, which frees its spot. Returns the kind of spot that was freed, or""if no car with that plate is parked.free_spots(kind)returns how many spots of the kindkindare empty.
park is never called with the plate of a car that is still parked, but a plate may park again after it has left. The tests call the methods in sequence and compare every return value. The expected list holds null for the constructor.
Example 1
ParkingLot(1, 1, 1)
park("A1", "small") returns "small"
park("B2", "small") returns "medium"
park("C3", "medium") returns "large"
park("D4", "large") returns ""
leave("B2") returns "medium"
park("E5", "medium") returns "medium"
free_spots("large") returns 0
leave("ZZ") returns ""
The second small car finds the small spot taken and moves up to the medium spot, which leaves only the large spot for the medium car C3. The large car D4 finds nothing. When B2 leaves, the medium spot is free for E5.
Constraints
0 <= small, medium, large <= 3plateis2to4uppercase letters or digits.sizeandkindare each"small","medium"or"large".- Each test makes
1to40method calls after the constructor.
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.