Frequently Bought Together
Learn this problemProblem statement
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}.
Source note (June 29, 2026): The original screenshot did not include a separate formatted Output block. FastPrep used the visible tie-break result {B07,B08} and formatted it as ["B07", "B08"] for this example. If you have the original output format or notice something wrong, please let us know and we'll fix it. If we find a clearer source later, we'll come back and update this too. 🦦
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026