Code Room
CodingMediumcod-g1217
Subject Data wranglingLevel Entry–Mid~16 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

A school tracks spending against slash-separated category paths. Each row is "path,amount" where path looks like "supplies/art/paint" and amount is a positive integer. Every amount counts toward its own path AND every ancestor prefix, so "it/laptops,300" adds 300 to both "it" and "it/laptops". Return a dictionary mapping every path that received money (directly or via a descendant) to its total. Example: ["it/laptops,300", "it/software,100", "sports,50"] gives {"it": 400, "it/laptops": 300, "it/software": 100, "sports": 50}.

Implement
rollup_totals(rows: list[str]) → dict[str,int]
Examples
in[["it/laptops,300","it/software,100","sports,50"]]out{"it":400,"sports":50,"it/laptops":300,"it/software":100}
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.