← Google Interview Insights

Google·Data Scientist·Technical Phone Screen·Senior

Senior
May 2026

Summary

Google Data Scientist technical screen, heavy on R and simulation work. One meaty coding question that took up the whole session and had a lot of moving parts.

Questions Asked (1)

Q1

Using R and dplyr, write a simulation that runs 1,000 iterations with set.seed(2025). In each iteration, randomly select half the rows from a prices table to keep at their original price and increase the other half by 10%. Then left join to a catalog table and compute the overall mean price plus mean price broken down by category. Return a data frame with one row per simulation, and also report the empirical mean and SD across all simulations for each statistic. You must use dplyr verbs like slice_sample, mutate, case_when, left_join, group_by, and summarise, no for-loops, and your approach should scale safely to a million items.

A/B Testing & ExperimentationTechnical Trade-offsData Modeling
Author's notes

This one wrecked me a little.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

First, clarify the data structure and simulation goal: each iteration randomly assigns half the rows to a 10% price increase, then joins to a catalog and computes overall and per-category mean prices. Use a vectorized, dplyr-based approach with slice_sample, mutate, case_when, left_join, group_by, and summarise, wrapping the iteration in a function and using purrr::map_dfr to avoid for-loops. Finally, summarise the simulation results to report empirical mean and SD for each statistic.

Pro tip: Mention that you would set the seed once at the start and use slice_sample with replace = FALSE to ensure exactly half the rows are selected, and note that using purrr::map_dfr keeps the code clean and scalable while satisfying the no-for-loop requirement.

1. Clarify data and simulation design

Confirm the structure of the prices and catalog tables, the definition of 'half the rows', and how categories are derived. Discuss the need for reproducibility with set.seed(2025) and the requirement to scale to a million items.

2. Write a single-iteration function

Create a function that takes the prices and catalog data, uses slice_sample to randomly select half the rows to keep at original price, and mutate with case_when to increase the other half by 10%. Then left_join to catalog and compute overall mean price and mean price by category using group_by and summarise.

3. Run 1,000 iterations without for-loops

Use purrr::map_dfr (or replicate with simplify) to apply the function 1,000 times, binding the results into a single data frame with one row per simulation. Ensure set.seed(2025) is called before the iterations.

4. Summarise simulation results

From the simulation output, compute the empirical mean and standard deviation for the overall mean price and for each category's mean price using summarise(across(...)) or pivot_longer and group_by.

5. Discuss scalability and trade-offs

Explain how the dplyr pipeline is vectorized and memory-efficient, and mention potential optimizations like using data.table or disk-based processing if the data exceeds memory, while still adhering to the dplyr requirement.

Key Points to Mention

  • Use of set.seed(2025) for reproducibility and slice_sample to randomly select exactly half the rows.
  • Application of mutate and case_when to conditionally increase prices by 10% for the non-selected half.
  • Left join to catalog to bring in category information, ensuring all price rows are retained.
  • Grouped summarise to compute mean price overall and by category, and then across simulations to get empirical mean and SD.
  • Avoidance of for-loops by using purrr::map_dfr or similar functional programming techniques.
  • Scalability considerations: vectorized operations, memory management, and potential use of alternative packages for large data.

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