feat: sunday

This commit is contained in:
2026-01-11 15:42:42 -05:00
parent 32173210d6
commit f3abe4ff5b

View File

@@ -0,0 +1,36 @@
package container_with_most_water
func MaxArea(height []int) int {
if len(height) < 2 {
return 0
}
start := 0
end := len(height) - 1
// Let:
// - A = the smaller side,
// - B = the larger side.
//
// Notice that:
// - Any container with A cannot have a height larger than `min(A, B)`.
// - Any container with A cannot have a width larger than `B - A`.
//
// Because of this, all solutions containing A cannot be larger than `area`.
area := (end - start) * min(height[start], height[end])
// Futhermore, we can completely ignore A.
//
// The maximum area will either be the current `area`, or some other two
// lines in the subset without A.
var subset []int
if height[start] < height[end] {
subset = height[start+1:]
} else {
subset = height[:end]
}
// We can now evaluate the problem space in the subset, and compute the
// maximum area.
return max(area, MaxArea(subset))
}