Staircase
InterviewTime limit0.25sMemory limit256 MB
Given column heights, find the longest contiguous run where the i-th column from the left has height at least i.
- Level
Medium4 of 10
- Topics
- Array, Greedy, Implementation, Two pointers
- Solved
- No attempts yet
Problem
A graph that shows the distribution of data as in the figure below is called a histogram.

You want to find the largest staircase in the histogram region. A staircase is a region that satisfies the following conditions.
- The 'length' of a staircase is the number of histogram columns it contains.
- When the length of a staircase is , the height of the -th column from the left is . That is, the leftmost column has height 1, the next column has height 2, and the rightmost column has height .
The histogram region only needs to contain the staircase, so the histogram's height only needs to be at least the staircase's height; it does not need to be exactly equal.
In the histogram above, the largest staircase is shown below. The largest staircase means the staircase with the greatest length. Given a histogram as input, find the length of the largest staircase.

Input
The first line contains an integer , the number of columns in the histogram.
The second line contains integers , the heights of the columns.
Output
Print the length of the longest staircase in the histogram.