Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Relative Velocity from Coordinates

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

Your question is Relative Velocity from Coordinates. 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

Given two vehicles moving in a 2D plane, each represented by two consecutive positions: (x1, y1) at time t1 and (x2, y2) at time t2, compute the relative velocity vector of the merging vehicle with respect to the ego vehicle. Return [rvx, rvy, speed], where rvx and rvy are the relative velocity components and speed is the magnitude of that relative velocity.

Constraints

  • dt > 0
  • Each vehicle is given by exactly two 2D points
  • -10^6 <= x, y <= 10^6
  • Coordinates may be integers or floating-point values

Function Signature

def relative_velocity(ego, merge, dt):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output