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 = int(input()) heights = list(map(int, input().split())) heights.append(0) stack = [-1] max_area = 0 for i in range(len(heights)): while len(stack) > 1 and heights[i] < heights[stack[-1]]: h = heights[stack.pop()] left = stack[-1] width = i - left - 1 area = h * width if area > max_area: max_area = area stack.append(i) 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.