Largest rectangle under bars
heights describes a row of bars standing side by side, each 1 unit wide. Return the area of the largest rectangle that fits entirely under the bars. A rectangle may span several adjacent bars; its height is limited by the shortest bar it covers.
Aim for O(n): trying every pair of edges is O(n²).
Besides the tests, one large input (3,000 bars) with a ~200 ms limit (scaled to your device's speed): brute force won't pass.
Examples
largest_rectangle([2,1,5,6,2,3])→10largest_rectangle([2,4])→4largest_rectangle([3,3,3,3])→12