FastPrepLargest Square in a Histogram

Largest Square in a Histogram

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA
Learn

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[]) → int

Examples

Example 1

heights = [1,2,3,3]return = 4

Two adjacent bars have height at least two.

Example 2

heights = [3,3,3]return = 9

All three bars support a side-three square.

Constraints

  • 1 <= heights.length <= 100000
  • 0 <= heights[i] <= 100000

More ZipRecruiter problems

See ZipRecruiter hiring insights
public int largestSquareArea(int[] heights) {
    // Write your code here.
}
heights[1,2,3,3]
expected4
Checking account…