1739. Building Boxes

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1739

class Solution:
    def minimumBoxes(self, n: int) -> int:
        s, k = 0, 1
        while s + k * (k + 1) // 2 <= n:
            s += k * (k + 1) // 2
            k += 1
        k -= 1
        res = k * (k + 1) // 2
        k = 1
        while s < n:
            res += 1
            s += k
            k += 1
        return res