Loyal Customers by Two-Day Product Variety
Updated
Problem statement
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