Code RoomAggregate spending by path
MediumPrep Room Coding #396

Aggregate spending by path

CodingAlgorithms & data structuresEntry–Mid~16 min

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.

0:00 of about 16 min
InputExpectedGot
[["it/laptops,300","it/software,100","sports,50"]]{"it":400,"sports":50,"it/laptops":300,"it/software":100}not run yetsample