5

Count distinct elements in every window | SDE Sheet | Hashing

 1 year ago
source link: https://www.geeksforgeeks.org/videos/count-distinct-elements-in-every-window-sde-sheet-hashing/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Count distinct elements in every window

Count distinct elements in every window | SDE Sheet | Hashing
Hi. In this video, we will
  • 09/06/2022

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/


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK