Data Structures & AlgorithmsModerateTCS NQT Digital · Product Company SDE

Problem: The k = 2 closest points to the origin are chosen from the list (1,3), (−2,2), (5,8), (0,1). Compute the sum of the squared distances (x² + y²) of those two closest points.

  1. A. 11
  2. B. 18
  3. C. 108
  4. D. 9

Correct answer: D. 9

Squared distances are 10, 8, 89, 1, so the two closest give 1 + 8 = 9. Ranking by |x| + |y| ties (1,3) with (−2,2) and may give 1 + 10 = 11, skipping (0,1) gives 18, and 108 sums all four.

More Coding Interview Problems questions

Exams that ask this topic