Field Cart Reservation Desk
Problem
A field team shares a small fleet across named work slots. Design FieldCartReservationDesk to reserve one exact cart-slot pair, retrieve its reservation label, and free that pair when the reservation is cancelled.
Requirements
- Empty start. A new desk has no reservations.
- Open reservation. Reserving a free cart-slot pair stores the supplied reservation ID.
- Targeted cancellation. Cancelling a reservation removes the addressed occupied cart-slot pair.
- Occupied lookup. Looking up an occupied cart-slot pair returns its stored reservation ID.
- Free lookup. Looking up a free cart-slot pair returns the empty string.
API
| Signature | Returns | Behavior |
|---|---|---|
FieldCartReservationDesk(cartIds: string[]) | A new FieldCartReservationDesk | Creates an empty desk for the declared carts. |
reserve(reservationId: string, cartId: string, slotId: string) | void | Stores the reservation ID at the addressed free pair. |
cancel(cartId: string, slotId: string) | void | Removes the addressed occupied pair. |
reservationAt(cartId: string, slotId: string) | string | Returns the stored reservation ID or the empty string. |
Examples
Given a desk constructed with ["CART_A"]:
| Call | Result |
|---|---|
reservationAt("CART_A", "MORNING") | "" |
reserve("R1", "CART_A", "MORNING") | No return value |
reservationAt("CART_A", "MORNING") | "R1" |
cancel("CART_A", "MORNING") | No return value |
reservationAt("CART_A", "MORNING") | "" |
Constraints
cartIdscontains between 1 and 12 unique cart IDs.- At most 20 distinct slot IDs appear in one testcase.
- A testcase contains at most 40 method calls.
- Every identifier matches
[A-Za-z0-9_-]{1,24}. - Reservation IDs are unique within a testcase.
Notes
All calls are valid and sequential. reserve addresses a free pair, and cancel addresses an occupied pair. Calls outside these preconditions and invalid identifiers are outside the contract.