Loyal Customers Across Two Days
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The Amazon OA reported in July 2026 looks like a log-parsing chore, and it is one. Two arrays of logs, each entry a timestamp, customerId and pageId. You need customers who hit more than two distinct pages on both days, returned sorted. It's a hash map of sets plus a sort, nothing exotic. The danger is overthinking it or fumbling the details under the clock. If you blank mid-assessment, StealthCoder runs invisibly on your screen and hands you the solution, so one bad minute doesn't sink the whole OA.
The problem
You are given two arrays of website logs, dayOneLogs and dayTwoLogs. Each log entry contains exactly three strings in this order: timestamp, customerId, and pageId. A customer is loyal when both conditions hold: The customer appears in the logs on both days. On each day, the customer visits more than two distinct pages. Return the loyal customer IDs in lexicographically increasing order. Repeated visits to the same page count only once for that day. Function findLoyalCustomers(dayOneLogs: String[][], dayTwoLogs: String[][]) → List<String> Examples Example 1 dayOneLogs = [["09:00","alice","home"],["09:05","alice","search"],["09:10","alice","checkout"],["10:00","bob","home"],["10:05","bob","search"],["10:10","bob","checkout"],["11:00","cara","home"],["11:05","cara","search"],["11:10","cara","checkout"]] dayTwoLogs = [["09:00","alice","home"],["09:05","alice","offers"],["09:10","alice","checkout"],["10:00","bob","home"],["10:05","bob","search"],["12:00","dan","home"],["12:05","dan","search"],["12:10","dan","checkout"]] return = ["alice"] alice visits three distinct pages on each day. bob visits only two distinct pages on day two, cara is absent on day two, and dan is absent on day one. Example 2 dayOneLogs = [["1","cust-b","p1"],["2","cust-b","p2"],["3","cust-b","p3"],["4","cust-a","p1"],["5","cust-a","p2"],["6","cust-a","p3"]] dayTwoLogs = [["7","cust-a","p4"],["8","cust-a","p5"],["9","cust-a","p6"],["10","cust-b","p4"],["11","cust-b","p5"],["12","cust-b","p6"]] return = ["cust-a","cust-b"] Both customers visit three distinct pages on each day. The returned IDs are sorted lexicographically. Constraints Every log entry contains exactly three strings: timestamp, customerId, and pageId. Customer IDs and page IDs are compared exactly as provided. The timestamp does not affect whether a customer is loyal.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The input size rules out anything quadratic. Don't compare every log against every other log, and don't rescan day two for each customer. Make one pass per day. Build a map from customerId to a set of pageIds, ignoring the timestamp completely since the problem says it doesn't matter. Sets handle the repeat-visit rule for free. Then filter each map to customers with set size greater than 2. Intersect the two qualified key sets, drop the result into a list and sort it lexicographically. Total cost is O(n log k) at worst, where k is the number of loyal customers. Common pitfalls: using >= 2 instead of > 2, counting visits instead of distinct pages, and forgetting the sort. Another trap is checking presence on both days but not the threshold on each day separately. Bob in Example 1 fails exactly that way. Use plain string comparison for the sort, not a locale-aware one.
The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.
You can drill Loyal Customers Across Two Days 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. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Loyal Customers Across Two Days FAQ
How hard is the Loyal Customers Across Two Days question really?+
Easy to medium. There's no tricky algorithm. It's a hash map of sets, a filter and a sort. Most people who miss it slip on the threshold (more than two, not two) or forget that repeated page visits count once.
What's the trick to solving it fast?+
Build a map from customerId to a set of pageIds for each day, ignoring timestamps. Keep only customers whose set size is above 2. Intersect the two day results and sort. That's the whole solution, one pass per day.
What's the time complexity I should state?+
O(n + m) to build the two maps, where n and m are the log counts, plus O(k log k) to sort the k loyal customers. Space is O(n + m) for the sets. Say that out loud and you're covered.
Which edge cases should I test before submitting?+
Test a customer with exactly two distinct pages on one day, a customer who repeats the same page many times, a customer present on only one day, and empty logs. Also check the output order using IDs like cust-a and cust-b.
How do I prepare for this in 48 hours?+
Write the map-of-sets pattern from scratch a couple of times in your language of choice. Practice grouping logs by key, counting distinct values, intersecting key sets and sorting strings. Amazon OAs reward clean, correct code on simple patterns like this one.