Shard Rebalancing
Asked at OpenAI
Reported by the problem's creator, not verified
A cluster stores data in shards. Each shard has a unique string id and covers every integer key in an inclusive range [start, end]. Shards may overlap. A replication limit limit (an integer of at least 1) says each key may belong to at most limit shards.
Build Shards(limit).
Examples
Example 1
Input: init =
[1], operations =[["add_shard",["A",0,100]],["add_shard",["B",80,180]],["rebalance",[]],["get_shards",[]]]Output:
[null,null,null,[["A",0,100],["B",101,180]]]Explanation: Keys 80 to 100 are in both shards. Shard A starts first and keeps its range, so B starts at 101. The limit is 1, so each key may be in only one shard.
Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.