A histogram is made of a number of contiguous bars, which have same width. For a given…
- User
A histogram is made of a number of contiguous bars, which have same width.
For a given histogram with bars which have a width of 1 and a height of = respectively, find the area of the largest rectangular area.
Assistant
pythonn, *rest = map(int, open(0).read().split()) h = rest[:n] stack = [] max_area = 0 for i in range(len(h)): while stack and h[i] < h[stack[-1]]: top = stack.pop() width = i if not stack else i - stack[-1] - 1 max_area = max(max_area, h[top] * width) stack.append(i) while stack: top = stack.pop() width = len(h) if not stack else len(h) - stack[-1] - 1 max_area = max(max_area, h[top] * width) print(max_area)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.