Hash ring slot ownership

Write codeEasy16 minAmazon style

Your task

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.

Examples

ring_segment_loads(node_names: list[str], node_positions: list[int], ring_size: int) -> list[int]
Example 1
Inputring_segment_loads(["alpha", "bravo", "charlie"], [10, 40, 90], 100)
Output[20, 30, 50]
Example 2
Inputring_segment_loads(["late", "early"], [90, 10], 100)
Output[80, 20]
Example 3
Inputring_segment_loads(["solo"], [7], 16)
Output[16]