Count Customers Who Visited on Multiple Dates

Quick Overview

Count distinct customers who entered a store on at least two different dates, treating repeated logs for the same customer and date as one visit date.

Count Customers Who Visited on Multiple Dates

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

## Problem Each store-entry log is `[customerId, date]`, where `date` is an integer day identifier. Count how many distinct customers visited on at least two distinct dates. Multiple entries by the same customer on the same date count as one visit date. Logs may be in any order. ### Function Contract Implement `countRepeatCustomers(logs)` and return one integer. ### Constraints & Assumptions - `0 <= len(logs) <= 2,000,000`. - Customer IDs are nonempty ASCII strings. - Dates are signed 32-bit integers. - A customer is counted once regardless of how many distinct dates beyond two appear. - The input may be too large to sort comfortably, so explain the memory and streaming trade-offs of the chosen approach. ### Clarifying Questions to Ask - Do two entries on one date make a repeat customer? No. - Is the result the number of repeat visits or repeat customers? Distinct customers. - Can processing stop tracking all dates after a customer reaches two? Yes, only the first distinct date and repeat status are needed. ```hint Store the first distinct date For each customer, remember the first date. When a different date appears, mark the customer repeated and increment the answer only on that transition. ``` ### Examples ```text logs = [["a",1], ["a",1], ["b",2], ["a",3], ["b",2]] -> 1 logs = [["a",1], ["a",2], ["a",3], ["b",4], ["b",5]] -> 2 logs = [] -> 0 ``` ### Evaluation Focus - Deduplicates repeated same-day entries. - Counts each customer at most once. - Works without depending on input order. - Uses `O(number of distinct customers)` state and linear expected time. ### Extensions to Discuss 1. How would you filter logs to an inclusive time range before counting? 2. How could a partitioned data pipeline guarantee all records for one customer meet at the same reducer? 3. What approximation would you consider if even one state record per customer is too large?

Quick Answer: Count distinct customers who entered a store on at least two different dates, treating repeated logs for the same customer and date as one visit date.

|Home/Coding & Algorithms/Amazon
Amazon logo
Amazon
Aug 16, 2026, 12:00 AM
mediumSoftware EngineerTechnical ScreenCoding & Algorithms
0
0

Problem

Each store-entry log is [customerId, date], where date is an integer day identifier. Count how many distinct customers visited on at least two distinct dates.

Multiple entries by the same customer on the same date count as one visit date. Logs may be in any order.

Function Contract

Implement countRepeatCustomers(logs) and return one integer.

Constraints & Assumptions

  • 0 <= len(logs) <= 2,000,000 .
  • Customer IDs are nonempty ASCII strings.
  • Dates are signed 32-bit integers.
  • A customer is counted once regardless of how many distinct dates beyond two appear.
  • The input may be too large to sort comfortably, so explain the memory and streaming trade-offs of the chosen approach.

Clarifying Questions to Ask Guidance

  • Do two entries on one date make a repeat customer? No.
  • Is the result the number of repeat visits or repeat customers? Distinct customers.
  • Can processing stop tracking all dates after a customer reaches two? Yes, only the first distinct date and repeat status are needed.

Examples

logs = [["a",1], ["a",1], ["b",2], ["a",3], ["b",2]] -> 1
logs = [["a",1], ["a",2], ["a",3], ["b",4], ["b",5]] -> 2
logs = [] -> 0

Evaluation Focus

  • Deduplicates repeated same-day entries.
  • Counts each customer at most once.
  • Works without depending on input order.
  • Uses O(number of distinct customers) state and linear expected time.

Extensions to Discuss

  1. How would you filter logs to an inclusive time range before counting?
  2. How could a partitioned data pipeline guarantee all records for one customer meet at the same reducer?
  3. What approximation would you consider if even one state record per customer is too large?

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...