Tags

Sliding Window

Sliding Window

1 lesson
11 problems
3 code snippets
3 question banks
1 system design
7 community items

sliding-window

Algorithms

1 lesson

Sliding Window (Intro)

Free
Beginner

55 min

2 prereqs

To find the longest substring of `s` with no repeated characters, the brute-force approach checks every substring in `O(n^3)` time. The sliding-window solution touches each character at most twice and runs in `O(n)`: extend a right pointer until a duplicate appears, then advance a left pointer until the duplicate is gone, repeating until the right pointer falls off the end. **Sliding Window (Intro)** turns that idea into two reusable templates. The fixed-size window slides a range of length `k` across the array and updates the running sum or count by adding the new right element and removing the old left element, never recomputing from scratch. The variable-size window expands the right edge while a condition holds and shrinks the left edge to restore that condition, tracking the window's contents with a hash map or counter. You will apply both to maximum-sum subarray of size `k`, longest substring without repeating characters, minimum window substring, and longest substring with at most `k` distinct characters. In **Two Pointers (Intro)**, you used coordinated indices to walk an array linearly. **Hash Map (Dictionary) Basics** gave you the `O(1)` lookup and update that lets a window track its own contents efficiently. Sliding window combines both: two indices and one hash map. From here you turn to **Recursion Fundamentals**, which trades sequential index movement for self-similar subproblems.

Not Started

0%

Algorithms
Sliding Window
Arrays
Strings
Subarray / Substring Problems
Time Complexity
Beginner
Free

Practice Problems

11 problems

Best Time to Buy and Sell Stock

Free
Not Started
Easy

Find the maximum profit from buying and selling a stock once, given daily prices.

Arrays
Sliding Window
Kadane's Algorithm
Beginner

1.1k

22

Contains Duplicate II

Free
Not Started
Easy

Check if an array contains two distinct indices with the same value whose absolute difference is at most k.

Arrays
Hash Map / Dictionary
Sliding Window
Beginner

181

1

Maximum Average Subarray I

Free
Not Started
Easy

Find the contiguous subarray of a given length k that has the maximum average value.

Arrays
Sliding Window
Beginner

164

2

Minimum Window Substring

Not Started
Hard

Find the smallest substring of s that contains all characters of t, including duplicates.

Strings
Sliding Window
Hash Map / Dictionary
Frequency Count
Advanced

346

9

Sliding Window Maximum

Not Started
Hard

Find the maximum value in each sliding window of size k as it moves across the array.

Arrays
Sliding Window
Deque
Monotonic Queue
Advanced

289

5

Substring with Concatenation of All Words

Not Started
Hard

Find all starting indices where a concatenation of all given words (each of equal length) forms a substring.

Strings
Sliding Window
Hash Map / Dictionary
Frequency Count
Advanced

455

14

Find All Anagrams in a String

Not Started
Medium

Find all start indices where an anagram of pattern p occurs in string s.

Strings
Sliding Window
Hash Map / Dictionary
Frequency Count
Anagrams
Intermediate

1.1k

22

Longest Repeating Character Replacement

Free
Not Started
Medium

Find the length of the longest substring containing the same letter after performing at most k character replacements.

Strings
Sliding Window
Hash Map / Dictionary
Intermediate

212

5

Longest Substring Without Repeating Characters

Free
Not Started
Medium

Find the length of the longest substring without repeating characters using the sliding window technique.

Strings
Sliding Window
Hash Map / Dictionary
Intermediate

506

3

Minimum Size Subarray Sum

Not Started
Medium

Find the minimal length subarray whose sum is greater than or equal to the target.

Arrays
Sliding Window
Intermediate

282

1

Permutation in String

Not Started
Medium

Given two strings, determine if one string's permutation is a substring of the other.

Strings
Sliding Window
Hash Map / Dictionary
Frequency Count
Intermediate

1.1k

37

Question Banks

3 items
Question Bank
Premium

Deque and Sliding Window Max

Five prompts on the monotonic deque pattern: implementing sliding window maximum, the invariant that makes it O(n), and adjacent online-statistics applications.

Python
deque
sliding-window
algorithms
interview-prep

981

27

Hard
Question Bank

Sliding Window Essentials

Five mid-level prompts on fixed and variable sliding windows: max sum, longest substring without repeats, and a window-shrink invariant. Mixes implementation and trace.

JavaScript
sliding-window
algorithms
interview-prep

621

6

Medium
Question Bank
Premium

JavaScript Longest and Shortest Unique Substring: Two Approaches Quiz

Two seeded approaches to find the longest and shortest unique substrings (restart-on-conflict and instrumented restart), plus two companions on a real sliding window and complexity analysis.

JavaScript
quiz
strings
sliding-window
interview-prep

417

2

Hard

Community

7 items
Article

Sliding Window Technique

What sliding window actually optimises (state reuse, not just same-direction pointers), the fixed vs variable templates, four canonical problems, and when the technique is the wrong tool.

sliding-window
two-pointers
array-manipulation-patterns
subarray-substring
interview-prep

827

9

May 16, 2026

by @sophiesharma

Problem
Hard
$8.99

Subarrays with K Different Integers

Count subarrays containing exactly K distinct integers using the at-most-K window trick.

arrays
sliding-window
hash-table

562

18

4.3 (13)

Mar 14, 2026

by @leoeriksson

Problem
Medium
Free

Subarray Product Less Than K

Count contiguous subarrays whose product is strictly less than k, in linear time using a sliding window.

arrays
sliding-window
two-pointers

817

13

4.3 (14)

Mar 4, 2026

by @yukisantos

Article

Rate Limiting: Token Bucket vs Sliding Window

Token bucket is the right default. Sliding window log is correct but expensive. Fixed window is the algorithm I would not ship.

rate-limiting
token-bucket
sliding-window
api-design
system-design

198

2

4.2 (12)

Feb 11, 2026

by @adityadesai

Problem
Medium
Free

Design Hit Counter

Build a counter that returns the number of hits in the past 5 minutes (300 seconds), with monotonically non-decreasing timestamps.

sliding-window
deque
arrays

929

29

4.3 (13)

Jan 4, 2026

by @meibennett

Problem
Medium
Free

Max Consecutive Ones III

Find the longest contiguous subarray of 1s achievable when you can flip at most K zeros.

arrays
sliding-window

634

14

4.5 (8)

Dec 23, 2025

by @gracebanda

Problem
Medium
Free

Fruit Into Baskets

Find the longest contiguous subarray that contains at most two distinct values.

arrays
sliding-window
hash-table

825

6

4.3 (12)

Dec 7, 2025

by @nehanasser