Count Pairs Whose Sum is Less than Target
A easy-tier problem at 87% community acceptance, tagged with Array, Two Pointers, Binary Search. Reported in interviews at josh technology and 1 others.
Count Pairs Whose Sum is Less than Target is an easy problem that shows up in assessments at Josh Technology and Accenture, with an 87% acceptance rate. Don't let the ease rating fool you. The trap is obvious: brute force nested loops works, but interviewers are testing whether you know the two-pointer trick. If you blank on that pattern during a live OA, StealthCoder runs invisibly and surfaces the optimal solution in seconds, cutting through the panic.
Companies that ask "Count Pairs Whose Sum is Less than Target"
Count Pairs Whose Sum is Less than Target is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by a senior engineer who knows the OA is theater. This is the script.
Get StealthCoderThe naive approach is O(n^2): check every pair. It passes, but it's the wrong answer to the real question being asked. The pattern here is sorting plus two pointers. Once sorted, you fix a pointer at the start and one at the end, then slide inward based on the sum. Each time the sum is under target, you count all valid pairs in one step instead of iterating. It's fast, it's clean, and it's the pattern that stays with you across similar problems. Most candidates see the array and jump to nested loops. The ones who studied two-pointer technique nail it in under a minute. If this problem hits your live assessment and you freeze on optimization, StealthCoder solves it while the proctor sees nothing.
Pattern tags
You know the problem.
Make sure you actually pass it.
Count Pairs Whose Sum is Less than Target recycles across companies for a reason. It's easy-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Count Pairs Whose Sum is Less than Target interview FAQ
Is this really an easy problem or are companies lying about difficulty?+
It's genuinely easy if you've drilled two pointers and sorting. The 87% acceptance rate confirms it. But easy doesn't mean interviewers skip it. Companies like Josh Technology and Accenture ask it because it's a fast checkpoint for whether you know the fundamental pattern.
Why would Accenture and Josh Technology ask this problem?+
Both companies hire for software roles where algorithmic basics matter. This problem tests whether you can spot the optimal approach from an easy setup. It's a signal about your pattern recognition and knowledge of two-pointer technique, not raw problem-solving skill.
What's the most common mistake candidates make?+
Staying with the brute force O(n^2) solution because it works and they're nervous about optimization. Two pointers requires sorted input and careful pointer movement. If you haven't practiced it, you'll code it wrong under pressure. That's when StealthCoder becomes your safety net.
Is sorting required or does binary search work better?+
Sorting plus two pointers is the standard. Binary search is listed in topics but it's a red herring for this specific problem. Sort the array, use two pointers, count in O(n log n) time. Binary search would add complexity without benefit here.
How do I practice this pattern so I get it right under time pressure?+
Run through the two-pointer pattern on sorted arrays until it's reflex: start at ends, move inward based on comparison, count or adjust as needed. This problem is the practice case itself. Once you've coded it three times without bugs, you own the pattern. That's your insurance for the live OA.
Want the actual problem statement? View "Count Pairs Whose Sum is Less than Target" on LeetCode →