AI InterviewSearch…Search problems, topics, or pages…Ctrl KGet started
Skip to content

03 Parking lot / Checkpoint

Checkpoint — Parking lot

30 min · +25 XP · 1 exercise · 10 questions

Exercise0/1
Quiz · 70% to clear10 q

This checkpoint covers the module: composition of lot, levels and spots; a vehicle type that carries the size it needs; the vehicle factory; best-fit allocation; tickets; and a pricing strategy that can be switched while the lot runs.

How it works. Ten questions and one program. You need 70% on the questions and the program accepted to clear the module.

The program puts both lesson programs together: several levels, best fit, tickets with entry hours, and hourly or flat pricing. Before you code, check your design against these:

  • Which class decides which spot, and which decides how much?
  • Where is the rule "a car fits a medium or large spot" written — once?
  • What does park return when nothing fits, and what does it throw?

Hidden cases switch the tariff between two departures, fill a level so a vehicle moves up, and charge a vehicle that leaves in the hour it arrived.

Common questions

Which patterns does a parking lot design use?

Strategy twice — one interface chooses the spot and another prices the stay — and a Factory that turns a vehicle type into a vehicle and refuses unknown ones. The lot depends only on the two interfaces, so new rules arrive as new classes.

How do you stop two cars taking the last spot at once?

Make finding a spot and taking it a single atomic step, with a lock in one process or a conditional update in a database. The second caller then sees the spot taken and gets another one or none.

Parking Lot LLD Quiz: Strategy, Factory and Best-Fit Practice

Practise parking lot design: ten questions on composition, the Strategy and Factory patterns, fees and concurrency, plus a multi-level lot with tariffs to code.

Checkpoint — Parking lot is the checkpoint that closes the Parking lot module: a graded quiz and whole-program exercises, passed at 70%.

Instructions

This checkpoint covers the module: composition of lot, levels and spots; a vehicle type that carries the size it needs; the vehicle factory; best-fit allocation; tickets; and a pricing strategy that can be switched while the lot runs.

How it works. Ten questions and one program. You need 70% on the questions and the program accepted to clear the module.

The program puts both lesson programs together: several levels, best fit, tickets with entry hours, and hourly or flat pricing. Before you code, check your design against these:

  • Which class decides which spot, and which decides how much?
  • Where is the rule "a car fits a medium or large spot" written — once?
  • What does park return when nothing fits, and what does it throw?

Hidden cases switch the tariff between two departures, fill a level so a vehicle moves up, and charge a vehicle that leaves in the hour it arrived.

Common questions

Which patterns does a parking lot design use?

Strategy twice — one interface chooses the spot and another prices the stay — and a Factory that turns a vehicle type into a vehicle and refuses unknown ones. The lot depends only on the two interfaces, so new rules arrive as new classes.

How do you stop two cars taking the last spot at once?

Make finding a spot and taking it a single atomic step, with a lock in one process or a conditional update in a database. The second caller then sees the spot taken and gets another one or none.

Exercise

A multi-level lot with fees

Put both programs together. The first line is the number of levels n, then n lines of spot ids. Spot ids start with their size — S1 small, M2 medium, L1 large. A bike fits any spot, a car a medium or large one, a truck only a large one. Allocation is best fit (lowest level, then smallest fitting spot, then the first listed); pricing starts hourly (BIKE 10, CAR 20, TRUCK 40 an hour, at least one hour) and can be switched.

CommandPrints
PARK <plate> <TYPE> <hour><plate> parked at level <L> spot <id> or no spot for <plate>
LEAVE <plate> <hour><plate> left level <L> spot <id>, paid <fee>
PRICING HOURLY / PRICING FLAT <amount>pricing: hourly / pricing: flat <amount>
STATUSlevel <L>: <k> free or level <L>: full for each level, joined by ,
EARNINGSearnings: <total>

Refusals print error: <reason>: unknown vehicle type <T>, <plate> is already parked, <plate> is not parked, unknown pricing <WORD>, unknown command <WORD>.

In this module: Parking lot

← Parking lot · Vending machine →