Data Structures & AlgorithmsModerateTCS NQT · Infosys

Points (0,0), (1,2), (2,1), (3,3), (4,0) in the plane. How many unordered pairs have Manhattan distance exactly 3?

  1. A. 5
  2. B. 7
  3. C. 4
  4. D. 1

Correct answer: A. 5

Compute |dx| + |dy| for each of the ten unordered pairs and count the ones equal to 3. Euclidean distance of 3 is a different condition and gives another count.

More Coding Interview Problems questions

Exams that ask this topic