dsa1 min read
Number of Substrings Containing All Three Characters [Medium]
Count substrings containing at least one a, b, and c using the last-seen indices shortcut for O(n) time.
Read →
1575 articles
Count substrings containing at least one a, b, and c using the last-seen indices shortcut for O(n) time.
Count subarrays with sum divisible by k using prefix sum modulo k and a frequency map of remainders.
Find k closest integers to x in a sorted array using binary search to locate the optimal left boundary of the window.
Count subarrays where min=minK and max=maxK using a single pass tracking the last invalid position and last positions of minK and maxK.
Find the maximum consecutive ones in a binary array when you can flip at most k zeros, identical to the Max Consecutive Ones III pattern.