The Banner on the Stepped Wall
The mason of bitwick built the inn's north wall out of stone columns set side by side. Each column is exactly one hand wide, and the mason gave each one whatever height the stone allowed, so the top of the wall steps up and down.
The innkeeper wants to hang one rectangular banner flat against that wall, with its bottom edge resting on the ground. Stone must sit behind every part of the banner — no corner of it may cross open air above a short column.
heights is a list of non-negative integers: the heights of the columns in order from left to right. Every column has width 1.
Return an integer: the largest area of such a banner. That is, the maximum over every contiguous run of columns of (the number of columns in the run) × (the smallest height in the run). If heights is empty, return 0.
examples
- case 1
heights of [2, 1, 5, 6, 2, 3]10 — the two columns of heights 5 and 6 give a banner 2 wide and 5 tall - case 2
heights of [0, 3]3 — the single column of height 3; any run including the 0 has area 0 - case 3
heights of [4]4
- reward
- 360 XP
- signature
bannerArea
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- bare ground
- a single column
- the stepped wall
- no stone at all
- rising stair
- falling stair
- level plateau
- one shallow notch spans all
- the long sawtooth wall