FastPrepCount Distinct Users by Activity
Problems/Count Distinct Users by Activity

Count Distinct Users by Activity

Google logoGoogle● EasyFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamples

Problem statement

Source note: The report gives keyed records and asks for a mapping from activity to count. It does not say how records are written across languages, how the mapping is written out, or how it is ordered. Our version is about 95% the same as the reported question.

Given a collection of user-activity records, count how many distinct users performed each activity.

Each source record is represented as exactly three strings in this order:

  1. decimal user_id
  2. timestamp
  3. activity

Return the mapping as a two-column String[][]. Each row must be [activity, distinctUserCount], where the count is a decimal string. Order the rows by the first appearance of each activity in records.

Repeated records or repeated occurrences of the same activity by one user count that user only once for that activity. The timestamp is part of the input record but does not change the distinct-user count. If records is empty, return an empty matrix.

Function

countDistinctUsersByActivity(records: String[][]) → String[][]

Examples

Example 1

records = [["1","2024-07-26 10:00:00","login"],["2","2024-07-26 10:05:00","login"],["1","2024-07-26 10:10:00","view"],["1","2024-07-26 10:15:00","purchase"],["2","2024-07-26 10:20:00","view"],["3","2024-07-26 10:25:00","login"],["1","2024-07-26 10:30:00","logout"]]return = [["login","3"],["view","2"],["purchase","1"],["logout","1"]]

The distinct users are {1, 2, 3} for login, {1, 2} for view, and {1} for both purchase and logout. The activities first appear in the order login, view, purchase, logout.

Example 2

records = [["10","2024-08-01 09:00:00","search"],["10","2024-08-01 09:01:00","search"],["20","2024-08-01 09:02:00","search"],["10","2024-08-01 09:03:00","checkout"],["20","2024-08-01 09:04:00","checkout"]]return = [["search","2"],["checkout","2"]]

User 10 performs search twice but contributes once to that activity's distinct-user count. Both users perform search and checkout.

More Google Phone Screen questions

  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
  • Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Logger Rate Limiter with Every-Arrival HistoryPHONE SCREEN · Seen Nov 2026

Similar questions at other companies

  • Majority ElementByteDance · PHONE SCREENByteDance interview questions
  • Detect a Straight FlushTemu · PHONE SCREENTemu interview questions
  • Recommend Films from Viewers Who Watched Everything You DidBloomberg LP · PHONE SCREENBloomberg LP interview questions
  • Find Unique ElementsCisco · PHONE SCREENCisco interview questions
  • Shared Courses for Every Pair of StudentsCrunchyroll · PHONE SCREENCrunchyroll interview questions
  • Two SumAmazon · OA · PHONE SCREEN
  • Employee Count Median, Mean and ModeClay · PHONE SCREEN
  • Two SumBNSF Railway · PHONE SCREENBNSF Railway interview questions
  • Single-Condition Product FilterCrowdstrike · PHONE SCREENCrowdstrike interview questions
  • Cross-Day User Trust ScoresAffirm · PHONE SCREEN · ONSITE INTERVIEWAffirm interview questions

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
  • Google Experienced SWE First Round and Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public String[][] countDistinctUsersByActivity(String[][] records) {
      // write your code here
    }
}
Checking account…