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 hash map of 5 million records. To resolve this problem, we have to work on ranges
We are given ranges of phone numbers like
range1 start="9899123446" end="9912345678" location="a"
range2 start="9912345679" end="9999999999" location="b"
A number can belong to single location only.
We need a data structure to store these ranges in the memory.
It has to support two functions
- findLocation(Integer number) it should return the location name to which number belongs
- changeLocation( Integer Number , String range). It changes location of Number from old location to new location
This is completely in memory design.
I am planning to use tree structure with each node contains ( startofrange , endofrange ,location). I will keep the nodes in sorted order. I have not finalized anything yet. The main problem is-- when 2nd function to change location is called say 9899123448 location to b
The range1 node should split to 3 nodes 1st node (9899123446,9899123447,a)
2nd node (9899123448,9899123448,b)
3rd node (9899123449,9912345678,a)
.
Please suggest the suitable approach Thanks in advance