‹ back to the board

Wednesday, October 14

Adeptalgorithms & data structures

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).

  • frieze is a string of lowercase letters a-z. It may be empty.
  • spell is a non-empty string of lowercase letters a-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.

  • two pointers and sliding windows
  • Adept

examples

  1. case 1frieze of "adobecodebanc", spell of "abc"4 (the stretch "banc")
  2. case 2frieze of "baxxab", spell of "abb"6 (two b's are needed, so only the whole frieze will do; "ba" is not enough)
  3. case 3frieze of "abc", spell of "abd"0 (there is no d anywhere on the frieze)
reward
320 XP
signature
shortestStretch
not yet run

TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.

loading the editor…
  • 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
The Glyph-Frieze of Ashvenn Cliffs · bitwick