A chart library wants to place a text label inside a bar chart where it has the most room. The bars are side by side, each 1 unit wide, and heights[i] is the height of bar i.
Write largestArea(heights) that returns the area of the largest rectangle that fits completely inside the bars. The rectangle must sit on the baseline and cover a run of neighboring bars, and its height can't be more than the shortest bar it covers.
Input: heights = [3,1,4,6,5,2] Output: 12
Bars 4, 6, and 5 hold a rectangle of height 4 and width 3, area 12.
Input: heights = [2,4] Output: 4
Either the single bar 4, or both bars at height 2: area 4.
1 <= heights.length <= 10^50 <= heights[i] <= 10^4Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #268 Biggest Rectangle Under a Bar Chart. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.