Skip to content

Commit 214fdad

Browse files
authored
added problem number 011 (container-with-most-water)(https://leetcode.com/problems/container-with-most-water/) (#501)
* added problem container-with-most-water and updated readme
1 parent 80c004e commit 214fdad

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

C++/container-with-most-water.cpp

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// https://leetcode.com/problems/container-with-most-water
2+
// code for the question : "container-with-most-water"
3+
// language : cpp
4+
5+
6+
class Solution {
7+
public:
8+
int maxArea(vector<int>& height) {
9+
int n = height.size();
10+
int max_area = 0; // Variable to store the maximum water that can be contained
11+
int i = 0; // Left pointer
12+
int j = n - 1; // Right pointer
13+
14+
// Use two-pointer approach to find the maximum area
15+
while (i < j) {
16+
// Calculate the area between the two current pointers
17+
int current_area = (j - i) * min(height[i], height[j]);
18+
19+
// Update the maximum area found so far
20+
max_area = max(max_area, current_area);
21+
22+
// Move the pointer with the smaller height
23+
if (height[i] < height[j]) {
24+
i++; // Move left pointer to the right
25+
} else {
26+
j--; // Move right pointer to the left
27+
}
28+
}
29+
return max_area;
30+
}
31+
};
32+

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
124124
| 119 | [Pascal's Triangle II](https://leetcode.com/problems/pascals-triangle-ii) | [Python](./Python/pascals-triangle-ii.py) | _O(N^2)_ | _O(K)_ | Easy | | |
125125
| 1480 | [Running Sum of 1d Array](https://leetcode.com/problems/running-sum-of-1d-array/) | [Java](./Java/running-sum-of-1d-array.java) | _O(N)_ | _O(N)_ | Easy | Simple sum | |
126126
| 42 | [Trapping Rain Water](https://leetcode.com/problems/trapping-rain-water/) | [Python](./Python/trapping_rain.py) | _O(N^2)_ | _O(N)_ | Hard | Array | |
127-
| 11 | [Container with Most Water](https://leetcode.com/problems/container-with-most-water/) | [Python](./Python/container_with_most_water.py) | _O(N)_ | _O(N)_ | Medium | Array Two Pointers | |
127+
| 11 | [Container with Most Water](https://leetcode.com/problems/container-with-most-water/) | [Python](./Python/container_with_most_water.py) <br> [C++](./C++/container-with-most-water.cpp) | _O(N)_ | _O(N)_ | Medium | Array Two Pointers | |
128128
| 1134 🔒 | [Armstrong Number](https://leetcode.com/problems/armstrong-number/) | [Java](./Java/Armstrong-Number.java) | _O(N)_ | _O(1)_ | Easy | | |
129129
| 1534 | [Count Good Triplets](https://leetcode.com/problems/count-good-triplets/) | [Python](./Python/count-good-triplets.py) | _O(N^3)_ | _O(1)_ | Easy | | |
130130
| 1572 | [Matrix Diagonal Sum](https://leetcode.com/problems/matrix-diagonal-sum/) | [Java](./Java/matrix-diagonal-sum.java) | _O(N)_ | _O(1)_ | Easy | | |
@@ -297,6 +297,7 @@ Check out ---> [Sample PR](https://github.com/codedecks-in/LeetCode-Solutions/pu
297297
| 015 | [3 Sum](https://leetcode.com/problems/3sum/) | [C++](./C++/3sum.cpp) | _O(N)_ | _O(1)_ | Medium | Two Pointer | |
298298
| 021 | [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/) | [C++](./C++/Longest-Mountain-in-Array.cpp) | _O(N)_ | _O(1)_ | Easy | Two Pointer | |
299299

300+
300301
<br/>
301302
<div align="right">
302303
<b><a href="#algorithms">⬆️ Back to Top</a></b>
@@ -515,6 +516,8 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if
515516
| [Shrimadh V Rao](https://github.com/Shrimadh) <br> <img src="https://avatars.githubusercontent.com/u/64469917?v=4" width="100" height="100"> | India | C++ | [GitHub](https://github.com/Shrimadh)
516517
| [Shreyas Shrawage](https://github.com/shreyventure) <br> <img src = "https://avatars.githubusercontent.com/u/55741087?v=4" width="100" height="100"> | India | Python | [CodeChef](https://www.codechef.com/users/shreyventure)<br/>[LeetCode](https://leetcode.com/shreyventure/)<br/>[HackerRank](https://www.hackerrank.com/shreyas_shrawage)
517518
| [Surbhi Mayank](https://github.com/surbhi2408) <br> <img src="https://avatars.githubusercontent.com/u/58289829?s=400&u=68fd396819b927ec4d8820d87d6d1e311c3abd01&v=4" width="100" height="100"> | India | C++ | [GitHub](https://github.com/surbhi2408)
519+
| [Amrit Kumar](https://github.com/amrit-GH23) <br> <img src="https://avatars.githubusercontent.com/u/146119347?s=400&u=599ba9f51c94e08861dc01580db03fadde609ad8&v=4" width="100" height="100"> | India | C++ | [CodeChef](https://www.codechef.com/users/amrit_kumar08)<br/>[Linkedin](https://www.linkedin.com/in/amrit-kumar-28053b253/)
520+
518521
<div align="right">
519522
<b><a href="#algorithms">⬆️ Back to Top</a></b>
520523
</div>

0 commit comments

Comments
 (0)