PHP Min Perimeter Rectangle
function minPerimeterRectangle(int $n): int
{
$i = 1;
$min = PHP_INT_MAX;
while ($i * $i < $n) {
if ($n % $i === 0) {
$min = min($min, (2 * ($i + $n / $i)));
}
$i++;
}
return $min;
}
This searches factor pairs up to the square root and picks the pair with the smallest perimeter.