dsa1 min read
Subarrays with K Different Integers [Hard] — Sliding Window Subtract
Count subarrays with exactly K distinct integers using the formula: atMost(K) - atMost(K-1).
Read →
1575 articles
Count subarrays with exactly K distinct integers using the formula: atMost(K) - atMost(K-1).
Find the minimum rotations to make all tops or bottoms equal by checking if a target value (from first domino) can unify the entire row.
Reconstruct the stamp sequence in reverse by greedily finding where the stamp can overwrite current characters in the target string.
Find the longest substring that appears at least twice using binary search on length and Rabin-Karp rolling hash for O(n log n) average time.
Design a stack that pops the most frequent element (breaking ties by recency) using frequency and group-stacks mapping.