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.
- A. 11
- B. 18
- C. 108
- 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
- Problem: Intervals [1,4], [3,7] and [6,10] are available. What is the minimum number of these intervals needed to cover the whole segment…
- Problem: Starting from x = 7, apply six times the rule: if x is even, x = x/2 (integer), otherwise x = 2x + 3. What is the final value of x?
- Problem: The words of "the sky is blue" are put in reverse order and joined by single spaces to form a new string. How many characters…
- Problem: The array [1, 2, 3, 4, 5, 6, 7, 8] is rotated left by 3 and then the first 4 elements are reversed. What is the element at index…
- Problem: The string "abcdefgh" is cut into pieces of length 3 from the left (the last piece may be shorter). The pieces are then sorted…
- Problem: Let g(n) be the number of integers in [1, n] whose decimal digit sum is even. What is g(50)?