Reported June 2026
Amazonhash table

Frequently Bought Together

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

The mistake that sinks a first attempt at Amazon's Frequently Bought Together, reported in June 2026, is counting pairs per occurrence instead of per order. Duplicate SKUs inside one order must collapse to one. Skip that and your counts drift, your tie-break flips, and the sample passes while hidden tests fail. It's a hash-table counting problem with a sorting twist at the end. Dedupe each order, generate every pair, count across orders, pick the max. If you blank during the live OA, StealthCoder can sit invisibly on your screen as a safety net and hand you the structure.

The problem

Amazon's Retail Analytics team wants to discover which pairs of items are most often bought together so they can create Frequently Bought Together bundles.
During a short observation window, each customer order is recorded as a space-separated list of SKU strings, for example "B07 B08 B09". Within a single order, the same SKU may repeat, but repeats count only once toward a bundle.
Your task is to find the pair of distinct SKUs that appears in the highest number of orders. If several pairs tie for first place, return the lexicographically smallest pair, comparing the first SKU and then the second SKU.

Function
findFrequentBundlePair(orders: String[]) → String[]

Examples
Example 1
orders = ["B07 B08 B09", "B07 B08", "B08 B09"]
return = ["B07", "B08"]
Order-level pairs:
{B07, B08}, {B07, B09}, {B08, B09}
{B07, B08}
{B08, B09}
The global counts are {B07, B08} -> 2, {B07, B09} -> 1, and {B08, B09} -> 2. The highest count is tied between {B07, B08} and {B08, B09}, so the lexicographic tie-break gives {B07, B08}.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is normalization. For each order, split on spaces, put the SKUs in a set, sort them, then generate every i<j pair. Sorting inside the order means {B08, B07} and {B07, B08} hit the same key, and it makes the pair already lexicographically ordered. Store counts in a hash map keyed by the two SKUs joined with a separator. Then scan the map: take the higher count, and on a tie take the smaller first SKU, then the smaller second. The common pitfall is comparing keys as one joined string when SKUs have different lengths, so compare the tuple instead. Another is forgetting that a single-SKU order contributes no pairs. Also handle the case where no pair exists. If the live OA freezes you on the tie-break logic, StealthCoder is the hedge that shows a clean version while you keep typing.

StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.

If this hits your live OA

You can drill Frequently Bought Together 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. If you're reading this with an OA window open, you're who this was built for.

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. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Frequently Bought Together FAQ

What's the trick in the Amazon Frequently Bought Together OA?+

Dedupe SKUs inside each order before making pairs. Repeats count once per order. Then sort the unique SKUs, generate all pairs, and count them in a hash map. The rest is picking the max count with a lexicographic tie-break.

How hard is this problem really?+

Easy to medium. The algorithm is a plain hash map count. The difficulty is the details: dedupe within an order, consistent pair ordering, and the two-level tie-break. Candidates lose points on edge cases, not on the idea.

How should I do the tie-break correctly?+

Keep the pair as a tuple of two strings, not a joined string. When a new pair has a higher count, replace the best. When counts are equal, replace only if the first SKU is smaller, or the first matches and the second is smaller.

What's the time complexity and will it be fast enough?+

For an order with k unique SKUs you generate about k squared over 2 pairs. Total work is the sum of that across orders, plus sorting each order. It's fine unless orders are huge, in which case the pair count itself is the bottleneck.

How do I prepare for this in 48 hours?+

Write it once from scratch with a set, a sort, nested loops for pairs, and a map. Test an order with repeated SKUs, a one-item order, and a tie across three pairs. Knowing those three cases covers most hidden test failures.

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