‹ back to the board

Saturday, October 3

Adeptalgorithms & data structures

The Hedge-Witches of the Thornwall

Commission of the Coven of Brackenmoor.

The Thornwall is a living hedge that rings the borderland against whatever walks out of the Gloamwood. Each dusk every segment of it must be sung shut, and each segment demands a known number of verses.

The Coven sends out a number of hedge-witches together. Each witch is given one unbroken stretch of consecutive segments and sings all of them. Every segment must be sung by exactly one witch. A witch may be given no segments at all. The Coven wants the division that makes the heaviest stretch (the one with the most verses in total) as light as possible.

The contract. Write heaviestStretch(wards, witches).

  • wards is a list of non-negative integers: the verses each segment needs, in order along the wall. It may be empty.
  • witches is a positive integer.

Split wards into at most witches contiguous groups. Keep the original order, and put every element in exactly one group. Among all such splits, find the one whose largest group sum is smallest, and return that largest group sum as an integer. If wards is empty, return 0.

  • binary search
  • Adept
  • efficiency bonus

examples

  1. case 1wards of [7, 2, 5, 10, 8], 2 witches18 — one witch takes [7, 2, 5] (14 verses), the other takes [10, 8] (18 verses)
  2. case 2wards of [3, 9, 4], 5 witches9 — each segment gets its own witch, two witches sing nothing, and the heaviest stretch is the lone 9
  3. case 3wards of [], 3 witches0
reward
360 XP
signature
heaviestStretch
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…
  • two witches on five segments
  • ascending wall split in two
  • empty wall
  • single segment single witch
  • more witches than segments
  • one witch sings everything
  • all silent segments
  • witches equal segments
  • three witches six segments
  • long mixed wall eight witches
  • long wall with a great knot in the middle
The Hedge-Witches of the Thornwall · bitwick