Beyond Big O

Task registry

Task registry

Medium

Part 1 only.

Solution guide

Reveal solution guide — spoilers

Approach

  1. Store records by ID and keep their insertion order separately.
  2. Check capacity, duplicates and legal transitions before changing state. Return detached snapshots rather than mutable internal records.
  3. Test rejected operations and confirm every later read still reflects the last accepted state.

Why it works

The ID map has one authoritative record per accepted task. Validating before mutation preserves that invariant when an operation is rejected, while copied snapshots prevent callers from changing registry state indirectly.

Complexity

Expected O(1) ID lookup and transitions; O(n) listing with O(n) registry storage, including snapshot output.

Edge cases to check

  • Empty registries return explicit missing values and empty lists.
  • Duplicate IDs and illegal or repeated transitions leave state unchanged.
  • Changing a returned record or list must not change later registry reads.
Editor options
Typing preferences

Saved in this browser.

Restoring local drafts…