Compute unique visitors per department from clicks
AmazonSoftware Engineer · Technical ScreenLast updated
This question evaluates a candidate's skill in data manipulation and deduplication using SQL/Python, specifically mapping hierarchical product metadata to departments and computing unique user counts without double-counting, and is categorized under Data Manipulation (SQL/Python).
Given tables Products(product_id, department, category, subcategory) where department > category > subcategory form a hierarchy, and ClickLog(user_id, product_id, event_ts) that records user clicks, write SQL to compute the number of unique customers who visited (clicked any product in) a specified department over a given time range. Ensure correct mapping from product_id to its department and avoid double-counting users who clicked multiple products/categories within the same department. Explain your indexing/partitioning strategy for large-scale data and how you would extend the query to return results for all departments.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.