Reported March 2024
Amazonhash table

Get Distinct Pairs

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 March 2024 OA included 'Get Distinct Pairs', a deceptively simple problem that trips up candidates who overthink it. You're likely counting or generating pairs of elements that satisfy some constraint, and the word 'distinct' is doing more work than it seems. The pattern is usually hash-table logic combined with a counting or two-pointer pass. If you blank on the nuance of what 'distinct' means in context, StealthCoder reads the exact problem statement and walks you through the approach in real time.

Pattern and pitfall

This problem lives in the intersection of hash-table tracking and either counting or two-pointer techniques. The catch is always the definition of 'distinct': does it mean unique pairs, pairs with unique sums, pairs that don't repeat, or something else. Most candidates hash their way to a solution but miss an edge case on deduplication. The pattern typically involves storing seen pairs or elements in a set or dictionary, then iterating through candidates once or twice to find valid matches. A two-pointer variant is also common if the input is sorted or sortable. StealthCoder is your safety net if the problem wording is ambiguous or you can't remember whether order matters in the pair definition.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Get Distinct Pairs 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

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

Amazon reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Get Distinct Pairs FAQ

Does 'distinct pairs' mean (a, b) and (b, a) are the same?+

Almost always yes. Use a set to track pairs in canonical order, like (min, max) or lexicographic. If you hash both orderings, you'll double-count. Read the examples carefully; Amazon usually clarifies this implicitly.

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

Hash-table first. Store elements or partial results in a set or dict. Two-pointer appears if the input is sorted and you're searching for complements. Try hash-table first; it's the safer bet for 'distinct' logic.

What if the problem asks for the count vs. the actual pairs?+

Count is easier. Generate all valid pairs using a set to eliminate duplicates, return the size. If you need the pairs themselves, build a list and deduplicate before returning. The logic is the same; only the return type changes.

How do I handle edge cases like empty input or single elements?+

Edge cases here are minimal. Empty input returns 0 pairs or an empty list. Single element can't form a pair. A pair always needs at least two elements. Check the constraints; Amazon usually keeps input size reasonable.

If I have 48 hours, what should I focus on?+

Understand the exact definition of 'distinct' from examples. Write pseudocode using a set to deduplicate. Code a hash-table solution, test on the provided cases. Don't over-optimize. Clean, readable, correct beats clever.

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