Count Repeat Customers Across Dates
Updated
Problem statement
You are given an array visits. Each row contains exactly two strings: [customerId, timestamp]. Every timestamp is a valid UTC value in the fixed format YYYY-MM-DDTHH:MM.
Only visits whose timestamps are between windowStart and windowEnd, inclusive, belong to the reporting window.
A customer is a repeat customer when that customer has at least one visit on each of two different calendar dates inside the reporting window. Multiple visits by the same customer on the same date count once for this rule.
Return the number of repeat customers.
Function
countRepeatCustomers(visits: String[][], windowStart: String, windowEnd: String) → intExamples
Example 1
visits = [["alice","2026-08-18T09:00"],["bob","2026-08-18T09:15"],["alice","2026-08-19T10:00"],["bob","2026-08-18T17:00"],["cara","2026-08-20T12:00"]]windowStart = "2026-08-18T00:00"windowEnd = "2026-08-19T23:59"return = 1alice visits on August 18 and August 19 inside the window. Both of bob's visits are on August 18, and cara's visit is outside the window.
Example 2
visits = [["a","2026-08-01T00:00"],["a","2026-08-02T23:59"],["b","2026-08-02T23:59"],["b","2026-08-03T00:00"],["c","2026-08-02T12:00"]]windowStart = "2026-08-01T00:00"windowEnd = "2026-08-02T23:59"return = 1The window includes both boundary timestamps. Customer a appears on two dates. Customer b's August 3 visit is outside the window, and c appears on one date.
Example 3
visits = [["u1","2026-09-01T08:00"],["u1","2026-09-01T09:00"],["u2","2026-09-01T10:00"],["u2","2026-09-02T10:00"]]windowStart = "2026-09-01T00:00"windowEnd = "2026-09-02T23:59"return = 1Two visits by u1 on the same date do not make that customer repeat. Customer u2 visits on two different dates.
Constraints
0 <= visits.length <= 200000.- Every row in
visitscontains exactly two non-empty strings: a customer ID and a timestamp. - Every customer ID contains at most
64English letters, digits, hyphens, or underscores. - Every timestamp,
windowStart, andwindowEndis a valid UTC value in the fixed formatYYYY-MM-DDTHH:MM. windowStart <= windowEnd.- The visits may be in any order.
More Amazon Phone Screen questions
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Search in a Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent ElementsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
- Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
- Second Largest Distinct ElementPHONE SCREEN · Seen Nov 2026
- Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
- Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
- Insert an Employee into an Organization HierarchyWaymo · PHONE SCREENWaymo interview questions
- Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
- Deep Merge with a Conflict ResolverAutodesk · ONSITE INTERVIEWAutodesk interview questions
- Rank Word-Translation Hints from Sentence TranslationsDuolingo · PHONE SCREEN · ONSITE INTERVIEWDuolingo interview questions
- Most Frequent Call Path From Function Trace LogsRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Group AnagramsWorkday · PHONE SCREEN
- Video Cache Hit Rates from a CSV LogTubi · PHONE SCREEN
- Apply Operations to Make a String EmptyFlexport · PHONE SCREENFlexport interview questions