Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
For each index <code>i</code>, find the rightmost index <code>j >= i</code> such that the frequency of each element in the subarray <code>[i, j]</code> is at most <code>k</code>.
We can use 2 pointers / sliding window to achieve it.