Find Gmail Users Who First Crossed Their Storage Quota

Last updated: November 29, 2026

Quick Overview

From a daily snapshot table of each user's bytes used and quota, return the first date each user went over quota and how many separate times they crossed it.

Google
Data Manipulation (SQL/Python)
Data Scientist
Google
November 29, 2026
Data Scientist
Technical Screen
Data Manipulation (SQL/Python)
Medium

0

0

0 solved


From a daily snapshot table of each user's bytes used and quota, return the first date each user went over quota and how many separate times they crossed it.

A Google One and Gmail storage scenario used in data science technical screens. The interviewer wants to see LAG used to detect state transitions rather than just filtering over-quota rows, since the business cares about crossing events that trigger upgrade prompts.

What the Interviewer Expects
  • Define a crossing as an over-quota day whose previous snapshot was under quota or missing
  • Use LAG partitioned by user and ordered by date
  • Handle the first snapshot for each user explicitly
  • Distinguish first crossing date from total crossings
  • Discuss what missing snapshot days do to the logic
Key Topics to Cover
LAG
state transitions
window functions
event detection
How to Approach This
  1. Clarify the schema and expected output format before writing queries.
  2. Use CTEs (WITH clauses) to break complex queries into readable steps.
  3. Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
  4. Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
  5. For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
  • Snapshots are missing for some days. Should a gap reset the state?
  • How would you measure the share of crossers who upgraded within seven days?
  • Quota changes when a user upgrades. Does your query still work?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice SQL Problems
Sample Answer
Clarify the Data

storage_daily(user_id, ds, bytes_used, quota_bytes), one row per user per snapshot date. Quota can change over time (upgrades), so I compare each day to that day's quota. I will ask whether a user w...

Approach

Mark each row with over_quota, then use LAG to get yesterday's flag for the same user. A crossing is a row where today is over and the previous flag is false or NULL (no earlier row). Then aggrega...


Submit Your Answer
Markdown supported