Hash ring slot ownership
A storage team is auditing how evenly a hash ring spreads load, before deciding whether virtual nodes are worth the trouble. The ring has ring_size slots, numbered 0 through ring_size - 1. Node node_names[i] sits at slot node_positions[i]. The positions are distinct, and they are not given in ring order. A key that lands on slot p is stored by the first node whose slot is greater than or equal to p, wrapping past the last slot back to slot 0. Return a list holding, for each node in the order it was given, how many of the ring slots that node owns. The counts add up to ring_size whenever at least one node is present. Return an empty list when no nodes are given.
ring_segment_loads(node_names: list[str], node_positions: list[int], ring_size: int) → list[int][["alpha","bravo","charlie"],[10,40,90],100]out[20,30,50][["late","early"],[90,10],100]out[80,20][["solo"],[7],16]out[16]State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
[["alpha","bravo","charlie"],[10,40,90],100][20,30,50]not run yetsample[["late","early"],[90,10],100][80,20]not run yetsample[["solo"],[7],16][16]not run yetsample