Tap here to switch tabs
Problem
Submissions

Problem: Minimum Garden Perimeter to Collect Enough Apples

Try to solve the Minimum Garden Perimeter to Collect Enough Apples problem.

Statement

An apple tree is planted at every integer coordinate (x,y)(x, y) on an infinite two dimensional grid. The tree at coordinate (x,y)(x, y) produces ∣x∣+∣y∣|x| + |y| apples.

You are given an integer neededApples, representing the minimum total number of apples you need to collect. You want to purchase an axis aligned square plot of land centered at the origin (0,0)(0, 0) such that the total number of apples located on the perimeter or inside the plot is at least neededApples.

Return the minimum perimeter of a square plot of land that satisfies this condition.

Constraints:

  • 1≤1 \leq neededApples ≤1015\leq 10^{15}

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Garden Perimeter to Collect Enough Apples

Try to solve the Minimum Garden Perimeter to Collect Enough Apples problem.

Statement

An apple tree is planted at every integer coordinate (x,y)(x, y) on an infinite two dimensional grid. The tree at coordinate (x,y)(x, y) produces ∣x∣+∣y∣|x| + |y| apples.

You are given an integer neededApples, representing the minimum total number of apples you need to collect. You want to purchase an axis aligned square plot of land centered at the origin (0,0)(0, 0) such that the total number of apples located on the perimeter or inside the plot is at least neededApples.

Return the minimum perimeter of a square plot of land that satisfies this condition.

Constraints:

  • 1≤1 \leq neededApples ≤1015\leq 10^{15}