dsa · easy
Arranging Coins
You have n identical coins. Build a staircase whose k-th row (1-based) must contain exactly k coins. You fill rows from the top, and a row counts only if it is completely filled. Return the number of complete rows you can finish with the n coins you have. Leftover coins that cannot fill the next row are ignored.
Example
n = 8:
- row 1 needs 1 coin (1 used, 7 left)
- row 2 needs 2 coins (3 used, 5 left)
- row 3 needs 3 coins (6 used, 2 left)
- row 4 needs 4 coins, but only 2 remain, so it stays unfinished
Three complete rows → 3.
n = 1 fills exactly row 1 → 1.
n = 6 fills rows 1+2+3 exactly (1+2+3 = 6) → 3.
## Arguments - n — number of coins you may spend on the staircase
Constraints
1 <= n <= 2^31 - 1 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: 8 Expected: 3
Example 2
Input: 1 Expected: 1
Example 3
Input: 6 Expected: 3