Build a Most-Specific-Wins IP Range Geo Lookup Table

Last updated: November 29, 2026

Quick Overview

You receive IP ranges (as integers, inclusive) labeled with geo regions, where ranges may nest or overlap and the narrowest covering range should win. Preprocess them into a table that answers point lookups by binary search.

StackAdapt
Coding & Algorithms
Software Engineer
StackAdapt
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


You receive IP ranges (as integers, inclusive) labeled with geo regions, where ranges may nest or overlap and the narrowest covering range should win. Preprocess them into a table that answers point lookups by binary search.

Geo targeting in a StackAdapt campaign depends on resolving the bidder's IP to a country, region and city in microseconds, and vendor data often ships as overlapping ranges at different granularity. The screen checks sweep-line thinking and careful handling of inclusive boundaries.

What the Interviewer Expects
  • Turns overlapping ranges into disjoint elementary segments
  • Uses a sweep with a min-heap keyed by width to find the most specific active range
  • Removes expired ranges lazily
  • Merges adjacent segments with the same label
  • Answers queries with bisect in O(log S)
Key Topics to Cover
Sweep line
Heap
Binary search
Interval processing
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you handle IPv6 addresses?
  • If two ranges have the same width and overlap, how should ties be broken?
  • How would you ship a new table to every bidder host daily without a latency spike?
  • How would you compress the table to fit in L2 cache?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: (start, end, geo) with inclusive integer bounds. For any IP, the answer is the geo of the narrowest range containing it, or None. Build once, query millions of times, so heavy preprocessing i...

High-Level Design

Collect every start and end + 1 as boundary points. Between consecutive points the set of covering ranges is constant, so each gap is an elementary segment. Sweep the points in order: push ranges ...


Submit Your Answer
Markdown supported

Related Questions