Problem
You have n coins and build a staircase: row 1 has 1 coin, row 2 has 2 coins, row k has k coins. The last row may be left incomplete. Return the number of complete rows you can build.
Example 1
- Input
- n = 5
- Output
- 2
- Why
- rows of 1 and 2 use 3 coins; 2 left over is not enough for row 3
Example 2
- Input
- n = 8
- Output
- 3
- Why
- 1 + 2 + 3 = 6; 2 left over
Example 3
- Input
- n = 1
- Output
- 1
The first k rows need k * (k + 1) / 2 coins in total.
Constraints
1 <= n <= 2^31 - 1