-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Maximum_Water_Container.py
60 lines (51 loc) · 1.4 KB
/
Maximum_Water_Container.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Python code for maximum water Container
def maxArea(A): # Function to find Maximum Area
start = 0
end = len(A) - 1
area = 0
while start < end:
# Calculating the max area
area = max(area, min(A[start], A[end]) * (end - start))
if int(A[start]) < int(A[end]):
start += 1
else:
end -= 1
return area
# Driver code
print("Input-->")
# number of elemetns as input
size1 = int(input(" Enter the a size :\n"))
size2 = int(input(" Enter the b size :\n"))
a = []
b = []
# iterating till the range
print(" Enter the elements of a container :")
for i in range(0, size1):
ele1 = int(input())
a.append(ele1) # adding the element
print(" Enter the elements of b container :")
for j in range(0, size2):
ele2 = int(input())
b.append(ele2) # adding the element
print("Output-->")
# displaying the Output
A = int(maxArea(a))
B = int(maxArea(b))
if A > B:
print("Container a with more area contain more water i.e " + str(A))
else:
print("Container b with more area contain more water i.e " + str(B))
"""
Input-->
Enter the a size : 4
Enter the b size : 5
Enter the elements of a container :
1 5 4 3
Enter the elements of b container :
3 2 1 4 5
Output-->
Container b contain more water i.e 12
Time Compelxity: O(n) where n is size of array.
Space Complexity: O(1).
No extra space is required, so space complexity is constant
"""