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
Distance Between Two Points in Python
00:00
5 left

Distance Between Two Points in Python

MediumSQL · PostgreSQL

Problem

Describe how you would compute the distance between two points in Python and explain what assumptions you make about the coordinate system.

Write a PostgreSQL query that applies the same reasoning to distance requests. A distance is valid only when both points and coordinates exist, both points use the same known coordinate system, and that system is Euclidean. Rows with missing or incompatible inputs must remain in the output with a status and a NULL distance.

Output

  1. One row per request, ordered by request_id ascending.
  2. Return request_id, point_a_id, point_b_id, coordinate_system_a, coordinate_system_b, distance_status, and distance.
  3. Round valid distances to 6 decimal places. Rows with missing coordinates or coordinate systems are included with a NULL distance.

Schema

distance_requests
ColumnTypeDescription
request_idPKINTUnique distance request identifier
point_a_idINTIdentifier of the first point
point_b_idINTIdentifier of the second point
points
ColumnTypeDescription
point_idPKINTUnique point identifier
coordinate_systemVARCHAR(20)Coordinate-system code
x_coordinateNUMERIC(12,4)Horizontal or first coordinate
y_coordinateNUMERIC(12,4)Vertical or second coordinate
coordinate_systems
ColumnTypeDescription
system_codePKVARCHAR(20)Coordinate-system code
system_nameVARCHAR(100)Human-readable coordinate-system name
unit_nameVARCHAR(30)Measurement unit used by the system
is_euclideanBOOLEANWhether straight-line Euclidean distance is appropriate
Tablesdistance_requestspointscoordinate_systems
Interviewer

Your question is Distance Between Two Points in Python. Start with the requirements and the three tables 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.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.