← Google Interview Insights

Google·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Google Data Engineer interview with a Python data processing question. Two tasks, one input list, and a handful of edge cases that'll trip you up if you're not careful about parsing and division-by-zero.

Questions Asked (2)

Q1

Given a list of user activity records (each with a user_id, timestamp string, and activity type), write a function that returns a mapping of each activity to the count of distinct users who performed it.

Algorithms & Data StructuresProduct Analytics & Metrics
Author's notes

The dedup part is straightforward with a set, but I'd probably reach for a defaultdict of sets and then just take the lengths at the end.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the input format and edge cases, then propose an efficient solution using a hash map to track distinct users per activity. Iterate through the records, using a set per activity to ensure distinct user counts, and finally return the mapping of activity to count.

Pro tip: Mention that you would use a set per activity to avoid double-counting users, and discuss the time and space complexity upfront to show you think about scalability.

1. Clarify requirements and edge cases

Ask about input size, data types, possible null values, and whether the output should include activities with zero distinct users. Confirm the definition of 'distinct users'.

2. Choose data structures

Select a hash map to map each activity to a set of user IDs. This allows O(1) average-time insertion and ensures distinctness.

3. Iterate and populate

Loop through each record, extract the activity and user_id, and add the user_id to the corresponding set in the map.

4. Compute counts and return

After processing all records, create a new mapping where each activity maps to the size of its set. Return this mapping.

5. Analyze complexity and test

State the time complexity O(n) and space complexity O(n) in the worst case. Walk through a small example to verify correctness.

Key Points to Mention

  • Use of hash map for O(1) average-time lookups and insertions.
  • Use of set to track distinct users per activity, avoiding duplicates.
  • Time complexity: O(n) where n is number of records.
  • Space complexity: O(n) in the worst case (all users distinct per activity).
  • Handling edge cases: empty input, activities with no users, duplicate records.
  • Potential optimization: if memory is a concern, discuss trade-offs or alternative approaches like sorting.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Using the same list of user activity records, write a function that computes the average time spent on the site per user, where each user's time is defined as the gap in seconds between their earliest and latest recorded action.

Algorithms & Data StructuresProduct Analytics & Metrics
Author's notes

Two things will bite you here.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the input format and edge cases (e.g., empty list, single user). Then, iterate through the records to compute each user's min and max timestamps, calculate the time difference, and finally average these differences across all users.

Pro tip: Mention that you would handle large datasets by using a streaming approach with a hash map to avoid storing all records in memory, and discuss how to handle users with only one action (time spent = 0).

1. Clarify requirements and edge cases

Ask about the input format (e.g., list of tuples, objects), time unit (seconds), and edge cases like empty list, single user, or users with one action.

2. Design data structure

Use a hash map (dictionary) to store for each user the minimum and maximum timestamps seen so far.

3. Iterate and update min/max

Loop through each record, update the user's min and max timestamps accordingly.

4. Compute per-user time and average

For each user, compute max - min, then sum these times and divide by the number of users to get the average.

5. Analyze complexity and optimize

State time complexity O(n) and space O(u) where u is number of users. Discuss potential optimizations for large data.

Key Points to Mention

  • Time complexity: O(n) where n is number of records
  • Space complexity: O(u) where u is number of unique users
  • Handling edge cases: empty list, single user, users with one action
  • Using a hash map to track min and max timestamps per user
  • Definition of 'time spent' as max timestamp minus min timestamp
  • Potential for streaming processing to handle large datasets

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.