Java Min Perimeter Rectangle
public class Solution {
public static int minPerimeterRectangle(int n) {
long i = 1;
long min = Long.MAX_VALUE;
while (i * i < n) {
if (n % i == 0) {
min = Math.min(min, 2 * (i + n / i));
}
i++;
}
return (int) min;
}
}
This searches factor pairs up to the square root and picks the pair with the smallest perimeter.