Problem · Array

Frequently Bought Together

Learn this problem
MediumAmazonINTERNOA
See Amazon hiring insights

Problem 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:

  1. {B07, B08}, {B07, B09}, {B08, B09}
  2. {B07, B08}
  3. {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

drafts saved locally
public String[] findFrequentBundlePair(String[] orders) {
  // write your code here
}
orders["B07 B08 B09", "B07 B08", "B08 B09"]
expected["B07", "B08"]
checking account