Ctrl K

Full Pyramid Rows

Easy
A child builds a pyramid out of blocks toy blocks. From the top down, the first row has 1 block, the second has 2, the third has 3, and so on: row i has i blocks. Rows are filled in order, and the last one may come up short. Return how many rows end up completely filled. Adding rows one at a time takes O(√n); you can do better.
Example 1
blocks=7 → 3

Rows of 1, 2 and 3 use 6 blocks, leaving one block for a fourth row that needs four. Three rows are complete.

Example 2
blocks=10 → 4

1 + 2 + 3 + 4 = 10, so all four rows are full and nothing is left.

Example 3
blocks=1 → 1
Constraints
  • 1 ≤ blocks ≤ 2³¹ − 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsWhole Square Root EasyThe Lost Ticket EasyTiles Into a Full Square EasyDigit of Endless Counting MediumA Base of All Ones Hard
loading Python…
Input
blocks=7
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 57 tests on the server, hidden ones included.