As reported: Walmart Senior Software Engineer round 1 (2025): a stream of location coordinates
(lat, long)arrives. Support (1) returning the nearest 10 locations to given coordinates and (2) returning the top 5 hotspots.
Design and implement a class:
add(lat, long)— called for every location in the stream.nearest(lat, long)— the 10 stored locations closest to the given coordinates.topHotspots()— the 5 hotspots.
Clarifications
- Agree with the interviewer what a hotspot is before coding (for example, the areas with the most recorded locations).
- Agree on the distance measure (straight-line on small areas, or great-circle distance).