FastPrepLoyal Customers Across Two Days
Problems/Loyal Customers Across Two Days

Loyal Customers Across Two Days

Amazon logoAmazon● EasyFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report gives the complete loyalty rule but not the callable interface or result order. This practice version returns customer IDs in lexicographic order; the judged core task matches the report at about 96%.

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.

More Amazon problems

  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
See Amazon hiring insights
Saved
class Solution {
    public List<String> findLoyalCustomers(String[][] dayOneLogs, String[][] dayTwoLogs) {
        // Write your code here.
    }
}
Checking account…