Data Structure to store Integer Range , Query the ranges and modify the ranges

后端 未结 2 606
离开以前
离开以前 2021-01-05 09:32

We need to maintain mobileNumber and its location in memory. The challenge is that we have more than 5 million of users and storing the location for each user will be like

2条回答
  •  醉酒成梦
    2021-01-05 10:11

    First of all range = [begin;end;location]

    Use two structures:

    • Sorted array to store ranges begins
    • Hash-table to access ends and locations by begins

    Apply following algo:

    1. Use binary search to find "nearest less" value ob begin
    2. Use hash-table to find end and location for begin

提交回复
热议问题