Skip to content

Commit 82f39af

Browse files
committed
🔥 Container With Most Water
1 parent c5ff727 commit 82f39af

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ Solutions of LeetCode Blind 75 Problems in JavaScript
1515
| [Find Minimum in Rotated Sorted Array](./find-minimum-in-rotated-sorted-array.js) | <img src="https://img.shields.io/badge/-Medium-orange" /> | `Array`, `Binary Search` | [:link:](https://leetcode.com/problems/find-minimum-in-rotated-sorted-array/) |
1616
| [Search in Rotated Sorted Array](./search-in-rotated-sorted-array.js) | <img src="https://img.shields.io/badge/-Medium-orange" /> | `Array`, `Binary Search` | [:link:](https://leetcode.com/problems/search-in-rotated-sorted-array/) |
1717
| [3Sum](./3sum.js) | <img src="https://img.shields.io/badge/-Medium-orange" /> | `Array`, `Two Pointers`, `Sorting` | [:link:](https://leetcode.com/problems/3sum/) |
18+
| [Container With Most Water](./container-with-most-water.js) | <img src="https://img.shields.io/badge/-Medium-orange" /> | `Array`, `Two Pointers`, `Greedy` | [:link:](https://leetcode.com/problems/container-with-most-water/) |

container-with-most-water.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const maxArea = (height) => {
2+
let resultantArea = 0,
3+
low = 0,
4+
high = height.length - 1;
5+
6+
while (low < high) {
7+
const smallestHeight = Math.min(height[low], height[high]);
8+
9+
const area = smallestHeight * (high - low);
10+
11+
resultantArea = Math.max(resultantArea, area);
12+
13+
height[low] < height[high] ? low++ : high--;
14+
}
15+
16+
return resultantArea;
17+
};

0 commit comments

Comments
 (0)