Allocate the Nearest Free IP Address in a Cloud Subnet
Last updated: November 29, 2026
Quick Overview
Design an allocator for a VPC subnet range that supports allocate(hint), returning the smallest free address at or above the hint (wrapping to the lowest free if none), and release(address).
IBM
November 29, 20260
0
0 solved
Design an allocator for a VPC subnet range that supports allocate(hint), returning the smallest free address at or above the hint (wrapping to the lowest free if none), and release(address).
IBM Cloud VPC assigns private IPs from subnet pools, and users often request a preferred address. This ordered-set question checks whether you can keep free addresses sorted, use binary search for the successor query, and convert dotted IPv4 strings to integers.
What the Interviewer Expects
- Convert dotted IPv4 to integers and back
- Keep free addresses in a sorted structure
- Use binary search to find the successor of the hint
- Handle wraparound and exhaustion
- Discuss balanced BST or interval-based representations for large subnets
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you represent a /8 subnet without listing every address?
- How do you prevent double release?
- How would you make allocation safe across multiple API servers?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
The allocator is built with a first and last address (inclusive). allocate(hint) returns a dotted address string or None when full. release(addr) returns an address to the pool; releasing a free...
High-Level Design
Store free addresses as sorted integers. For allocate, bisect_left on the hint gives the first free address at or above it; if past the end, wrap to index 0. Remove it and return. For release, i...