Skip to content
Veltoryx Technologies
ProProblem 38● EasyLeetCode #441 ↗5 min readUpdated 30 October 2026

Arranging Coins

Find the maximum number of complete staircase rows that can be built with n coins using binary search on the answer with upward rounding.

01The problem

You have n coins and you want to build a staircase with these coins. The staircase consists of k rows where the i-th row has exactly i coins. The last row of the staircase may be incomplete.

Given the integer n, return the number of complete rows of the staircase you will build.

InputOutputWhy
n = 52Rows need 1 + 2 = 3 coins. 2 coins left cannot finish row 3
n = 83Rows need 1 + 2 + 3 = 6 coins. 2 coins left cannot finish row 4
n = 111 coin completes row 1
n = 321 + 2 = 3 coins exactly completes row 2

Constraints: 1 ≤ n ≤ 2³¹ − 1.

Loading the rest of the lesson…