Sample and Simulate Price Adjustments in R with dplyr
Company: Google
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Technical Screen
Overview: This question evaluates proficiency in R data manipulation with dplyr, specifically sampling, left joins, conditional price transformations and running simple simulations to estimate average prices.
Tables
products(id INTEGER, product VARCHAR(50), price DECIMAL(10,2))
discounts(id INTEGER, discount DECIMAL(5,2))
Hints
- Use ORDER BY random() with a LIMIT based on 50% of the row count to sample products (in PostgreSQL).
- Use a LEFT JOIN from products to discounts on id to include all products and any matching discounts.