Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA

Given the array [-1, 2, 1, -4, 6, 3] and target 1, pick three different elements whose sum is as close to 1 as possible. What is that closest sum?

  1. A. 2
  2. B. 4
  3. C. 1
  4. D. 6

Correct answer: C. 1

Sort, fix the first element, and move two pointers inward depending on whether the sum is below or above the target. The values 2, 3 and -4 sum to exactly 1, so the closest sum is the target itself; a pointer walk that stops early would miss this triple.

More Coding Interview Problems questions

Exams that ask this topic