Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save manish-manghwani/d746044de07941a497b058eae0ca6773 to your computer and use it in GitHub Desktop.

Select an option

Save manish-manghwani/d746044de07941a497b058eae0ca6773 to your computer and use it in GitHub Desktop.
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