I just went through a Google Hangout Interview.
Question:
We have one webserver which is serving large requests per second let's say 50K. Along with each request, we know the IP address of the connected user.
We have one database(you can assume any) which has information on the IP address range and its city name.
eg.
100.100.100.100 - 200.200.200.200 belongs to banglore.
101.100.100.100 - 201.200.200.200 belongs to mumbai.
We need to implement the function which has input as an IP address(IPv4) and output as city name.
As max 4 billion IP addresses are available in IPv4 so let's consider we have 1billion ranges (same city can have multiples ranges). How can we do a lookup in constant time?
Please share your most optimal approaches in the solution.