• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
June 09, 2022 |10.9K Views
Count distinct elements in every window | SDE Sheet | Hashing
Description
Discussion

In this video we will see when given an array of size n and an integer k, how to return the count of distinct numbers in all windows of size k.

Example:

Input: arr[] = {1, 2, 1, 3, 4, 2, 3}; k = 4

Output: 3 4 4 3

Explanation:
First window is {1, 2, 1, 3}, count of distinct numbers is 3
Second window is {2, 1, 3, 4} count of distinct numbers is 4
Third window is {1, 3, 4, 2} count of distinct numbers is 4
Fourth window is {3, 4, 2, 3} count of distinct numbers is 3

Check out the video to see how we implement this!!


Practice Problem: https://practice.geeksforgeeks.org/problems/count-distinct-elements-in-every-window/1
Article: https://www.geeksforgeeks.org/count-distinct-elements-in-every-window-of-size-k/
SDE Sheet: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/

Read More