You are given an array of integers
arr
where each element represents the height of a bar in a histogram. The bars are placed in the exact same sequence as given in the array. You need to find the area of the largest rectangle found in the histogram.
Problem Note
- The width of each bar is 1 unit.
- You cannot change the sequence of bars.
The above histogram is represented by the array [2, 4, 8, 10, 8, 4, 2]. In this case, the area of the largest rectangle found is 24 units(green section) in the histogram.
Example 1:
Input: [2, 4, 8, 10, 8, 4, 2]
Output: 24
Explanation: You can see the above image in which the input array is drawn as a histogram. Here, all the green boxes represent the area of the largest rectangle found in the histogram.