Variable Size Sliding Window Problem
In these sliding window questions we have been asked about the maximum or minimum subarray/substring with some conditions (like having largest sum, smallest sum etc.)
For example: Find length of the longest substring without repeating characters.
Post Link: Click Here
Intuition: To solve the problems based on the above category follow the below intuition steps:
- In these kind of problems we can increase right pointer till we found some character (say ‘x‘) which is already in our range, store the answer and increase left pointer till we found that character (‘x’) again, We can keep moving forward and store the answer.
- As we can see in this question our window size is variable so that’s why these problems are called variable size sliding window problem.
Similar problems following same approach:
Sliding Window Problems | Identify, Solve and Interview Questions
When we are dealing with problems that require checking answers of some ranges in an array, the Sliding window algorithm can be a very powerful technique.