During an auction clearing phase at Jump Trading and HRT, an aggregated Limit Order Book snapshot provides available resting liquidity across discrete price levels. The available volume at price tick is represented by a non-negative integer heights[i].
An institutional block trading algorithm seeks to clear a uniform block of liquidity spanning a contiguous sequence of price levels. The volume cleared across contiguous ticks at a uniform depth is given by the rectangular area:
Your Task
Implement largest_liquidity_rectangle(heights: list[int]) -> int that determines the maximum possible liquidity area that can be cleared in strictly time using a monotonic stack.
Constraints
Examples
heights = [2, 1, 5, 6, 2, 3]
# Contiguous rectangle spanning indices 2 and 3 (heights 5 and 6) at depth 5 has area 5 * 2 = 10.
# Output: 10
heights = [2, 4]
# Rectangle spanning index 1 has area 4 * 1 = 4. Rectangle spanning indices 0..1 has min height 2 * 2 = 4.
# Output: 4