MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / maxArea

Method maxArea

ContainerWithMostWater.java:2–21  ·  view source on GitHub ↗
(int[] height)

Source from the content-addressed store, hash-verified

1class Solution {
2 public int maxArea(int[] height)
3 {
4 int b1=0;
5 int b2=height.length-1;
6 int r=0;
7 while(b1<b2)
8 {
9 int curMax=(b2-b1)*Math.min(height[b1],height[b2]);
10 if(height[b1]<height[b2])
11 {
12 b1++;
13 }
14 else
15 {
16 b2--;
17 }
18 r=Math.max(r,curMax);
19 }
20 return r;
21 }
22}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected