As reported: Wayfair L4 (software engineer) screening round on HackerRank (2025): given customer purchase logs
(customer_id, product_id)for two different days, find the loyal customers. The loop continued with a machine-coding round and a low-level design round.
You are given the purchase logs of two different days. Each log entry is a pair [customerId, productId].
A customer is loyal if they:
- bought something on both days, and
- bought at least 3 distinct products in total across the two days.
Return the IDs of all loyal customers in ascending order.
Example 1
day1 = [[1,101],[2,102],[1,103],[3,104],[2,102]]
day2 = [[1,104],[2,102],[3,105],[3,106],[4,101]]
-> [1,3]
Customer 1 bought 101, 103, 104 over both days; customer 3 bought 104, 105, 106. Customer 2 came both days but bought only product 102; customer 4 came only on day 2.
Example 2
day1 = [[7,1],[7,2],[7,3]]
day2 = [[8,1],[8,2],[8,3]]
-> []
Clarifications
- The same customer can buy the same product several times; it counts once toward the distinct products.
- Either log can be empty.
Constraints: each log has at most 10^5 entries; 1 ≤ customerId, productId ≤ 10^9.
Code runner format: two lines: day1 and day2 as JSON arrays of [customerId, productId] pairs. Implement getLoyalCustomers(day1, day2); the harness prints the list of IDs.