Problem · Medium · 25 min
The longest run of few kinds
- Medium
- Sliding window
- Arrays
A bird watcher writes down the bird that she sees each minute. The list has one name for each minute, for example ["owl", "wren", "owl", "crow"].
Write longestRun(sightings, maxKinds). It returns the length of the longest run of neighbouring minutes in which she saw at most maxKinds different birds.
- A run is a part of the list without gaps: the positions from
itojfor somei <= j. maxKindsis a whole number that is at least 1.- For an empty list, the answer is 0.
Examples
| Call | Result |
|---|---|
longestRun(['owl', 'wren', 'owl', 'crow'], 2) |
3 |
longestRun(['owl', 'owl', 'owl'], 1) |
3 |
longestRun([], 2) |
0 |
Tasks
2 to do
Task 1, not checked yet. Make
longestRunpass the example tests.Task 2, not checked yet. Make
longestRunpass the hidden tests.
Task 1 of 2
Make longestRun pass the example tests.