All problems
Rectangle Max Area
Problem
A rectangle has a fixed perimeter P. Maximize its area A = w * h subject to 2*(w + h) = P.
The optimum is a square, so return (P / 4)^2. Assume P >= 0.
Hint
Substitute h = P/2 - w into the area and maximize the resulting quadratic.
Test cases
case 1
in: [20]
expected: 25
case 2
in: [4]
expected: 1
case 3
in: [0]
expected: 0
case 4
in: [10]
expected: 6.25
case 5
in: [2.4]
expected: 0.36
Starter codePython
def max_rectangle_area(perimeter):
# Your code here
pass5 test cases · run your code against them in the editor