Implement Server Number Allocation
Company: Oura
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Take-home Project
Quick Answer: This question evaluates the ability to design efficient stateful data structures and algorithms for resource allocation, focusing on management of per-type namespaces and correct reuse of released identifiers.
Constraints
- Inputs are Python literals matching the function signature.
- Return a deterministic exact-match value.
Examples
Input: ([["allocate","web"],["allocate","web"],["allocate","database"],["release","web",1],["allocate","web"]],)
Expected Output: [1, 2, 1, 1]
Explanation: Namespaces are independent and released web 1 is reused.
Input: ([["release","web",1],["allocate","web"],["release","web",1],["release","web",1],["allocate","web"]],)
Expected Output: [1, 1]
Explanation: Invalid or duplicate releases are ignored.
Input: ([["allocate","cache"],["allocate","cache"],["release","cache",2],["release","cache",1],["allocate","cache"],["allocate","cache"]],)
Expected Output: [1, 2, 1, 2]
Explanation: The smallest released number is reused first.
Hints
- Keep a min-heap of released numbers per type.
- Also track allocated numbers to ignore invalid releases.