forked from TheAlgorithms/C
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11.c
More file actions
27 lines (22 loc) · 671 Bytes
/
Copy path11.c
File metadata and controls
27 lines (22 loc) · 671 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Fucntion to calculate min of values a and b
int min(int a, int b) { return ((a < b) ? a : b); }
// Two pointer approach to find maximum container area
int maxArea(int *height, int heightSize)
{
// Start with maximum container width
int start = 0;
int end = heightSize - 1;
int res = 0;
while (start < end)
{
// Calculate current area by taking minimum of two heights
int currArea = (end - start) * min(height[start], height[end]);
if (currArea > res)
res = currArea;
if (height[start] < height[end])
start = start + 1;
else
end = end - 1;
}
return res;
}