Reported January 2024
Amazonhash table

Get Pairs Count

Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Amazon OA. Under 2s to a working solution.
Founder's read

Amazon's "Get Pairs Count" hit the OA circuit in January 2024, and candidates are still blanking on it. You've got an array, you need to count pairs that match some condition, and the brute force screams to your brain first. That's the trap. The trick lives in how you organize your data before you iterate. If you freeze during the live OA, StealthCoder will read the exact problem constraints and hand you the pattern in seconds so you're not guessing.

Pattern and pitfall

This is a hash-table or two-pointers problem dressed up as a counting task. The naive approach is O(n^2): check every pair. The real solution either builds a frequency map and counts valid complement pairs in one pass, or sorts the array and uses two pointers to converge. The common pitfall: overcounting or undercounting because you didn't account for duplicates or didn't lock your pointer movement correctly. Candidates often miss that the problem is asking for "pairs," not "elements," so a single value counted twice doesn't mean two pairs. When you're live and the constraint is fuzzy, StealthCoder becomes your safety net by clarifying exactly what "pair" means in context.

If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.

If this hits your live OA

You can drill Get Pairs Count cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as two sum. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Amazon's OA.

Amazon reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Get Pairs Count FAQ

Is this a hash-table or two-pointers problem?+

Usually both work. Hash-table is simpler if you need exact matches or complements (sum to target, etc.). Two-pointers works if the problem is about relative order or comparative pairs. Read the constraint carefully. If it says "any two distinct indices," hash-table shines. If it says "sorted or in order," two-pointers is cleaner.

What's the counting trap?+

Pairs are unordered. (i, j) and (j, i) are the same pair. Also, if an element appears twice, that's one pair of that element, not two. Many candidates iterate naively and count 2x. Use a frequency map or be surgical with pointer bounds.

Can I solve this in one pass?+

Yes, with a hash-table. Iterate once, store frequencies or seen elements, and count valid pairs as you go. Two-pointers requires a sort first, so it's technically O(n log n) preprocessing plus O(n) iteration. Hash-table is cleaner for one-pass.

What's the time complexity I should target?+

O(n) with a hash-table, or O(n log n) if you sort and use two-pointers. Amazon usually doesn't ask for sub-linear on this pattern. O(n^2) brute force will time out. Don't submit that.

How do I prepare in 48 hours?+

Understand the exact condition for a valid pair. Write the brute force first to confirm logic. Then optimize to hash-table or two-pointers. Test on duplicates and edge cases (empty array, one element). Time yourself. If you blank on the OA, that's why StealthCoder exists.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Amazon.

OA at Amazon?
Invisible during screen share
Get it