As reported: Walmart SWE III onsite hiring drive, round 1 DS/Algo (Bangalore, Mar 2025), third question: Largest Rectangle in Histogram.
Given bar heights heights (each bar has width 1), return the area of the largest rectangle inside the histogram.
This is LeetCode 84 — Largest Rectangle in Histogram.
Example
[2,1,5,6,2,3] -> 10 (bars 5 and 6, height 5, width 2)
[2,4] -> 4
Constraints: 1 ≤ heights.length ≤ 10^5; 0 ≤ heights[i] ≤ 10^4.
Code runner format: one line with heights. Implement largestRectangleArea(heights); the harness prints the area.