Class Solution
java.lang.Object
g1901_2000.s1954_minimum_garden_perimeter_to_collect_enough_apples.Solution
1954 - Minimum Garden Perimeter to Collect Enough Apples.<p>Medium</p>
<p>In a garden represented as an infinite 2D grid, there is an apple tree planted at <strong>every</strong> integer coordinate. The apple tree planted at an integer coordinate <code>(i, j)</code> has <code>|i| + |j|</code> apples growing on it.</p>
<p>You will buy an axis-aligned <strong>square plot</strong> of land that is centered at <code>(0, 0)</code>.</p>
<p>Given an integer <code>neededApples</code>, return <em>the <strong>minimum perimeter</strong> of a plot such that <strong>at least</strong></em> <code>neededApples</code> <em>apples are <strong>inside or on</strong> the perimeter of that plot</em>.</p>
<p>The value of <code>|x|</code> is defined as:</p>
<ul>
<li><code>x</code> if <code>x >= 0</code></li>
<li><code>-x</code> if <code>x < 0</code></li>
</ul>
<p><strong>Example 1:</strong></p>
<p><img src="https://assets.leetcode.com/uploads/2019/08/30/1527_example_1_2.png" alt="" /></p>
<p><strong>Input:</strong> neededApples = 1</p>
<p><strong>Output:</strong> 8</p>
<p><strong>Explanation:</strong> A square plot of side length 1 does not contain any apples. However, a square plot of side length 2 has 12 apples inside (as depicted in the image above). The perimeter is 2 * 4 = 8.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> neededApples = 13</p>
<p><strong>Output:</strong> 16</p>
<p><strong>Example 3:</strong></p>
<p><strong>Input:</strong> neededApples = 1000000000</p>
<p><strong>Output:</strong> 5040</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= neededApples <= 10<sup>15</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
minimumPerimeter
public long minimumPerimeter(long neededApples)
-