Largest Rectangle in Histogram
Updated
Problem statement
Given an integer array heights representing a histogram, where every bar has width 1, return the area of the largest rectangle that can be formed using one or more consecutive bars.
Function
largestRectangleArea(heights: int[]) → intExamples
Example 1
heights = [2,1,5,6,2,3]return = 10The bars of heights 5 and 6 form a rectangle of height 5 and width 2.
Example 2
heights = [2,4]return = 4The best area is 4, achieved either by the second bar alone or by both bars at height 2.
Example 3
heights = [0]return = 0The only bar has height 0, so no positive-area rectangle exists.
Constraints
1 <= heights.length <= 100000.0 <= heights[i] <= 10000.
More Zipline Onsite Interview questions
Similar questions at other companies
- Trapping Rain WaterTeradata · ONSITE INTERVIEW
- Trapping Rain WaterBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Count Visible People to the LeftGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Construct a Tree from Level-Order and Inorder TraversalsSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Largest Rectangle in HistogramTekion · ONSITE INTERVIEWTekion interview questions
- Trapping Rain WaterAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Trapping Rain WaterKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Confirmed Profiling Events with First-Observed StartsAnthropic · PHONE SCREEN · ONSITE INTERVIEWAnthropic interview questions
- Trapping Rain WaterNuro · ONSITE INTERVIEWNuro interview questions
- Trapping Rain WaterMicrosoft · ONSITE INTERVIEWMicrosoft interview questions