We use cookies for site analytics. Accept to help us understand how the site is used. See our Privacy Policy for details.
An easy binary search problem, graded against 7 test cases (4 of them hidden).
Halving a search space each step - on sorted arrays, and on answers themselves.
Reach for it when you see: A sorted input, or a monotonic "is this value feasible?" predicate you can binary search over.
More Binary Searchproblems →The first `k` rows consume the triangular number `k(k+1)/2`, a strictly increasing function of `k`. Binary search for the largest `k` whose triangular number still fits within `n`. Since `n < 2^31`, `k` never exceeds 65535, so the intermediate product stays far below any precision limits.
The full reference solution in every supported language stays in the editor above - reveal it there once you have had a real attempt.
These apply to the pattern as a whole, not just this problem.