All practice tasks

Coding (Algo)

Recorded Route Distance

Geometry · Easy

An offline tracker stores integer grid coordinates in visit order. The summary needs the travelled Manhattan distance, not displacement from the start.

Sum distances between adjacent recorded points.

Input

Call

  • Implement solve(input) and return its result. Do not print from solve.

Input object

{ points:[x:integer,y:integer][] }

What each field means

  • points — recorded [x, y] coordinates in travel order.

Output

Return value and rules

  • Return the sum of Manhattan distances between adjacent points: abs(dx) + abs(dy).
  • Do not use straight-line Euclidean distance or close the route automatically.
  • Fewer than two points return 0.

Constraints

  • 0 <= points.length <= 100000
  • Coordinates in [-1000000,1000000]; repeated positions are allowed.

Examples

Example 1

{
  "points": [
    [
      0,
      0
    ],
    [
      3,
      4
    ],
    [
      0,
      0
    ]
  ]
}

Returns

14

Example 2

{
  "points": []
}

Returns

0

Required complexity

O(n) time and O(1) auxiliary space

What this task practices

Recorded Route Distance is a coding (algo) interview exercise that trains prompt interpretation, explicit assumptions, a concrete response, and a clear explanation of tradeoffs. The catalog marks it as easy difficulty. It focuses on Technical Reasoning, Testing, Validation. The signed-in workspace provides the tools for the round and evaluates the attempt against task-specific criteria. Reference solutions, hidden checks, evaluator instructions, and candidate work remain private.

Sign in to startThe workspace and evaluation open after sign in.