1954. Minimum Garden Perimeter to Collect Enough Apples
Previous1953. Maximum Number of Weeks for Which You Can WorkNext1955. Count Number of Special Subsequences
Last updated
Was this helpful?
Last updated
Was this helpful?
https://leetcode.com/problems/minimum-garden-perimeter-to-collect-enough-apples
In a garden represented as an infinite 2D grid, there is an apple tree planted at every integer coordinate. The apple tree planted at an integer coordinate (i, j)
has |i| + |j|
apples growing on it.
You will buy an axis-aligned square plot of land that is centered at (0, 0)
.
Given an integer neededApples
, return the minimum perimeter of a plot such that at leastneededApples
apples are inside or on the perimeter of that plot.
The value of |x|
is defined as:
x
if x >= 0
-x
if x < 0
Example 1:
Example 2:
Example 3:
Constraints:
1 <= neededApples <= 1015