codeintuition-logo

Identifying variable sized sliding window pattern


Some specific problems where we need to remember the occurrences of data items in all windows in a sequence can be solved using the variable sized sliding window technique. These are generally medium or hard problems where we need to make some critical observations to prove that skipping some windows does not affect the correctness of the solution. We then create a sliding window and identify when to expand, contract, or move it through the sequence while updating the associated hash map to always map all the data items in the current window to some values.

If the problem statement or its solution follows the generic template below, it can be solved by applying the variable-sized sliding window technique.

Template:

Given an iterable sequence of data, for all windows of all sizes, map all the data items in a window to some values and use them to solve the problem.

Liking the course? Check our discounted plans to continue learning.