The Gate That Reads the Wall
The warden's gate in bitwick stands beside a long wall of rune-marks. The wall is given as runes, a string of lowercase letters, read left to right. The gate's charm is given as charm, a string of lowercase letters; the charm is not a pattern to match but a bag of marks the gate demands, and repeats count — if the charm names a letter three times, the gate wants that letter three times.
The warden opens the gate by chalking a bracket around one unbroken run of consecutive marks on the wall. A run satisfies the gate when, counted with multiplicity, it contains every letter of the charm at least as many times as the charm names it. Extra marks inside the run are harmless, and the marks may sit in any order.
Write shortestCharm(runes, charm), which returns the shortest run of consecutive characters of runes that satisfies the charm, as a string. If several runs tie for shortest, return the one that begins earliest in runes. If no run satisfies the charm, return the empty string. If charm is empty, return the empty string.
examples
- case 1
runes of "adobecodebanc", charm of "abc""banc" - the run starting at index 9; every shorter run is missing at least one of a, b, c - case 2
runes of "abbcab", charm of "aab""abbca" - the charm wants two a's, so the run must reach both of them - case 3
runes of "aa", charm of "aaa""" - the wall never holds three a's at once
- reward
- 320 XP
- signature
shortestCharm
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- classic wall
- charm with a repeated letter
- earliest of tied shortest runs
- shortest run sits late on the wall
- a run of four beats the obvious one
- wall cannot satisfy the charm
- empty charm
- blank wall
- single mark suffices