Adeptalgorithms & data structures
The Sigil-Tablet of Ferrowind Caldera
On the floor of Ferrowind Caldera, a row of basalt columns stands shoulder to shoulder, running west to east. Each column is exactly one stride wide, and no gap separates neighbours. The Wardwrights' Guild has posted a commission. They will carve one rectangular warding sigil across the faces of a contiguous run of columns. The sigil's base rests on the caldera floor, and its top may not rise above the shortest column in that run. The Guild pays by area, so they want the largest sigil the row can hold.
Write largestSigil(heights).
heightsis a list of non-negative integers. The value at each position is the height of that column, in strides, in west-to-east order. The list may be empty, and a height may be0.- For a non-empty contiguous run from index
ito indexjinclusive, the area of the sigil is(j - i + 1) * min(heights[i..j]). - Return the largest such area over all non-empty contiguous runs, as an integer.
- If
heightsis empty, return0.
examples
- case 1
heights of [2, 1, 5, 6, 2, 3]10 - the columns of height 5 and 6 carry a sigil 2 strides wide and 5 tall - case 2
heights of [2, 1, 2]3 - the short middle column lets a sigil 1 tall span all three columns, beating either tall column alone - case 3
heights of [] (no columns at all)0
- reward
- 360 XP
- signature
largestSigil
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
loading the editor…
- guild_sample
- empty_row
- single_column
- all_zero
- two_columns
- equal_heights
- rising_row
- falling_row
- mixed_row
- zero_splits_row
- short_middle_spans
- long_low_ridge_with_spire