[Java] Leetcode 11. Container With Most Water [Two Pointers #5]

preview_player
Показать описание
In this video, I'm going to show you how to solve Leetcode 11. Container With Most Water which is related to Two Pointers.

Here’s a quick rundown of what you’re about to learn:

⭐️ Course Contents ⭐️
⌨️ (0:00) Question
⌨️ (2:09) Solution Explain
⌨️ (4:22) Code

In the end, you’ll have a really good understanding on how to solve Leetcode 11. Container With Most Water and questions that are similar to this Two Pointers.

Рекомендации по теме
Комментарии
Автор

Thanks for teaching me two pointers approach, solved this problem like it was easy lvl :P

lzobvfv
Автор

Hello Eric. The logic is good, but what happens when both the pointers are at the same value? Ideally we should be looking down from each side and move to a highest next tower. But that isn’t covered in this logic

greatrocker
Автор

How do you come to the conclusion that you & U Vis need to use the two pointers technique for this problem?

EmmanuelAgyapong-jnue
Автор

class Solution {
public int maxArea(int[] height) {
int N = height.length;
int L = 0;
int R = N - 1;
int min = 0;
int max = 0;
while (L < R) {
min = Math.min(height[L], height[R]);
max = Math.max(max, (min * (R - L)));
if (height[L] < height[R]) {
L++;
} else {
R--;
}
}
return max;

}
}

Rob-J-BJJ