Beyond Big O

Task registry

Task registry

Medium

Your task

  • Build a small in-memory task registry.
  • Add(id, note) accepts a new ID while the registry holds fewer than 6 tasks, creates a pending task, and returns true.
  • Duplicate IDs or a full registry return false without changes; rejected IDs are not reserved.
  • Get returns an independent task snapshot or an explicit missing result.
  • List returns independent snapshots in insertion order.
  • Changing a returned task, list, or nested collection must not change the registry.
  • Keep separate registry instances independent.

Required API

  • NewRegistry
    func NewRegistry() *Registry
  • Registry.Add
    func (r *Registry) Add(id, note string) bool
  • Registry.Get
    func (r *Registry) Get(id string) (Task, bool)
  • Registry.List
    func (r *Registry) List() []Task
  • Registry.Transition
    func (r *Registry) Transition(id, status string) bool
  • Task.ID
    ID string
  • Task.Note
    Note string
  • Task.Status
    Status string

Behavior

  • Transition(id, status) returns true only for pending → running and running → done.
  • Missing IDs, repeated statuses and every other transition return false without changing state.
  • A done task is terminal.

Constraints

  • Inputs are valid: IDs are case-sensitive ASCII [A-Za-z0-9_-], 1–8 characters.
  • Notes contain 0–8 ASCII printable characters, newline, carriage return or tab.
  • Transition's status argument is any printable ASCII string of length 0–8; unsupported status names must return false.
  • A scenario contains at most 12 operations and at most two registry instances.
  • Use only the standard library; no threads, disk or network.
Notes and example notation
  • Examples encode snapshots as [id, note, status].
  • Each output position corresponds to one operation.
  • Get returns null for a missing ID.
  • The harness supports ["new"] to create/select a second registry and ["use", index] to return to an earlier registry; both produce null.

Examples

The runner calls your functions directly; you do not need to parse JSON.

Example 1 · empty

Calls in order; values are shown as data.
CallReturns
NewRegistry()
Instance 1
instance1.List()
Empty list
instance1.Get("missing")
Missing (found = false)
instance1.Transition("missing", "running")
false
Test data
Input
{"ops":[["list"],["get","missing"],["transition","missing","running"]]}
Expected output
[[],null,false]

Example 2 · records

Calls in order; values are shown as data.
CallReturns
NewRegistry()
Instance 1
instance1.Add("b", "B")
true
instance1.Add("a", "A")
true
instance1.Add("b", "new")
false
instance1.Get("a")
Task snapshot
ID: "a"
Note: "A"
Status: "pending"
found: true
instance1.List()
Task snapshot
ID: "b"
Note: "B"
Status: "pending"

Task snapshot
ID: "a"
Note: "A"
Status: "pending"
Test data
Input
{"ops":[["add","b","B"],["add","a","A"],["add","b","new"],["get","a"],["list"]]}
Expected output
[true,true,false,["a","A","pending"],[["b","B","pending"],["a","A","pending"]]]

Example 3 · transitions

Calls in order; values are shown as data.
CallReturns
NewRegistry()
Instance 1
instance1.Add("x", "")
true
instance1.Transition("x", "done")
false
instance1.Transition("x", "running")
true
instance1.Transition("x", "pending")
false
instance1.Transition("x", "running")
false
instance1.Transition("x", "done")
true
instance1.Transition("x", "running")
false
instance1.Get("x")
Task snapshot
ID: "x"
Note: ""
Status: "done"
found: true
Test data
Input
{"ops":[["add","x",""],["transition","x","done"],["transition","x","running"],["transition","x","pending"],["transition","x","running"],["transition","x","done"],["transition","x","running"],["get","x"]]}
Expected output
[true,false,true,false,false,true,false,["x","","done"]]
Editor options
Typing preferences

Saved in this browser.

Restoring local drafts…