Member-only story

Sliding Window Technique(Array)

Data Structures & Algorithm (DSA)

Josephine Gyamera
6 min readFeb 8, 2024
Images from Canva

I have been going through DSA lately, and during my exploration, I stumbled upon the Sliding Window Technique. At first, it seemed tricky, but as I visualized it, everything fell into place. This article breaks down the essence of this technique, when to use it, and how to spot problems where it’s handy.

Understanding the Sliding Window Technique:

The Sliding Window Technique is an approach used to solve problems involving contiguous (sequential) data structures such as arrays, strings, and linked lists. It consists of creating a “window” that slides either to the left or right within the data structure based on specific conditions. This technique is particularly useful for efficiently solving problems where you need to find a subarray, substring, or sublist that meets certain criteria. For example, you can use it to:

  1. Find the maximum sum of a subarray with a specific size.
  2. Find the minimum subarray with a sum meeting a target.
  3. Find the longest string with distinct characters.
  4. Check if a substring exists within another string.

In this blog, we will only explore the first two problems which deal with arrays. For the substrings…

--

--

Josephine Gyamera
Josephine Gyamera

Written by Josephine Gyamera

Just learning cool Tech stuffs😎

No responses yet