← Gemini Interview Insights

Gemini·Data Scientist·Technical Phone Screen·Senior

SeniorPrefer not to say
Sep 2025Remote

Summary

Gemini data scientist technical round, three problems back to back covering window functions, device fingerprint ranking, and a Python union-find thing. The SQL parts were manageable but the Python question had a lot of moving pieces and I'm not sure I nailed the complexity analysis under pressure.

Questions Asked (3)

Q1

Write a SQL query using window functions and joins to find, for each user, the earliest rolling 24-hour window (ending no later than 2025-09-01 23:59:59) containing at least 3 ACH credit transactions where at least one of those credits has a return within 5 days. Output the window boundaries, count of ACH credits, count of returns within 5 days, and a net exposure figure defined as total credit amount minus total debit amount occurring between the window start and the earliest return timestamp.

Data ModelingProduct Analytics & MetricsAlgorithms & Data Structures
Author's notes

This one took me a while to even parse.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Break the problem into stages: first identify ACH credits and their associated returns, then use window functions to find rolling 24-hour windows with at least 3 credits and at least one return within 5 days, and finally join to compute net exposure. Use a subquery or CTE to calculate rolling counts and filter for the earliest qualifying window per user, then join to the transaction table to compute the net exposure.

Pro tip: Clarify the definition of 'rolling 24-hour window'—whether it's a fixed window (e.g., calendar day) or a sliding window based on transaction timestamps—and confirm the return window logic (e.g., return within 5 days of the credit). This shows attention to detail and avoids misinterpretation.

1. Identify ACH credits and returns

Filter the transaction table to ACH credits and identify returns associated with those credits, ensuring you capture the credit timestamp and return timestamp for each.

2. Compute rolling 24-hour windows

For each user, use a window function to count ACH credits within a rolling 24-hour window ending at each credit timestamp, and check if any of those credits have a return within 5 days.

3. Find earliest qualifying window

Filter windows where the credit count >= 3 and at least one return exists within 5 days, then select the earliest window per user based on the window end timestamp.

4. Compute net exposure

Join the qualifying window back to the transaction table to sum credit amounts and debit amounts between the window start and the earliest return timestamp, then calculate net exposure as total credits minus total debits.

Key Points to Mention

  • Use of window functions like ROWS BETWEEN or RANGE BETWEEN for rolling counts
  • Handling of time zones and timestamp precision
  • Definition of 'return within 5 days'—whether it's 5 calendar days or 120 hours
  • Ensuring the window ends no later than 2025-09-01 23:59:59
  • Performance considerations: indexing on user_id and transaction timestamp
  • Edge cases: multiple returns, overlapping windows, and users with no qualifying windows

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

Q2

Write a SQL query to rank each user's devices by how many returned ACH credits are linked to that device in the last 30 days, where a device is considered 'linked' to a credit transaction if it was the most recent login within 60 minutes before the transaction. Return only the top-ranked device per user with its fingerprint and returned credit count.

Data ModelingAlgorithms & Data Structures
Author's notes

Cleaner than the first question but the 'most recent login within 60 minutes before the credit' part requires a lateral join or a correlated subquery and I blanked on the cleanest way to write it.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Break the problem into two parts: first, identify the most recent login within 60 minutes before each returned ACH credit transaction to link devices to credits; then, count these linked credits per device per user in the last 30 days and rank devices using a window function. Finally, filter to the top-ranked device per user and return the fingerprint and count.

Pro tip: Clarify the definition of 'returned ACH credit' (e.g., status = 'returned') and ensure you handle ties in ranking by specifying a tie-breaking rule (e.g., most recent login time or device fingerprint). Also, consider time zone consistency and whether the 30-day window is based on transaction date or current date.

1. Filter returned ACH credits in last 30 days

Select credit transactions that are returned and occurred within the last 30 days from the current date (or a specified reference date).

2. Link each credit to the most recent login within 60 minutes before

For each returned credit, find the login event for the same user that occurred within 60 minutes before the transaction and is the most recent. Use a lateral join or window function to pick the latest login.

3. Count linked credits per device per user

Group by user and device fingerprint to count the number of linked returned credits.

4. Rank devices per user by count

Use ROW_NUMBER() or RANK() partitioned by user, ordered by count descending (and a tie-breaker if needed) to assign a rank to each device.

5. Select top-ranked device per user

Filter to rows where rank = 1 and return user identifier, device fingerprint, and the count.

Key Points to Mention

  • Use of window functions (e.g., ROW_NUMBER, RANK) for ranking devices per user.
  • Handling the 60-minute window with a lateral join or correlated subquery to find the most recent login before each transaction.
  • Filtering transactions by status (returned) and date range (last 30 days).
  • Ensuring correct join conditions: same user, login time between transaction time - 60 minutes and transaction time.
  • Considering performance implications and indexing on user_id, transaction_time, and login_time.
  • Addressing ties in ranking by specifying a deterministic tie-breaker (e.g., most recent login time or device fingerprint).

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

Q3

In Python, process a streaming login feed (events may arrive up to 5 minutes late and out of order) and cluster device fingerprints that differ by exactly one character using union-find. Then identify all clusters where the canonical fingerprint is used by 3 or more distinct users within any 7-day window ending on 2025-09-01. Return a list of tuples with the canonical fingerprint, window start and end, and distinct user count. Also state the time and space complexity and explain how you handle late events and ties in canonical fingerprint selection.

Algorithms & Data StructuresSystem DesignTechnical Trade-offs
Author's notes

I knew union-find going in but combining it with the streaming late-event handling and the 7-day sliding window on top made this genuinely hard to finish in one session.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the problem and outlining a streaming architecture that handles late and out-of-order events using a watermark and allowed lateness. Then detail the union-find clustering with a deterministic canonical selection rule, and explain the sliding window aggregation for distinct user counts. Finally, analyze time and space complexity and discuss trade-offs.

Pro tip: Mention that you would use a deterministic tie-breaker for canonical fingerprint (e.g., lexicographically smallest) to ensure reproducibility, and that you would handle late events by maintaining a buffer with a watermark and recomputing affected windows.

1. Clarify requirements and constraints

Ask about event schema, definition of 'differ by exactly one character', expected throughput, and whether the 7-day window is sliding or tumbling. Confirm that canonical fingerprint is the representative of a cluster.

2. Design streaming ingestion with late handling

Use a watermark with allowed lateness (e.g., 5 minutes) and a buffer to hold out-of-order events. For each event, update the union-find structure and maintain per-fingerprint user sets with timestamps.

3. Implement union-find clustering

For each new fingerprint, compare with existing fingerprints that differ by one character (using a hash map of patterns) and union them. Choose canonical fingerprint deterministically (e.g., lexicographically smallest) and update cluster metadata.

4. Compute sliding window distinct user counts

For each cluster, maintain a time-ordered list of (timestamp, user) events. Use a sliding window of 7 days ending 2025-09-01 to count distinct users, emitting tuples when count >= 3.

5. Analyze complexity and trade-offs

State time complexity: near O(N α(N)) for union-find plus O(N log N) for windowing; space O(N). Discuss trade-offs between exactness and memory, and how late events trigger recomputation.

Key Points to Mention

  • Union-find with path compression and union by rank for near-constant time operations.
  • Deterministic canonical selection: lexicographically smallest fingerprint in the cluster.
  • Handling late events: watermark with allowed lateness, buffering, and recomputation of affected windows.
  • Sliding window distinct count: using a hash set or balanced tree per cluster, with timestamps for eviction.
  • Time complexity: O(N α(N) + N log N) and space O(N) where N is number of events.
  • Trade-offs: memory vs. accuracy, and potential need for approximate algorithms at scale.

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