A construction crew is assembling temporary bleacher rows for a one-day event out of identical wooden planks. Row 1 requires exactly 1 plank, row 2 requires exactly 2 planks, row 3 requires exactly 3 planks, and in general row k always requires exactly k planks. Rows must be completed strictly in order starting from row 1 — a new row is only started once the previous row has used up all of its required planks — and the crew stops building as soon as there are not enough remaining planks to finish the next row in full (they never leave a row half-built, and they never skip ahead).
Given the total number of planks delivered, determine the maximum number of complete rows the crew can build. Any planks left over after the last complete row simply go unused.
A single line containing one integer n, the total number of planks delivered.
Print a single integer: the maximum number of complete rows that can be built.
Example 1
Input
5
Expected
2
Explanation
Row 1 uses 1 plank (4 left), row 2 uses 2 more planks (2 left). Row 3 would need 3 planks but only 2 remain, so building stops. 2 complete rows were built.
Example 2
Input
8
Expected
3
Explanation
Row 1 uses 1 plank (7 left), row 2 uses 2 more (5 left), row 3 uses 3 more (2 left). Row 4 would need 4 planks but only 2 remain. 3 complete rows were built.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →