The Burl-Holds of the Ossenwald Greatoak
The Thornwarden Guild posts a commission for climbers bold enough to scale the Ossenwald Greatoak, a tree so vast its crown is lost in cloud. The trunk is smooth save for burls, swollen knots in the bark that serve as holds. The Guild's surveyors have measured the height of every burl on the climbing line. They need to know how high a climber of a given reach can get before the bark leaves them stranded.
The rules of the climb:
- The climber starts on the forest floor, at height
0. - The burls are taken strictly in the order given, which is non-decreasing by height.
- From their current height, the climber may move onto the next burl only if that burl's height minus the current height is at most
reach. If they do, their current height becomes that burl's height. - At the first burl whose gap is greater than
reach, the climb ends. No later burl is considered.
Write climbHeight(holds, reach), where:
holdsis a list of non-negative integers in non-decreasing order, giving the burls' heights in feet. It may be empty.reachis a non-negative integer, in feet.
Return an integer: the climber's height when the climb ends. If every burl is climbed, return the height of the last burl. If no burl is climbed, return 0.
examples
- case 1
holds of [3, 5, 9, 10, 16, 18], reach of 410. The climber goes 0 → 3 → 5 → 9 → 10. The gap from 10 to 16 is 6, which is more than 4, so the climb ends at 10. - case 2
holds of [2, 4, 6, 8], reach of 28. Every gap is exactly 2, which is within reach. - case 3
holds of [6, 7], reach of 50. The first burl is already 6 feet above the floor, so the climber never leaves the ground.
- reward
- 220 XP
- signature
climbHeight
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- stops at first gap too wide
- empty trunk stays on floor
- first burl out of reach
- gaps exactly equal to reach
- long reach climbs everything
- zero reach with burls at floor level
- repeated heights then a gap
- later burls ignored after stop
- single reachable burl