Revenue by section
A store's sales feed tags each line with a slash-separated catalog path. Each row is "path,amount" where path looks like "electronics/phones/cases" and amount is a positive integer; a path may also be a single segment like "toys". For the executive summary, total the amounts per TOP-LEVEL section (the first path segment). Example: ["electronics/phones,200", "electronics/laptops,300", "home/kitchen,50"] gives {"electronics": 500, "home": 50}.
Implement
top_level_totals(rows: list[str]) → dict[str,int]Examples
in
[["electronics/phones,200","electronics/laptops,300","home/kitchen,50"]]out{"home":50,"electronics":500}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 11 min
solution.py
InputExpectedGot
[["electronics/phones,200","electronics/laptops,300","home/kitchen,50"]]{"home":50,"electronics":500}not run yetsample