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:

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

Open in the Dojo editor