You are stacking cans into a triangle: the top row has 1 can, the next has 2, then 3, and so on. Write can_rows(cans) that returns how many complete rows you can build with cans cans. Leftover cans that cannot finish a row are ignored.
Examples
Input: cans = 10
Output: 4
Explanation: 1 + 2 + 3 + 4 = 10
Input: cans = 7
Output: 3
Explanation: 1 + 2 + 3 = 6; the 4th row would need 4 more cans but only 1 is left.
Constraints
0 <= cans <= 10**9
Goals
- Use a while loop whose stopping point depends on a running total
- Count completed steps of a process