← Google Interview Insights

Google·Data Scientist·Technical Phone Screen·Intermediate

Intermediate
Jun 2026

Summary

Data wrangling interview for a Data Scientist role at Google, focused entirely on R and dplyr. Three questions, all practical, all connected around the same two tables. Not a vibe check at all, just code.

Questions Asked (3)

Q1

Using dplyr in R, how would you randomly sample exactly 50% of the rows in a data frame?

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

slice_sample() with prop=0.5 is the clean answer and I got there, but I initially started talking about sample_n() out of habit before catching myself.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying that you would use dplyr's sample_frac() function with a fraction of 0.5 to randomly sample exactly 50% of the rows. Then, demonstrate awareness of the need to set a random seed for reproducibility and discuss potential trade-offs such as sampling with or without replacement.

Pro tip: Mention that sample_frac() is a wrapper around sample_n() and that for large datasets, you might consider using slice_sample() (dplyr 1.0.0+) for better performance and clarity. Also, highlight the importance of setting a seed to ensure reproducible results, which is crucial in collaborative data science projects.

1. Clarify the requirement

Confirm that the goal is to randomly select exactly 50% of the rows from a data frame, and discuss whether sampling should be with or without replacement.

2. Choose the appropriate dplyr function

Explain that sample_frac() is the direct function for sampling a fraction of rows, and note that slice_sample() (with prop argument) is the newer, recommended alternative.

3. Implement the sampling

Write the code: df %>% sample_frac(0.5) or df %>% slice_sample(prop = 0.5). Emphasize the use of the pipe operator for readability.

4. Ensure reproducibility

Set a random seed before sampling using set.seed() to make the result reproducible, and explain why this is important.

5. Discuss trade-offs and edge cases

Mention considerations such as sampling with replacement (replace = TRUE), handling grouped data (use group_by() before sampling), and performance on large datasets.

Key Points to Mention

  • sample_frac() and slice_sample() are the primary dplyr functions for random sampling.
  • Setting a random seed with set.seed() ensures reproducibility.
  • The replace argument controls sampling with or without replacement.
  • For grouped data, group_by() can be used before sampling to sample within groups.
  • slice_sample() is the newer, more flexible function (dplyr 1.0.0+) and can replace sample_frac().
  • Consider performance implications for large datasets; sample_frac() may be slower than slice_sample().

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

Q2

Perform a left join between the products table and the discounts table on the product id column. What does the result look like for products with no matching discount?

Data Modeling
Author's notes

Pretty routine.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Explain that a left join returns all rows from the left table (products) and matching rows from the right table (discounts). For products with no matching discount, the discount columns will contain NULL values. Emphasize that the product row is still included, ensuring no products are lost.

Pro tip: Mention that left joins are often used to find missing matches, and you can filter for NULLs in the right table to identify products without discounts. This shows practical insight beyond just the mechanics.

1. Define left join

State that a left join returns all rows from the left table and matched rows from the right table. Unmatched right table columns are filled with NULLs.

2. Identify tables and keys

Clarify that products is the left table and discounts is the right table, joined on product_id. This sets the context for the result.

3. Describe result for unmatched products

Explain that for products with no discount, the discount-related columns (e.g., discount_id, discount_amount) will be NULL, but the product columns remain intact.

4. Provide an example

Give a concrete example: if product 101 has no discount, the result row shows product 101's details and NULLs for all discount columns.

5. Discuss implications

Mention that this ensures all products are included, which is useful for reports or analyses where you need to see all products regardless of discounts.

Key Points to Mention

  • Left join preserves all rows from the left table (products).
  • Unmatched rows from the right table (discounts) result in NULL values in the joined columns.
  • The join condition is on product_id (primary key in products, foreign key in discounts).
  • The result includes all product columns and all discount columns, with NULLs where no match exists.
  • This is useful for identifying products without discounts by filtering for NULLs in discount columns.
  • Contrast with inner join, which would exclude products without discounts.

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

Q3

Write a simulation in R where, for each run, half the products keep their original price and the other half get a 10% price increase. Return the average simulated price across runs.

A/B Testing & ExperimentationProduct Analytics & Metrics
Author's notes

This is where I stumbled a bit.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Clarify the simulation parameters (number of products, number of runs) and then implement a vectorized R simulation where each run randomly assigns half the products to a 10% price increase. Compute the average price per run and then average across runs, ensuring reproducibility with set.seed.

Pro tip: Always set a random seed for reproducibility and use vectorized operations instead of loops for efficiency, especially when the number of runs is large. Also, consider discussing the expected value analytically to validate your simulation results.

1. Define parameters and assumptions

Specify the number of products, number of simulation runs, and the price increase percentage. Assume all products start with the same price or define a price vector if needed.

2. Implement the simulation

For each run, randomly select half of the products to receive a 10% price increase. Use vectorized operations in R to efficiently generate the price vectors for all runs.

3. Compute per-run averages

Calculate the average price for each run by summing the prices and dividing by the number of products.

4. Aggregate across runs

Compute the overall average of the per-run averages to obtain the final simulated average price.

5. Validate and present results

Compare the simulated average with the theoretical expected value (e.g., if all start at $1, expected average is $1.05) and present the result clearly.

Key Points to Mention

  • Reproducibility via set.seed()
  • Vectorization for efficiency (e.g., using matrix operations or replicate)
  • Correct random assignment: exactly half get the increase
  • Theoretical expected value: 0.5 * original + 0.5 * (original * 1.1) = 1.05 * original
  • Handling of ties or odd number of products (if applicable)
  • Interpretation of results in the context of A/B testing or product analytics

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