Problemmulti branch library circulation

Session: Sign in to solve

Solution.txt

Archive Box Circulation

Problem

Design ArchiveBoxCirculation for a library network that lends physical archive boxes to researchers. Each box belongs to one branch when available, remains associated with that branch while borrowed, and may be returned to a different branch. Calls are sequential on one shared instance.

Requirements

  • Initialize inventory. Construction assigns box boxIds[i] the state (initialBranchIds[i], available).
  • Borrow a box. borrow(boxId) changes that box from (branchId, available) to (branchId, borrowed).
  • Return a box. returnBox(boxId, branchId) changes that box from (previousBranchId, borrowed) to (branchId, available).
  • Observe availability. isAvailable(boxId, branchId) returns whether that box's state is exactly (branchId, available).

API

SignatureReturnsBehavior
ArchiveBoxCirculation(branchIds: string[], boxIds: string[], initialBranchIds: string[])Not applicablePerforms the initialization transition.
borrow(boxId: string)voidPerforms the borrow transition.
returnBox(boxId: string, branchId: string)voidPerforms the return transition.
isAvailable(boxId: string, branchId: string)booleanEvaluates the availability query.

Examples

Starting with branches ["north", "south"], boxes ["BX-1"], and initial branches ["north"]:

StepOperationResult
1isAvailable("BX-1", "north")true
2borrow("BX-1")No return value
3isAvailable("BX-1", "north")false
4returnBox("BX-1", "south")No return value
5isAvailable("BX-1", "south")true

Constraints

  • 1 <= branchIds.length <= 10
  • 1 <= boxIds.length <= 20
  • A testcase contains at most 50 method calls.
  • Every ID matches [A-Za-z0-9_-]{1,32}.
  • branchIds and boxIds contain unique values.
  • boxIds and initialBranchIds have equal lengths.
  • Every referenced branch is present in branchIds.
  • Every method argument is nonempty and names a configured box or branch.
  • Every borrow names an available box.
  • Every returnBox names a borrowed box.

Notes

All calls satisfy the constraints. Behavior outside these preconditions is unspecified and is not judged.

PRIVATE WORKSPACE

Checking your session…

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