Question bank › Arrays
Dsa Arrays Medium

Pair Sum with a Target

Given an array of integers and a target integer, determine if there exists a pair of distinct indices (i, j) such that arr[i] + arr[j] equals the target. Return the indices in a list, or -1 if no such pair exists. Input Format: - The first line contains an integer N (the number of elements in the array). - The second line contains N space-separated integers representing the elements of the array. - The third line contains an integer target. Output Format: - Print two space-separated integers, the indices of the two numbers that add up to the target, or -1 if no valid pair exists. Example: Input: 5 2 7 11 15 9 Output: 0 1

Key concepts

arraystwo pointersiteration

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.