FastPrepLoyal Customers by Two-Day Product Variety
Problems/Loyal Customers by Two-Day Product Variety

Loyal Customers by Two-Day Product Variety

Amazon logoAmazon● EasyNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Amazon new grad onsite interview. The report gives the two-day loyalty rule and hints at a solution with sets. It does not give the function signature or the order of results. Our version is about 97% the same as the reported question.

You are given website interaction logs from two consecutive days. Every row in dayOneLogs and dayTwoLogs contains [customerId, productId].

A customer is loyal when both conditions hold:

  • The customer appears at least once on each day.
  • Across both days combined, the customer interacts with at least two distinct products.

Repeated interactions with the same product count once. Return all loyal customer IDs in lexicographically increasing order.

Function

loyalCustomers(dayOneLogs: String[][], dayTwoLogs: String[][]) → String[]

Examples

Example 1

dayOneLogs = [["u1","p1"],["u1","p1"],["u2","p2"],["u3","p9"]]dayTwoLogs = [["u1","p2"],["u2","p2"],["u2","p3"],["u4","p1"]]return = ["u1","u2"]

Customers u1 and u2 appear on both days. Their combined distinct-product sets are respectively {p1, p2} and {p2, p3}.

Example 2

dayOneLogs = [["amy","book"],["bob","pen"]]dayTwoLogs = [["amy","book"],["bob","paper"]]return = ["bob"]

Both customers appear on both days, but amy interacts only with book. Customer bob interacts with two distinct products.

Example 3

dayOneLogs = [["a","x"],["a","y"]]dayTwoLogs = [["b","x"],["b","y"]]return = []

No customer appears on both days, so the result is empty even though each customer has two distinct products.

Constraints

  • 0 <= dayOneLogs.length, dayTwoLogs.length <= 2 * 10^5.
  • Every log row contains exactly two non-empty strings: a customer ID followed by a product ID.
  • Every ID contains only English letters, digits, hyphens, and underscores.
  • The total number of log rows across both days is at most 2 * 10^5.

More Amazon Onsite Interview questions

  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Cheapest Flights Within K StopsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Dungeon GameONSITE INTERVIEW · Seen Nov 2026
  • Integer BreakONSITE INTERVIEW · Seen Nov 2026
  • LFU CacheONSITE INTERVIEW · Seen Nov 2026
  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
  • Filter Anagrams of a TargetMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Deduplicate Logs: Keep FirstGoogle · ONSITE INTERVIEWGoogle interview questions
  • Count Word FrequenciesBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Most Voted CandidateExpedia · ONSITE INTERVIEWExpedia interview questions
  • List Each Name Once, AlphabeticallyDocuSign · ONSITE INTERVIEWDocuSign interview questions
  • Process Shopping Records, Promotions, and Display OrderInstacart · PHONE SCREEN · ONSITE INTERVIEWInstacart interview questions
  • Deep Merge with a Conflict ResolverAutodesk · ONSITE INTERVIEWAutodesk interview questions
  • Group Duplicate Files by ContentPostman · ONSITE INTERVIEWPostman interview questions
  • Group AnagramsGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions

Interview reports that mention this question

  • Amazon New Grad SDE Onsite Interview Questions: 17 Experiences

Amazon interview experiences

  • Amazon SWE OA with AI Coding: 1 Experience
  • Amazon SWE Intern Phone Screen Interview Experience: 1 Experience
  • Amazon New Grad SDE I OA and Virtual Onsite: 1 Experience
  • Amazon BIE Intern SQL and Interview Questions: 17 Experiences
  • Amazon Experienced SWE AI-Assisted Debugging OA: 1 Experience
See Amazon hiring insights
Saved
class Solution {
    public String[] loyalCustomers(String[][] dayOneLogs, String[][] dayTwoLogs) {
      // Write your code here
    }
}
Checking account…