Dsa
Two Pointers
Hard
Closest Pair of Sum
Given an array of integers and a target integer, return the indices of two numbers such that they add up to the closest possible sum to the target. If multiple pairs have the same distance to the target, return the pair with the smallest indices. Input is a single line of space-separated integers followed by the target integer. Example input: '10 2 5 6 3 8 7 12 9 15 13
10'. Example output: '2 3'.
Key concepts
two_pointerssortingbinary_search
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now