Dsa
Two Pointers
Warm-up
Count Unique Pairs
Given a sorted array of integers, write a function that counts the number of unique pairs (i, j) such that i < j and arr[i] + arr[j] is equal to a target value.
Input:
The first line contains space-separated integers of the array, followed by a single integer (the target value).
Output:
An integer representing the count of unique pairs.
Example:
Input:
1 2 3 4 5
6
Output:
2
(Pairs are (1, 5) and (2, 4).)
Key concepts
two_pointersarraysorting
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