Arranging Coins

You have n coins and want to build a staircase. Row 1 needs one coin, row 2 needs two coins, and every next row needs one more coin than the previous row.…

You have `n` coins and want to build a staircase. Row 1 needs one coin, row 2 needs two coins, and every next row needs one more coin than the previous row. Return the number of complete rows you can build. Coins left over after the last complete row do not count as another row.

- `1 <= n <= 10^9` - Note: when `n = 1`, the single coin completes row 1, so the answer is `1`. - Note: `n = 0` is not a valid input; with no coins, not even row 1 can be built.

Example 1: input n = 5; output 2. Rows of sizes 1 and 2 are complete; only 2 coins remain, fewer than the 3 needed next.

Example 2: input n = 8; output 3. Three rows use 1 + 2 + 3 = 6 coins, leaving 2.

Category: Binary Search. Topic: binary-search. Difficulty: Easy. Patterns: binary-search-on-answer.