Dataford
Interview QuestionsInterview GuidesExperiencesCoaching
New
Pricing
Get started
Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
Experiences
Practice
Mock InterviewsTimed interview simulations with feedbackCoaching1:1 coaching with people at your target companiesSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Build my plan
Find Home from GPS Clusters
00:00
5 left

Find Home from GPS Clusters

HardPython

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):
Interviewer

Your question is Find Home from GPS Clusters. Start with the requirements in the Question tab.

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.
CodePython 3
Sign up free to run your codeLog inLn 2
Run your code to see test output here.