Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Distance Between Two Points

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

Your question is Distance Between Two Points. 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

GM vehicle localization systems represent two positions on a two-dimensional coordinate plane. Given the coordinates of two points, calculate the straight-line Euclidean distance between them.

Implement the function distance_between_points, which receives four numeric coordinates and returns the distance as a floating-point number.

Formal Specification

  • Input: Four integers x1, y1, x2, and y2, representing points (x1, y1) and (x2, y2).
  • Output: A number equal to sqrt((x2 - x1)^2 + (y2 - y1)^2).
  • The result may be returned as an integer-valued float when the distance is a whole number.

Constraints

  • -10^9 <= x1, y1, x2, y2 <= 10^9
  • Coordinates are integers
  • The points may be identical
  • Return the Euclidean distance as a number

Function Signature

def distance_between_points(x1, y1, x2, y2):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output