29. Largest Rectangle in Histo
Lesson 30 of 31 in Coddy's 30 Days of Logic Building in Javascript course.
Challenge
MediumGiven an array of non-negative integers representing the height of bars in a histogram, find the largest rectangle that can be formed from the histogram.
- Input:
<strong>[2, 1, 5, 6, 2, 3]</strong> - Expected Output:
<strong>10</strong>(The largest rectangle is formed by heights 5 and 6)
Note - The area of this rectangle is calculated as the width (number of bars) times the minimum height of the bars within the rectangle: <strong>2 * min(5, 6) = 2 * 5 = 10</strong>.

Try it yourself
function largestRectangleArea(heights) {
// write your code below
}All lessons in 30 Days of Logic Building in Javascript
1Introduction
What is here for you?43rd Mile Stone
21. Calculate GCD22. Fizz Buzz23. Two Sum24. Validate Email25. Occurrences of Each Char26. Count Words27. Reverse an Integer28. Subarray Sum Equals K 29. Largest Rectangle in Histo30. Count And Say