educative.io

Cant Wrap my head around the Logic

In the Solution for this problem,

In Line 14 why are we checking if we crosses the extra 0’s limit using if and not a while loop ?

If we have encountered, more 0’s than the k then shouldn’t we be increasing the start until we have reduced the 0’s count under k by using a while loop ?

3 Likes

The top comment on this Leetcode post really helped me understand this same question on the previous problem (it applies to this one as well): https://leetcode.com/problems/longest-repeating-character-replacement/discuss/91271/Java-12-lines-O(n)-sliding-window-solution-with-explanation

1 Like