Count Distinct Elements in Window

00:00
MediumArraySliding WindowHashMap
AmazonGoogle

Count distinct elements in every window of size k in an array.

Examples

Input → arr=[1,2,1,3,4,2,3], k=4
Output → [3,4,4,3]
Input → arr=[1,2,3,4,5], k=3
Output → [3,3,3]
Input → arr=[1,1,1,1], k=2
Output → [1,1,1]