Code Room
CodingMediumcod-g1164
Subject Database queryLevel Mid–Senior~28 minCommon in Databases & SQL interviewsIndustries Software development

Question

You have a star schema: a fact table `sales` as rows [product_id, amount] (amount int), and a dimension table `products` as rows [product_id, category] (category string). Join the fact rows to their product's category and roll up total amount per category. Fact rows whose product_id is missing from the dimension table are dropped (inner join). Return [category, total_amount] pairs sorted by category ascending. product_ids in the dimension table are unique.

Implement
star_rollup(sales: list[list], products: list[list]) → list[list]
Examples
in[[[1,100],[2,50],[1,25]],[[1,"books"],[2,"toys"]]]out[["books",125],["toys",50]]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.