MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / getCoordinates

Function getCoordinates

javascript/0853-car-fleet.js:19–30  ·  view source on GitHub ↗
(target, position, speed)

Source from the content-addressed store, hash-verified

17};
18
19var getCoordinates = (target, position, speed) =>
20 position
21 .map((_position, index) => [
22 _position,
23 speed[index],
24 ]) /* Time O(N) | Space O(N) */
25 .sort(
26 ([aPosition], [bPosition]) => aPosition - bPosition,
27 ) /* Time O(N * log(N)) | HeapSort Space 0(1) | QuickSort Space O(log(N)) */
28 .map(
29 ([_position, _speed]) => (target - _position) / _speed,
30 ); /* Time O(N) | Space O(N) */
31
32var searchAscending = (coordinates, stack = []) => {
33 for (const coordinate of coordinates) {

Callers 1

carFleetFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected