# 1954. Minimum Garden Perimeter to Collect Enough Apples

<https://leetcode.com/problems/minimum-garden-perimeter-to-collect-enough-apples>

## Description

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 least***`neededApples` *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:**

![](https://assets.leetcode.com/uploads/2019/08/30/1527_example_1_2.png)

```
**Input:** neededApples = 1
**Output:** 8
**Explanation:** 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.
```

**Example 2:**

```
**Input:** neededApples = 13
**Output:** 16
```

**Example 3:**

```
**Input:** neededApples = 1000000000
**Output:** 5040
```

**Constraints:**

* `1 <= neededApples <= 1015`

## ac

```java
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jaywin.gitbook.io/leetcode/solutions/1954-minimum-garden-perimeter-to-collect-enough-apples.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
