LeetCodechevron_rightCategorieschevron_rightsliding window
view_carousel

sliding window

133 problems
Easy: 18Medium: 78Hard: 37

sliding window is one of the most repeated interview dimensions. Start with edge-safe fundamentals, then move into pattern-level trade-offs.

Interview Signal

Frequently tests problem modeling, edge handling, and verbal clarity.

Common Pitfall

Template-only answers break under follow-up questioning.

Practice Strategy

Practice in 3-5 problem rounds and always review complexity alternatives.

Recommended Progression

#TitleDifficulty
3

Longest Substring Without Repeating Characters

Find the length of the longest substring without repeating characters using a sliding window and hash map to track state…

Medium
30

Substring with Concatenation of All Words

Find all starting indices of substrings in a string that are concatenations of a given list of words.

Hard
76

Minimum Window Substring

Find the smallest substring of s containing all characters from t using a sliding window with running state updates for …

Hard
187

Repeated DNA Sequences

Solve Repeated DNA Sequences by sliding a length-10 window and tracking seen patterns with a hash set or bitmask.

Medium
209

Minimum Size Subarray Sum

Find the minimal length of a subarray whose sum is greater than or equal to the target using efficient algorithms.

Medium
219

Contains Duplicate II

Check if any two equal numbers exist within k indices using array scanning and hash table lookup efficiently.

Easy
220

Contains Duplicate III

The problem involves finding a pair of indices in an array where the index and value differences are within given limits…

Hard
239

Sliding Window Maximum

Solve the "Sliding Window Maximum" problem using efficient techniques like the sliding window, deque, and priority queue…

Hard
395

Longest Substring with At Least K Repeating Characters

Find the length of the longest substring where every character appears at least k times using sliding window and divide-…

Medium
413

Arithmetic Slices

Count the number of arithmetic subarrays in a given integer array using dynamic programming.

Medium
424

Longest Repeating Character Replacement

Find the length of the longest substring after at most k replacements using a sliding window and character count trackin…

Medium
438

Find All Anagrams in a String

Find all starting indices of p's anagrams in s using sliding window and hash table approach.

Medium
480

Sliding Window Median

Compute the median for each sliding window of size k in an array using efficient array scanning and hash lookup techniqu…

Hard
567

Permutation in String

Check if a string contains a permutation of another string using two-pointer scanning and hash table techniques.

Medium
594

Longest Harmonious Subsequence

Find the length of the longest harmonious subsequence in an integer array using array scanning and hash-based frequency …

Easy
632

Smallest Range Covering Elements from K Lists

Find the minimal range covering at least one number from each of k sorted lists using array scanning and hash lookup eff…

Hard
643

Maximum Average Subarray I

Find the maximum average of any contiguous subarray of length k in a given integer array using a sliding window approach…

Easy
658

Find K Closest Elements

Identify the k integers closest to a target x in a sorted array using binary search and two-pointer strategies efficient…

Medium
689

Maximum Sum of 3 Non-Overlapping Subarrays

Maximize the sum of three non-overlapping subarrays with length k in an integer array using dynamic programming.

Hard
713

Subarray Product Less Than K

Count subarrays with a product strictly less than a given value k using efficient algorithms like binary search and slid…

Medium
718

Maximum Length of Repeated Subarray

Find the maximum length of a subarray that appears in both given integer arrays using dynamic programming.

Medium
837

New 21 Game

Calculate the probability Alice reaches at most n points using state transition dynamic programming efficiently.

Medium
862

Shortest Subarray with Sum at Least K

Find the shortest subarray with a sum of at least k using binary search and sliding window techniques.

Hard
904

Fruit Into Baskets

The Fruit Into Baskets problem requires finding the maximum number of fruits you can pick from a row of trees under spec…

Medium
930

Binary Subarrays With Sum

Count all contiguous subarrays in a binary array whose elements sum exactly to a given goal using prefix sums efficientl…

Medium
978

Longest Turbulent Subarray

Find the length of the longest subarray where element comparisons alternate, using state transition dynamic programming …

Medium
992

Subarrays with K Different Integers

Find subarrays with exactly k distinct integers in an integer array using sliding window and hash lookup techniques.

Hard
995

Minimum Number of K Consecutive Bit Flips

Determine the minimum number of k-length consecutive bit flips needed to convert all zeros to ones in a binary array eff…

Hard
1004

Max Consecutive Ones III

Find the longest consecutive ones in a binary array by optimally flipping at most k zeros using sliding window technique…

Medium
1016

Binary String With Substrings Representing 1 To N

Check if binary string contains all integers from 1 to n as substrings, leveraging sliding window and bit manipulation t…

Medium
1031

Maximum Sum of Two Non-Overlapping Subarrays

Find the maximum sum of two non-overlapping subarrays by efficiently using state transition dynamic programming.

Medium
1040

Moving Stones Until Consecutive II

Determine the minimum and maximum moves to make stones consecutive using sliding window and endpoint adjustments efficie…

Medium
1044

Longest Duplicate Substring

Find the longest duplicated substring in a string using binary search, sliding window, and rolling hash techniques.

Hard
1052

Grumpy Bookstore Owner

Maximize satisfied customers in a bookstore by strategically suppressing the owner's grumpy minutes using a sliding wind…

Medium
1156

Swap For Longest Repeated Character Substring

Find the maximum length of a repeated character substring after swapping two characters using a sliding window approach …

Medium
1208

Get Equal Substrings Within Budget

Optimize substring transformations using a binary search approach to maximize the change within a budget.

Medium
1234

Replace the Substring for Balanced String

Determine the minimum substring length to replace in order to balance a string of Q, W, E, and R characters efficiently.

Medium
1248

Count Number of Nice Subarrays

The problem requires counting subarrays with exactly k odd numbers using an efficient array scanning approach.

Medium
1297

Maximum Number of Occurrences of a Substring

Find the maximum number of occurrences of any valid substring in a given string with specific constraints on letter coun…

Medium
1343

Number of Sub-arrays of Size K and Average Greater than or Equal to Threshold

Given an array, find the number of sub-arrays of size k with an average greater than or equal to a given threshold.

Medium
1358

Number of Substrings Containing All Three Characters

Count all substrings containing at least one of each character a, b, and c using a sliding window approach efficiently.

Medium
1423

Maximum Points You Can Obtain from Cards

Maximize your score by selecting k cards from the beginning or end of the array using a sliding window approach.

Medium
1425

Constrained Subsequence Sum

Solve the Constrained Subsequence Sum problem using dynamic programming, sliding window, and priority queues to maximize…

Hard
1438

Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit

Find the longest subarray with elements whose absolute difference is within a specified limit using a sliding window app…

Medium
1456

Maximum Number of Vowels in a Substring of Given Length

Find the maximum number of vowels in a substring of a given length in a string using a sliding window approach.

Medium
1477

Find Two Non-overlapping Sub-arrays Each With Target Sum

Find two non-overlapping sub-arrays with a given target sum and return the minimal total length efficiently using array …

Medium
1493

Longest Subarray of 1's After Deleting One Element

Solve LeetCode 1493 by tracking runs of 1s around one deletion using a tight sliding window or state transition DP.

Medium
1499

Max Value of Equation

Max Value of Equation asks to find the maximum value of a specific equation on a set of 2D points using sliding window t…

Hard
1610

Maximum Number of Visible Points

Determine the maximum number of points visible from a fixed location within a given angle using a sliding window approac…

Hard
1652

Defuse the Bomb

Defuse the Bomb uses a sliding window to update a circular array based on a key, with efficient state updates.

Easy
1658

Minimum Operations to Reduce X to Zero

Find the minimum number of operations to reduce a value x to zero by removing elements from an array.

Medium
1695

Maximum Erasure Value

Maximize the score by erasing a subarray with unique elements in an array of integers.

Medium
1703

Minimum Adjacent Swaps for K Consecutive Ones

Find the minimum number of adjacent swaps to gather k consecutive ones in a binary array using sliding window logic.

Hard
1763

Longest Nice Substring

Find the longest nice substring in a given string using the sliding window technique with running state updates.

Easy
1838

Frequency of the Most Frequent Element

Maximize the frequency of an element in an array by incrementing at most `k` elements. Use binary search and greedy tech…

Medium
1839

Longest Substring Of All Vowels in Order

Find the longest substring of all vowels in order within a given string of vowels using sliding window technique.

Medium
1871

Jump Game VII

The problem asks to determine if we can reach the last index of a binary string, with a set range of jumps between indic…

Medium
1876

Substrings of Size Three with Distinct Characters

Count all substrings of length three in a string where each character is unique using sliding window techniques efficien…

Easy
1888

Minimum Number of Flips to Make the Binary String Alternating

Find the minimum number of flips to make a binary string alternate, using state transition dynamic programming.

Medium
1984

Minimum Difference Between Highest and Lowest of K Scores

Minimize the difference between the highest and lowest of k student scores using a sliding window approach.

Easy
2009

Minimum Number of Operations to Make Array Continuous

Find the minimum number of operations to make an array continuous by modifying elements using array scanning and hash lo…

Hard
2024

Maximize the Confusion of an Exam

Maximize the Confusion of an Exam requires adjusting at most k answers to create the longest consecutive true or false s…

Medium
2090

K Radius Subarray Averages

Efficiently calculate the k-radius average for subarrays using sliding window technique.

Medium
2106

Maximum Fruits Harvested After at Most K Steps

Compute the maximum fruits collectable on an infinite line by moving at most k steps from a start position efficiently.

Hard
2134

Minimum Swaps to Group All 1's Together II

Solve the minimum swaps to group all 1's together in a circular binary array using an optimized sliding window approach.

Medium
2156

Find Substring With Given Hash Value

Locate the first substring of length k whose rolling hash matches the given hashValue using a sliding window approach.

Hard
2260

Minimum Consecutive Cards to Pick Up

Solve Minimum Consecutive Cards to Pick Up by tracking each card's last index and minimizing duplicate spans during one …

Medium
2269

Find the K-Beauty of a Number

Calculate the k-beauty of a number by counting substrings of length k that divide the original number evenly using a sli…

Easy
2271

Maximum White Tiles Covered by a Carpet

Solve Maximum White Tiles Covered by a Carpet by sorting intervals, checking optimal carpet starts, and counting full pl…

Medium
2302

Count Subarrays With Score Less Than K

Count all non-empty subarrays whose score, defined as sum times length, is strictly less than a given integer k efficien…

Hard
2379

Minimum Recolors to Get K Consecutive Black Blocks

Given a string of blocks, determine the minimum number of recolors needed to get k consecutive black blocks.

Easy
2398

Maximum Number of Robots Within Budget

Determine the maximum number of consecutive robots you can operate without exceeding a given budget using efficient bina…

Hard
2401

Longest Nice Subarray

Find the length of the longest nice subarray where the bitwise AND of all pairs of elements in the subarray is zero.

Medium
2411

Smallest Subarrays With Maximum Bitwise OR

Find the smallest subarrays with the maximum bitwise OR for each starting index in an array.

Medium
2444

Count Subarrays With Fixed Bounds

Count all subarrays where the minimum and maximum match given bounds using efficient sliding window tracking techniques.

Hard
2461

Maximum Sum of Distinct Subarrays With Length K

Find the maximum sum of all distinct-element subarrays of length k using array scanning and hash lookup techniques.

Medium
2516

Take K of Each Character From Left and Right

Find the minimum number of minutes needed to take at least k of each character from both ends of a string.

Medium
2528

Maximize the Minimum Powered City

Determine the maximum minimum power a city can achieve by strategically adding power stations using binary search and pr…

Hard
2537

Count the Number of Good Subarrays

Count the number of subarrays that contain at least k pairs of equal elements using array scanning and hash lookup.

Medium
2555

Maximize Win From Two Segments

Maximize the total prizes by choosing two segments of length k on a sorted line of prize positions efficiently using bin…

Medium
2653

Sliding Subarray Beauty

Compute the xth smallest negative number in each sliding subarray using array scanning and hash frequency tracking effic…

Medium
2730

Find the Longest Semi-Repetitive Substring

Find the length of the longest substring where at most one adjacent pair of digits repeats, using a sliding window appro…

Medium
2747

Count Zero Request Servers

Count Zero Request Servers finds the number of servers with zero requests during specific time intervals for a given set…

Medium
2760

Longest Even Odd Subarray With Threshold

Determine the length of the longest subarray where elements alternate even and odd while staying below a given threshold…

Easy
2762

Continuous Subarrays

Count all continuous subarrays efficiently using sliding window with running max-min state tracking for array consistenc…

Medium
2779

Maximum Beauty of an Array After Applying Operation

Find the maximum beauty of an array by adjusting elements within a range using binary search and sliding window techniqu…

Medium
2781

Length of the Longest Valid Substring

This problem asks for the longest valid substring of a word that doesn't contain any substrings from a forbidden list.

Hard
2799

Count Complete Subarrays in an Array

Count Complete Subarrays in an Array requires scanning the array while tracking elements to detect subarrays with all di…

Medium
2831

Find the Longest Equal Subarray

Find the maximum length of an equal subarray after removing up to k elements using array scanning and hash-based index t…

Medium
2841

Maximum Sum of Almost Unique Subarray

Find the maximum sum of subarrays that contain at least m distinct elements using array scanning and hash lookups effici…

Medium
2875

Minimum Size Subarray in Infinite Array

Find the shortest subarray in an infinite array that sums to a given target using array scanning and hash lookup.

Medium
2902

Count of Sub-Multisets With Bounded Sum

This problem asks you to count the number of sub-multisets within a given array that have a sum in a specified range.

Hard
2904

Shortest and Lexicographically Smallest Beautiful String

Find the shortest beautiful substring in a binary string and return the lexicographically smallest option efficiently us…

Medium
2932

Maximum Strong Pair XOR I

Find the maximum XOR of any strong pair in an integer array using array scanning and hash-based lookups efficiently.

Easy
2935

Maximum Strong Pair XOR II

Find the maximum XOR among strong pairs in an array using array scanning and hash-based lookups efficiently.

Hard
2953

Count Complete Substrings

Count Complete Substrings involves finding substrings where each character appears exactly k times with constraints on a…

Hard
2958

Length of Longest Subarray With at Most K Frequency

Find the maximum length subarray where each number appears at most k times using array scanning and hash lookups.

Medium
2962

Count Subarrays Where Max Element Appears at Least K Times

Find the number of subarrays where the maximum element appears at least k times using a sliding window approach.

Medium
2968

Apply Operations to Maximize Frequency Score

Maximize the frequency score by applying up to k operations on a sorted array using binary search over valid answer spac…

Hard
2981

Find Longest Special Substring That Occurs Thrice I

Find the longest special substring in a string that appears at least three times, or return -1 if no such substring exis…

Medium
2982

Find Longest Special Substring That Occurs Thrice II

Find the longest special substring that occurs at least three times in a given string using binary search and hash table…

Medium
3013

Divide an Array Into Subarrays With Minimum Cost II

This problem asks to divide an array into subarrays with a minimal cost and certain constraints on subarray positions.

Hard
3086

Minimum Moves to Pick K Ones

Find the minimum number of moves to pick exactly k ones from a binary array, considering a constraint on changes.

Hard
3090

Maximum Length Substring With Two Occurrences

Find the maximum length substring where some substring occurs at least twice using a sliding window and hash mapping str…

Easy
3095

Shortest Subarray With OR at Least K I

Find the shortest non-empty subarray in nums whose bitwise OR reaches at least k using sliding window efficiently.

Easy
3097

Shortest Subarray With OR at Least K II

Find the length of the shortest subarray where the bitwise OR of all its elements is at least a given value.

Medium
3134

Find the Median of the Uniqueness Array

Given a nums array, find the median of its uniqueness array by considering all subarrays and their distinct element coun…

Hard
3191

Minimum Operations to Make Binary Array Elements Equal to One I

Find the minimum number of operations to make all elements of a binary array equal to one using sliding window and state…

Medium
3206

Alternating Groups I

Count all alternating groups in a circular array by tracking tiles with distinct neighbors efficiently using sliding win…

Easy
3208

Alternating Groups II

Solve the problem of counting alternating groups in a circle of tiles using a sliding window approach.

Medium
3234

Count the Number of Substrings With Dominant Ones

Count the number of substrings in a binary string with dominant ones, using a sliding window approach with state updates…

Medium
3254

Find the Power of K-Size Subarrays I

Given an array, find the power of all subarrays of size k using a sliding window approach.

Medium
3255

Find the Power of K-Size Subarrays II

Compute the power of all k-size subarrays in an array using sliding window with running state updates efficiently.

Medium
3258

Count Substrings That Satisfy K-Constraint I

Count all substrings in a binary string that meet a given k-constraint using an efficient sliding window approach.

Easy
3261

Count Substrings That Satisfy K-Constraint II

Count Substrings That Satisfy K-Constraint II requires finding valid substrings in a binary string based on a k-constrai…

Hard
3297

Count Substrings That Can Be Rearranged to Contain a String I

Count the number of valid substrings in word1 that can be rearranged to contain word2 as a prefix.

Medium
3298

Count Substrings That Can Be Rearranged to Contain a String II

Count Substrings That Can Be Rearranged to Contain a String II involves identifying valid substrings with a sliding wind…

Hard
3305

Count of Substrings Containing Every Vowel and K Consonants I

Count all substrings containing every vowel and exactly k consonants using a sliding window and hash map state tracking.

Medium
3306

Count of Substrings Containing Every Vowel and K Consonants II

Count the number of substrings containing all vowels and exactly k consonants using a sliding window technique.

Medium
3318

Find X-Sum of All K-Long Subarrays I

Compute the x-sum of every subarray of length k efficiently using array scanning combined with hash lookup techniques.

Easy
3321

Find X-Sum of All K-Long Subarrays II

Calculate the x-sum for every k-length subarray using efficient array scanning and hash-based counting techniques.

Hard
3325

Count Substrings With K-Frequency Characters I

Calculate the total number of substrings where at least one character repeats k times using a sliding window efficiently…

Medium
3346

Maximum Frequency of an Element After Performing Operations I

Maximize the frequency of an element in an array after performing a series of operations to find the best possible resul…

Medium
3347

Maximum Frequency of an Element After Performing Operations II

Determine the maximum frequency of any element after performing limited operations using binary search and sliding windo…

Hard
3364

Minimum Positive Sum Subarray

Find the minimum sum of any subarray of size between l and r with a positive total using efficient sliding window logic.

Easy
3411

Maximum Subarray With Equal Products

This problem involves finding the longest subarray where the product equals the LCM multiplied by the GCD, leveraging a …

Easy
3413

Maximum Coins From K Consecutive Bags

Solve the problem of maximizing coins from selecting k consecutive bags, using binary search and sliding window techniqu…

Medium
3420

Count Non-Decreasing Subarrays After K Operations

This problem asks you to count non-decreasing subarrays in a given array after applying at most k operations.

Hard
3439

Reschedule Meetings for Maximum Free Time I

Maximize free time by rescheduling up to k non-overlapping meetings within a fixed event using sliding window updates.

Medium
3445

Maximum Difference Between Even and Odd Frequency II

Find the maximum difference between even and odd character frequencies in substrings using sliding window updates effici…

Hard
3505

Minimum Operations to Make Elements Within K Subarrays Equal

Compute the minimum operations to ensure at least k non-overlapping subarrays of size x have all equal elements efficien…

Hard
3578

Count Partitions With Max-Min Difference at Most K

Count the number of valid ways to partition an array into contiguous segments where max-min difference is at most k.

Medium
3589

Count Prime-Gap Balanced Subarrays

Count the number of prime-gap balanced subarrays in an integer array using sliding window techniques and running state u…

Medium

Related Patterns

Sliding Window LeetCode Problems: 133 Solutions