Created
January 3, 2026 05:54
-
-
Save rtsoy/defac64a601b661b5a37d4773d04dc0f to your computer and use it in GitHub Desktop.
11. Container With Most Water
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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