‹ back to the board

Saturday, September 5

Adeptalgorithms & data structures

The Bridge-Troll's Chiselled Toll

The toll for crossing the bridge at bitwick is chiselled into the stone at the bridge-head: one long row of digits, read left to right as a number. The town has bought the right to have the mason strike digits out of that row, and she will strike exactly `k` of them. Digits left standing keep the order they were carved in, and the shortened row is then read as the toll.

toll is a string of one or more characters, each one of 0-9. It may begin with zeros. k is an integer with 0 <= k <= the length of toll.

Return a string: the smallest number that can be read off the stone after exactly k digits have been struck out, written with no leading zeros. If no digits remain, or all remaining digits are zeros, return "0".

  • stacks and queues
  • Adept
  • efficiency bonus

examples

  1. case 1toll of "1432219", k of 3"1219"
  2. case 2toll of "10200", k of 1"200" - the row reads 0200, and leading zeros are not written
  3. case 3toll of "10", k of 2"0" - nothing remains on the stone
  4. case 4toll of "112", k of 1"11" - no digit is bigger than the one after it, so the strike falls at the right end
reward
360 XP
signature
smallestToll
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…
  • the posted toll
  • a zero in the middle
  • nothing left to pay
  • the mason strikes nothing
  • zeros already carved in front
  • strikes to spare
  • a falling row
  • only zeros remain
  • a single digit struck away
  • the long tally at the bridge-head
The Bridge-Troll's Chiselled Toll · bitwick