The Glyph-Frieze of Ashvenn Cliffs
Along the face of the Ashvenn Cliffs runs a single carved frieze, a long row of glyphs left by a vanished order. The Wardbinders of Ashvenn work a binding by laying their palms on one unbroken stretch of that frieze. The stretch is valid only if it contains every glyph the incantation calls for, at least as many times as the incantation uses it. Order within the stretch does not matter, and extra glyphs inside the stretch are allowed. The Wardbinders' commission pays for the shortest valid stretch.
Write shortestStretch(frieze, spell).
friezeis a string of lowercase lettersa-z. It may be empty.spellis a non-empty string of lowercase lettersa-z. It may contain repeated letters.
A stretch is a contiguous substring of frieze. It is valid when, for every letter, it contains that letter at least as many times as spell does.
Return the length (an integer) of the shortest valid stretch. If no valid stretch exists, return 0.
examples
- case 1
frieze of "adobecodebanc", spell of "abc"4 (the stretch "banc") - case 2
frieze of "baxxab", spell of "abb"6 (two b's are needed, so only the whole frieze will do; "ba" is not enough) - case 3
frieze of "abc", spell of "abd"0 (there is no d anywhere on the frieze)
- reward
- 320 XP
- signature
shortestStretch
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- classic window
- multiplicity forces whole frieze
- missing glyph
- empty frieze
- spell longer than frieze
- single glyph match
- whole frieze any order
- repeated single letter
- mississippi sip
- mississippi double p double i
- adjacent pair in middle
- extra glyphs elsewhere