1954. Minimum Garden Perimeter to Collect Enough Apples

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

On This Page

LeetCode problem 1954

class Solution:
    def minimumPerimeter(self, neededApples: int) -> int:
        l, r = 1, 100000
        while l < r:
            mid = (l + r) >> 1
            if 2 * mid * (mid + 1) * (2 * mid + 1) >= neededApples:
                r = mid
            else:
                l = mid + 1
        return l * 8