Data Structures & AlgorithmsHardTCS NQT · Accenture

A robot starts at (0, 0) and performs the moves L, U, R, R, D, D, L, U, U, R, R. Moves L/R change x, U/D change y. What is the Manhattan distance |x| + |y| from the origin after all moves?

  1. A. 4
  2. B. {C-2}
  3. C. 6
  4. D. 3

Correct answer: D. 3

Horizontal moves net to x = +2 and vertical moves net to y = +1, so the distance is 3. Mixing the axes gives a wrong total.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic