Wave sets
- O(n) · Medium
- Full plan
- Python
- JavaScript
- lists
- loops
- conditionals
Problem
At Long Bay nobody paddles for a lone wave: surfers wait for sets, big waves that roll in one after another. From the tower, someone writes down the height of every wave that goes by.
Write a function that takes that list of heights, in whole centimeters, and a whole number h, and returns how many sets there were. A set is a group of back-to-back waves taller than h; a single big wave between small ones is also a set. A wave that is exactly h is not big.
With [120, 210, 250, 90, 230, 100] and h = 200 there are two sets, 210, 250 and 230: you return 2, not 3.
If the list is empty or no wave is taller than h, you return 0.
Examples
The example
[120, 210, 250, 90, 230, 100], 200 → 2
All big, a single set
[250, 260, 270], 200 → 1
None big
[100, 150, 180], 200 → 0
A single wave
[250], 200 → 1
Besides these, the challenge has hidden tests that are revealed when you submit your solution.
You start with this
Python
def count_sets(waves, h):
passJavaScript
function countSets(waves, h) {
}It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.