Find the maximum possible height of a triangle built from a limited number of blocks, where each lower row must contain one more block than the row above it.
You are given an integer n, representing the number of identical blocks available.
Using these blocks, you want to build a triangle with rows stacked from top to bottom:
1 block,2 blocks,3 blocks,A triangle of height h uses exactly 1 + 2 + ... + h blocks.
Return the maximum height of a triangle that can be built using at most n blocks.
n = 0, the answer is 0.n.Example 1
Input
n = 6
Output
3
Explanation
A triangle of height 3 uses 1 + 2 + 3 = 6 blocks, which fits exactly.
Example 2
Input
n = 7
Output
3
Explanation
Height 4 would need 1 + 2 + 3 + 4 = 10 blocks, which is too many. So the maximum height is 3.
Example 3
Input
n = 0
Output
0
Explanation
No blocks means no rows can be built.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.