Largest Square in a Histogram
Problem statement
Histogram bars have width one. A square of side k fits when some k consecutive bars each have height at least k.
Return the maximum square area k*k.
Function
largestSquareArea(heights: int[]) → intExamples
Example 1
heights = [1,2,3,3]return = 4Two adjacent bars have height at least two.
Example 2
heights = [3,3,3]return = 9All three bars support a side-three square.
Constraints
1 <= heights.length <= 1000000 <= heights[i] <= 100000