Created
November 16, 2020 08:36
-
-
Save manish-manghwani/d746044de07941a497b058eae0ca6773 to your computer and use it in GitHub Desktop.
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
| function maxArea(height: number[]): number { | |
| let leftPointer = 0; | |
| let rightPointer = height.length-1; | |
| let minHeight = 0; | |
| let maxArea = 0; | |
| while (leftPointer < rightPointer) { | |
| minHeight = height[leftPointer] < height[rightPointer] | |
| ? height[leftPointer] | |
| : height[rightPointer]; | |
| let area = minHeight * (rightPointer - leftPointer); | |
| maxArea = maxArea > area ? maxArea : area; | |
| height[leftPointer] < height[rightPointer] | |
| ? leftPointer++ | |
| : rightPointer--; | |
| } | |
| return maxArea; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment