MEDIUMasked at 2 companies

Count Pairs in Two Arrays

A medium-tier problem at 60% community acceptance, tagged with Array, Two Pointers, Binary Search. Reported in interviews at Shopee and 1 others.

Founder's read

Count Pairs in Two Arrays looks straightforward until you hit the constraint: you need to count pairs where arr1[i] * arr2[j] > k across two arrays. Shopee and Teradata both ask this. The naive nested loop times out. You'll either sort and use two pointers, or binary search one array while iterating the other. The 60% acceptance rate reflects that most candidates see the problem, think O(n²), code it, watch it fail on large inputs, then scramble to optimize. If this problem hits your live assessment and you blank on the sort-and-pointer trick, StealthCoder surfaces a working solution in seconds, invisible to the proctor.

Companies asking
2
Difficulty
MEDIUM
Acceptance
60%

Companies that ask "Count Pairs in Two Arrays"

If this hits your live OA

Count Pairs in Two Arrays 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 an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code.

Get StealthCoder
What this means

The core pattern is recognizing that a direct pair count needs pruning. Once you sort both arrays, two pointers becomes natural: anchor one pointer and slide the other to find the boundary where the product inequality flips. The mistake candidates make is overthinking which array to sort first, or trying to binary search without understanding that you're looking for a threshold, not an exact match. Another trap is off-by-one errors when counting valid pairs after you find the boundary. Binary search works too, but requires careful index logic. The problem tests whether you can move beyond brute force to a linear or log-linear scan. Sorting alone is O(n log n); two pointers on sorted arrays is O(n) after that. StealthCoder is your hedge if the optimization pattern doesn't click under live pressure.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Count Pairs in Two Arrays recycles across companies for a reason. It's medium-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 an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Count Pairs in Two Arrays interview FAQ

Is this problem actually hard or just tedious?+

It's medium-hard because the optimization is the point. The naive approach is obvious and fails silently on large inputs. You must recognize that sorting unlocks a linear scan, not because sorting is clever, but because product inequalities have a monotonic property once sorted.

Do I really need to use both Two Pointers and Binary Search?+

No. Two pointers is faster and more intuitive once both arrays are sorted. Binary search works but adds log complexity for no gain. Pick two pointers and move on. Both are in the topics list because both are valid, but one is cleaner.

What's the most common mistake candidates make?+

Forgetting that after sorting, the number of valid pairs at a given position is contiguous. If arr2[j] satisfies the inequality with arr1[i], then arr2[j+1], arr2[j+2], etc. all satisfy it too. Not exploiting that symmetry means you re-scan instead of jump.

Is this still asked by Shopee and Teradata?+

Yes. Both companies have reported this problem. It's not trendy or flashy, but it's a clean medium-difficulty filter that separates candidates who optimize from those who don't. That's exactly what these hiring teams want.

How much time should I spend on this in a real OA?+

Spend 5-10 minutes understanding the constraint, 5 minutes on the sort-and-pointer approach, 10-15 minutes coding and testing edge cases. If you're still stuck after 20 minutes, you need the solution. That's when StealthCoder earns its place.

Want the actual problem statement? View "Count Pairs in Two Arrays" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.