Area of Largest Rectangle in Histogram
Given an list of integer
The input will be a single line containing space-separated integers, denoting the heights of the bars.
The output should be a single line containing the area of the largest rectangle in the rectangle.
For example, if the given list of numbers are
2 1 5 6 2 3 , when they are drawn adjacent to each other according to their heights, the histogram will be like The largest rectangle can be found in between 5 and 6, which is 10.
Sample Input 1
2 1 5 6 2 3
Sample Output 1
10
Sample Input 2
65 87 96 31 32 86 57 69 20 42
Sample Output 2
248
l = [int(i) for i in input('Enter the integers: ').split(' ')]
large = 0
for i in range(0, len(l)):
r = l[i]
a = 1
b = 1
while i+a in range(0, len(l)) and l[i+a]>l[i]:
r = r + l[i]
a = a + 1
while i-b in range(0, len(l)) and l[i-b]>l[i]:
r = r + l[i]
b = b + 1
if r > large:
large = r
print(large)
Comments
Leave a comment