OpenAI

Verified interview challenge

Rebalance overlapping shard ranges

Rebalance a set of overlapping key ranges without leaving gaps in the data they cover.

Unlock with Full Access

The challenge

Several shards can own the same keys, but their overlap has a limit. Implement the rules for trimming ranges and repairing gaps while preserving the required ordering. The key space is large, so your solution needs to work with ranges efficiently.

What you'll practise

  • Overlapping intervals

    Track ownership across ranges that intersect.

  • Preserving coverage

    Keep the original key space covered as ranges change.

  • Efficient implementation

    Handle large coordinates without visiting every key.

Your coding workspacePreview
solution.pyPython 3.13
def rebalance(
    limit, shards
):
    # Your implementation goes here
    pass
Test cases

Run your code to see results.

Full instructions, starter code and test cases included with Full Access.