Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Find Home from GPS Clusters

HardPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Find Home from GPS Clusters. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Domo may receive GPS coordinates extracted from images uploaded to Domo. Assume the coordinate with the greatest number of coordinates within a specified radius represents the user's home location.

Given a list of latitude and longitude pairs and a radius in meters, return the original coordinate with the largest neighborhood. A coordinate counts itself, and ties must be resolved by returning the coordinate that appears first in the input.

Formal Specification

Implement find_home_coordinate(coordinates, radius), where coordinates is a list of [latitude, longitude] pairs and radius is a positive number of meters. Return the original [latitude, longitude] pair with the greatest number of coordinates whose great-circle distance from it is at most radius.

Use Earth's radius as 6,371,000 meters. The comparison must use spherical distance, not Euclidean distance on raw latitude and longitude values.

Example 1:

Input: coordinates = [[0, 0], [0, 0.001], [0, 0.002], [10, 10]], radius = 150
Output: [0, 0.001]

The middle coordinate is within approximately 111 meters of both neighboring coordinates, so its neighborhood is largest.

Example 2:

Input: coordinates = [[0, 0], [0, 0.001], [10, 10], [10, 10.001]], radius = 120
Output: [0, 0]

Both local pairs have the same size, so the first coordinate wins the tie.

Constraints

  • 1 <= len(coordinates) <= 200,000
  • -90 <= latitude <= 90
  • -180 <= longitude <= 180
  • 1 <= radius <= 100,000 meters
  • Duplicate coordinates are allowed
  • Return the earliest coordinate when multiple coordinates have the same maximum count

Function Signature

def find_home_coordinate(coordinates, radius):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output