Skip to content

Instantly share code, notes, and snippets.

@rtsoy
Created January 3, 2026 05:54
Show Gist options
  • Select an option

  • Save rtsoy/defac64a601b661b5a37d4773d04dc0f to your computer and use it in GitHub Desktop.

Select an option

Save rtsoy/defac64a601b661b5a37d4773d04dc0f to your computer and use it in GitHub Desktop.
11. Container With Most Water
// https://leetcode.com/problems/container-with-most-water/
//
// Time: O(n)
// Space: O(1)
//
// n = number of elements in array
// .................... //
func maxArea(height []int) int {
n := len(height)
area := 0
l, r := 0, n - 1
for l < r {
calc := (r-l) * min(height[l], height[r])
area = max(area, calc)
if height[l] >= height[r] {
r--
} else {
l++
}
}
return area
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment