Largest Area Histogram 2

hard
1. You are given a number n, representing the size of array a.
2. You are given n numbers, representing the height of bars in a bar chart.
3. You are required to find and print the area of largest rectangle in the histogram.

Challenge. Could u solve it in one iteration.
Note. This question is same as Largest Area Histogram just the constrains are higher.

Input Format

Input is managed for you

Output Format

Output is managed for you

Constraints

1. 1 <= heights.length <= 10^5
2. 0 <= heights[i] <= 10^4

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
6
2
1
5
6
2
3
Output
10
Previous
Remove Duplicate Letters
Next
Maximal Rectangle

Related Questions