Fivetran SDE 2 Connectors interview question
Anonymous User
1276

Company - Fivetran
Position - SDE2
Interview round
Platform - hackerrank

Given a 2d plane, we are given n cars and their postion coordinates on the 2d plane in the form of an array.

I/P format : X[n] -> x-coordinates of n cars, Y[n] -> y coordinates of n cars

The objective of the problem is to bring all the cars on the same line parallel to the horizontal (x-axis) in 2d plane, with no gap between 2 cars. We are asked to achieve the objective with minimum fuel cost. The fuel cost for moving a car from (x1,y1) to (x2, y2) is
abs(x1-x2) + abs(y1-y2)

Note : no gap between cars mean that if car1 is parked at (x1, y) then the next car should be parked at (x1+1, y)

Comments (2)