Aggregate spending by path
Your task
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}.
Examples
rollup_totals(rows: list[str]) -> dict[str,int]Example 1
Input
rollup_totals(["it/laptops,300", "it/software,100", "sports,50"])Output
{"it": 400, "it/laptops": 300, "it/software": 100, "sports": 50}