Largest Skyline Rectangle
A skyline is drawn as adjacent bars of width 1, where heights[i] is the height of bar i. Return the area of the largest axis-aligned rectangle that fits entirely inside the skyline.
Example 1
Input: heights = [2, 1, 5, 6, 2, 3] Output: 10 Explanation: Bars 5 and 6 give a 5 × 2 rectangle.
Example 2
Input: heights = [2, 4] Output: 4
Constraints
- 1 <= heights.length <= 10^5
- 0 <= heights[i] <= 10^4
Hint 1
For each bar, the widest rectangle of its height stretches until a shorter bar on each side.
Hint 2
A stack of increasing heights tells you both boundaries at the moment a bar is popped.
Good practice for: Frontend Developer, Backend Developer, Full Stack Developer, Mobile App Developer, Game Developer, Automation Test Engineer, Data Scientist
Run checks your code on 2 sample tests. Submit runs all 9 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.