The Rising Storms of the Brasswind Spires
High on the Brasswind Spires, the Weatherwrights' Lodge keeps a record of every storm that breaks over the peaks. Each thunderclap is written down as an integer loudness, in the order it was heard. The Lodge pays a bounty to anyone who can cut a storm's record into its rising rolls, so the storm-readers can study how each surge of thunder built.
A rising roll is a run of consecutive thunderclaps in which every clap is strictly louder than the one immediately before it. Each roll is made as long as possible.
Write risingRolls(claps), where claps is a list of integers giving the loudness of each thunderclap in order.
Return a list of lists of integers: the claps split into consecutive rising rolls, in their original order.
- Joining the rolls end to end gives back
clapsexactly. - Within each roll, every value is strictly greater than the value before it.
- A clap that is equal to or quieter than the clap immediately before it begins a new roll.
- A roll may contain a single clap.
- If
clapsis empty, return an empty list.
examples
- case 1
claps of [3, 5, 9, 2, 4, 4, 7][[3, 5, 9], [2, 4], [4, 7]] - the 2 is quieter than the 9, and the second 4 does not rise above the first - case 2
claps of [6, 6, 6][[6], [6], [6]] - equal claps never rise, so each stands alone - case 3
claps of [] (a storm that never broke)[]
- reward
- 210 XP
- signature
risingRolls
TypeScript, run as ES2022 — types are stripped, not checked. If a JS engine would run it, so will we.
- mixed storm with a tie
- empty record
- single clap
- strictly falling
- one long rise
- all equal
- negative loudness
- drop at the very end