Instead of four unrelated puzzles, picture one place: a neighbourhood shopping mall. Every problem in this post is something you can see in that mall. Read the mall scene first (the "like I'm five" part), then the technical meaning, then the Java code, whose class and method names come straight from the scene.
| Where in the mall |
What it is in plain words |
The software concept |
| The basement |
Cars, bikes and buses need a place; you get a paper ticket and pay when you leave |
Parking lot (entities, strategy pattern for pricing) |
| The shop's small front shelf |
Holds only a few items; the most-asked-for ones stay close, the dusty ones go back to the store room |
LRU cache (the back store room is the database) |
| The food-court counter |
A bucket of meal tokens; each order takes one; the bucket slowly refills |
Token-bucket rate limiter |
| The snack machine |
You put coins in, press a button, a snack drops, change comes back |
Vending machine (state machine) |
Where the analogy stops being accurate. A real mall has people who use judgement; software does exactly what the code says, including for the 3 a.m. edge case nobody imagined. A real shelf is looked after by one shopkeeper, but your cache will be hit by many threads at once, so locks matter. And a real food court does not refill tokens with a timer; our bucket will refill lazily by doing arithmetic when a customer shows up. We will point out each place the picture bends.
How a machine-coding round works
You get 60 to 90 minutes, a small problem statement, and an editor. There is no diagram to hand in: the interviewer wants working, runnable, extensible code and a conversation about it. The scoring is roughly: clarified requirements, sensible classes, clean separation of responsibilities, correct core flow, handled edge cases, and a plausible answer to "what if we add X?".
Follow the method from LLD foundations: clarify, list entities, assign responsibilities, code the happy path first, then edge cases. The code below is modern Java (17 or newer: record, switch expressions, var), compact, compiled and run with javac --release 17, and uses no external libraries. The second set of case studies covers more problems.
1. The mall basement (parking lot)
The scene, in simple words. Cars, motorbikes and buses drive down to the basement. A motorbike can squeeze into any space, a car needs a medium one or bigger, a bus needs a big one. At the gate a machine prints a ticket with the time. When you leave, you show the ticket, the machine counts the hours and tells you what to pay. If you lose the ticket or show an old one, the gate does not open.
What that means technically: vehicles and spots have sizes; a ticket links a vehicle to a spot and a start time; the fee comes from a rule (hours times a rate) that the mall can change without rebuilding the basement.
You've reached the free preview of this post.
Subscribe to the Blogs plan (₹99/mo) — or use any Algomi Suite, Career, Investor, or Trader plan — to keep reading.
See plans