The problem. Given an array arr and a number k, return how many distinct numbers each window of k consecutive elements contains — one count per window, from left to right. An array of n elements has n − k + 1 windows.
arr = [1, 2, 1, 3, 4, 2, 3], k = 4 -> [3, 4, 4, 3]
arr = [4, 1, 1], k = 2 -> [2, 1]
arr = [5, 5, 5, 5], k = 3 -> [1, 1]Free account
Sign up to read the rest of this lesson: 6 more sections, 2 drawings, a dry-run simulator and code in JavaScript, Python, Java and C++.
Still to come