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
n, *rest = map(int, open(0).read().split()) h = rest[:n] if rest else [] max_area = 0 stack = [] for i in range(n): while stack and h[i] < h[stack[-1]]: j = stack.pop() left = stack[-1] if stack else -1 current_width = i - left - 1 current_area = h[j] * current_width if current_area > max_area: max_area = current_area stack.append(i) while stack: j = stack.pop() left = stack[-1] if stack else -1 current_width = n - left - 1 current_area = h[j] * current_width if current_area > max_area: max_area = current_area 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.