VisaOA #15
Largest Square Area in Cityscape
Estimated MediumJudge-ready
Topics (AI-labelled)Stacks & HeapsBinary Search
You are given an array of non-negative building heights. Find the largest area of a square that fits beneath a contiguous run of buildings; side s is feasible if and only if there are s consecutive buildings each with height at least s. This criterion corresponds to the explicit condition in the source's solution section.
Input
n (1≤n≤200000), n heights h (0≤h≤10^9); the ranges are site-added.
Output
Output the largest square area.
Example 1
Input:
5
1 2 3 2 1
Output:
4
Example 2
Input:
2
0 0
Output:
0
Example 3
Input:
3
3 3 3
Output:
9
Editorial
Loading solution…