Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Midpoint Between Two Endpoints

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

Your question is Midpoint Between Two Endpoints. 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

Hexagon Ab geometry tools such as HxGN visualization may represent points in 2D, 3D, or higher-dimensional coordinate space. Given two endpoints of a line segment, return the point exactly halfway between them.

Implement midpoint(point_a, point_b) using coordinate-wise averaging. The input points are lists of numeric values with the same positive dimension. For every coordinate i, the result must satisfy result[i] = (point_a[i] + point_b[i]) / 2.

Formal Specification

  • Input: Two lists point_a and point_b containing integers or floating-point values.
  • Output: A list of floating-point values representing the midpoint.
  • The input lists must have equal lengths. Do not mutate either input list.
  • Floating-point results are considered correct within an absolute error of 1e-9.

Constraints

  • 1 <= len(point_a) = len(point_b) <= 100000
  • -10^9 <= coordinate <= 10^9
  • Both points contain finite numeric values
  • The input points have the same dimension
  • Neither input list may be mutated

Function Signature

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