Skip to content

Instantly share code, notes, and snippets.

Requirements:
1. Configuration is provided at startup (loaded once)
2. System receives requests with (clientId: string, endpoint: string)
3. Each endpoint has a configuration specifying:
- Algorithm to use (e.g., "TokenBucket", "SlidingWindowLog", etc.)
- Algorithm-specific parameters (e.g., capacity, refillRatePerSecond for Token Bucket)
4. System enforces rate limits by checking clientId against the endpoint's configuration
5. Return structured result: (allowed: boolean, remaining: int, retryAfterMs: long | null)
6. If endpoint has no configuration, use a default limit
@rahulmysuru
rahulmysuru / connect4.py
Last active April 24, 2026 06:07
connect 4
Requirements:
1. Two players take turns dropping discs into a 7-column, 6-row board
2. A disc falls to the lowest available row in the chosen column
3. The game ends when:
- A player gets four discs in a row (vertical, horizontal, or diagonal). They win.
- The board is full. It's a draw.
4. Invalid moves should be rejected clearly:
- Dropping in a full column.
- Moving out of turn.
- Moving after the game is over.
@rahulmysuru
rahulmysuru / movie_ticket.py
Created April 24, 2026 06:04
movie ticket booking
Requirements:
1. Users can search for movies by title
2. Users can browse movies playing at a given theater
3. Theaters have multiple screens; all screens share the same seat layout (rows A-Z, seats 0-20)
4. Users can view available seats for a showtime and select specific ones
5. Users can book multiple seats in a single reservation; booking returns a confirmation ID
6. Concurrent booking of the same seat: exactly one succeeds
7. Users can cancel a reservation by confirmation ID, releasing the seats
Out of Scope:
@rahulmysuru
rahulmysuru / elevator.py
Created April 24, 2026 05:56
elevator LLD
Requirements:
1. System manages 3 elevators serving 10 floors (0-9)
2. Users can request an elevator from any floor (hall call). System decides which elevator to dispatch.
3. Once inside, users can select one or more destination floors
4. Simulation runs in discrete time steps (e.g., a `step()` or `tick()` call advances time)
5. Elevator stops come in two types:
- Hall calls: Request from a floor with direction (UP or DOWN)
- Destination: Request from inside elevator (no direction specified)
@rahulmysuru
rahulmysuru / Amazon_locker.py
Last active April 24, 2026 05:50
Amazon locker LLD
Requirements:
1. Carrier deposits a package by specifying size (small, medium, large)
- System assigns an available compartment of matching size
- Opens compartment and returns access token, or error if no space
2. Upon successful deposit, an access token is generated and returned
- One access token per package
3. User retrieves package by entering access token
- System validates code and opens compartment
- Throws specific error if code is invalid or expired
4. Access tokens expire after 7 days
@rahulmysuru
rahulmysuru / Parking_lot.java
Created April 24, 2026 05:36
Parking lot LLD
// Requirements:
// -----------------------------------------------------------------------------------------
1. System supports three vehicle types: Motorcycle, Car, Large Vehicle
2. When a vehicle enters, system automatically assigns an available compatible spot
3. System issues a ticket at entry.
4. When a vehicle exits, user provides ticket ID
- System validates the ticket
- Calculates fee based on time spent (hourly, rounded up)
- Frees the spot for next use
5. Pricing is hourly with same rate for all vehicles