Problemshared fleet reservation desk

Session: Sign in to solve

Solution.txt

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

SignatureReturnsBehavior
FieldCartReservationDesk(cartIds: string[])A new FieldCartReservationDeskCreates an empty desk for the declared carts.
reserve(reservationId: string, cartId: string, slotId: string)voidStores the reservation ID at the addressed free pair.
cancel(cartId: string, slotId: string)voidRemoves the addressed occupied pair.
reservationAt(cartId: string, slotId: string)stringReturns the stored reservation ID or the empty string.

Examples

Given a desk constructed with ["CART_A"]:

CallResult
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

  • cartIds contains 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.

PRIVATE WORKSPACE

Checking your session…

The statement is public. The editor, editorial, submissions, and saved work are private.