PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • medium
  • Oura
  • Coding & Algorithms
  • Software Engineer

Implement Server Number Allocation

Company: Oura

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

Implement a server number allocator for a data center. Servers have a string `type`, such as `"web"`, `"database"`, or `"cache"`. Each server type has its own independent namespace of positive integer server numbers starting from `1`. Design a class that supports the following operations efficiently: - `allocate(type: string) -> int`: Assign and return a server number for the given server type. - Return the smallest currently available positive integer for that type. - If no released number is available, assign the next new number for that type. - `release(type: string, number: int) -> void`: Release a previously allocated server number so it can be reused later for the same server type. Requirements: - Server numbers are independent across types. For example, `web` server `1` and `database` server `1` can both exist at the same time. - A number that is currently allocated must not be allocated again for the same type. - Released numbers should be reused before creating larger numbers, using the smallest available released number first. - Handle a large number of allocation and release requests efficiently. Example: ```text allocate("web") -> 1 allocate("web") -> 2 allocate("database") -> 1 release("web", 1) allocate("web") -> 1 allocate("web") -> 3 ```

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.

Simulate allocate and release operations for independent server-type namespaces, returning allocated numbers.

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

  1. Keep a min-heap of released numbers per type.
  2. Also track allocated numbers to ignore invalid releases.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.