First Time Below Zero
moves has columns account and amount, in time order. Every account starts at 0 and each row adds its amount to that account. Return a dict from account to the count of its move (1 for its first) after which its balance is below 0 for the first time. Leave out accounts that never go below 0.
Example 1
moves {"account":["a","b","a","b","a","c"],"amount":[10,-5,-30,20,40,7]}
returns {"a":2,"b":1}
a goes 10, then -20 after its 2nd move. b is at -5 after its 1st move. c never goes below 0.
Constraints
1 <= len(moves) <= 80-50 <= amount <= 50
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More pandas problems
- Last Person on the BusMedium
- Manager NamesMedium
- Most Orders CustomerMedium
- Most Recent OrderMedium
- Person CitiesMedium
- Rearrange Products TableMedium
- Record ReadingsMedium
- Reformat Department TableMedium