towers.
Fit an axis-aligned rectangle into the skyline so that it rests on the ground and lies entirely within the towers. Return the largest possible area of such a rectangle.towers=[3, 1, 4, 4, 2, 5] → 8
The two towers of height 4 stand side by side: a 4 × 2 rectangle has area 8. Height 2 across towers 2–5 also gives 8, and nothing beats that.
towers=[2, 2, 2, 2] → 8
The whole row has the same height: 2 × 4 = 8.
towers=[0, 6, 0] → 6
The zeros on both sides limit the width: 6 × 1 = 6.
towers=[3, 1, 4, 4, 2, 5]
8
Run checks the first 3 tests in your browser. Submit checks all 99 tests on the server, hidden ones included.