sliding window
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
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…
Substring with Concatenation of All Words
Find all starting indices of substrings in a string that are concatenations of a given list of words.
Minimum Window Substring
Find the smallest substring of s containing all characters from t using a sliding window with running state updates for …
Repeated DNA Sequences
Solve Repeated DNA Sequences by sliding a length-10 window and tracking seen patterns with a hash set or bitmask.
Minimum Size Subarray Sum
Find the minimal length of a subarray whose sum is greater than or equal to the target using efficient algorithms.
Contains Duplicate II
Check if any two equal numbers exist within k indices using array scanning and hash table lookup efficiently.
Contains Duplicate III
The problem involves finding a pair of indices in an array where the index and value differences are within given limits…
Sliding Window Maximum
Solve the "Sliding Window Maximum" problem using efficient techniques like the sliding window, deque, and priority queue…
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-…
Arithmetic Slices
Count the number of arithmetic subarrays in a given integer array using dynamic programming.
Longest Repeating Character Replacement
Find the length of the longest substring after at most k replacements using a sliding window and character count trackin…
Find All Anagrams in a String
Find all starting indices of p's anagrams in s using sliding window and hash table approach.
Sliding Window Median
Compute the median for each sliding window of size k in an array using efficient array scanning and hash lookup techniqu…
Permutation in String
Check if a string contains a permutation of another string using two-pointer scanning and hash table techniques.
Longest Harmonious Subsequence
Find the length of the longest harmonious subsequence in an integer array using array scanning and hash-based frequency …
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…
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…
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…
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.
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…
Maximum Length of Repeated Subarray
Find the maximum length of a subarray that appears in both given integer arrays using dynamic programming.
New 21 Game
Calculate the probability Alice reaches at most n points using state transition dynamic programming efficiently.
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.
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…
Binary Subarrays With Sum
Count all contiguous subarrays in a binary array whose elements sum exactly to a given goal using prefix sums efficientl…
Longest Turbulent Subarray
Find the length of the longest subarray where element comparisons alternate, using state transition dynamic programming …
Subarrays with K Different Integers
Find subarrays with exactly k distinct integers in an integer array using sliding window and hash lookup techniques.
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…
Max Consecutive Ones III
Find the longest consecutive ones in a binary array by optimally flipping at most k zeros using sliding window technique…
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…
Maximum Sum of Two Non-Overlapping Subarrays
Find the maximum sum of two non-overlapping subarrays by efficiently using state transition dynamic programming.
Moving Stones Until Consecutive II
Determine the minimum and maximum moves to make stones consecutive using sliding window and endpoint adjustments efficie…
Longest Duplicate Substring
Find the longest duplicated substring in a string using binary search, sliding window, and rolling hash techniques.
Grumpy Bookstore Owner
Maximize satisfied customers in a bookstore by strategically suppressing the owner's grumpy minutes using a sliding wind…
Swap For Longest Repeated Character Substring
Find the maximum length of a repeated character substring after swapping two characters using a sliding window approach …
Get Equal Substrings Within Budget
Optimize substring transformations using a binary search approach to maximize the change within a budget.
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.
Count Number of Nice Subarrays
The problem requires counting subarrays with exactly k odd numbers using an efficient array scanning approach.
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…
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.
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.
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.
Constrained Subsequence Sum
Solve the Constrained Subsequence Sum problem using dynamic programming, sliding window, and priority queues to maximize…
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…
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.
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 …
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.
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…
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…
Defuse the Bomb
Defuse the Bomb uses a sliding window to update a circular array based on a key, with efficient state updates.
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.
Maximum Erasure Value
Maximize the score by erasing a subarray with unique elements in an array of integers.
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.
Longest Nice Substring
Find the longest nice substring in a given string using the sliding window technique with running state updates.
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…
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.
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…
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…
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.
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.
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…
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…
K Radius Subarray Averages
Efficiently calculate the k-radius average for subarrays using sliding window technique.
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.
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.
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.
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 …
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…
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…
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…
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.
Maximum Number of Robots Within Budget
Determine the maximum number of consecutive robots you can operate without exceeding a given budget using efficient bina…
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.
Smallest Subarrays With Maximum Bitwise OR
Find the smallest subarrays with the maximum bitwise OR for each starting index in an array.
Count Subarrays With Fixed Bounds
Count all subarrays where the minimum and maximum match given bounds using efficient sliding window tracking techniques.
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.
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.
Maximize the Minimum Powered City
Determine the maximum minimum power a city can achieve by strategically adding power stations using binary search and pr…
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.
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…
Sliding Subarray Beauty
Compute the xth smallest negative number in each sliding subarray using array scanning and hash frequency tracking effic…
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…
Count Zero Request Servers
Count Zero Request Servers finds the number of servers with zero requests during specific time intervals for a given set…
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…
Continuous Subarrays
Count all continuous subarrays efficiently using sliding window with running max-min state tracking for array consistenc…
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…
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.
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…
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…
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…
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.
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.
Shortest and Lexicographically Smallest Beautiful String
Find the shortest beautiful substring in a binary string and return the lexicographically smallest option efficiently us…
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.
Maximum Strong Pair XOR II
Find the maximum XOR among strong pairs in an array using array scanning and hash-based lookups efficiently.
Count Complete Substrings
Count Complete Substrings involves finding substrings where each character appears exactly k times with constraints on a…
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.
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.
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…
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…
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…
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.
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.
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…
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.
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.
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…
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…
Alternating Groups I
Count all alternating groups in a circular array by tracking tiles with distinct neighbors efficiently using sliding win…
Alternating Groups II
Solve the problem of counting alternating groups in a circle of tiles using a sliding window approach.
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…
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.
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.
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.
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…
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.
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…
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.
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.
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.
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.
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…
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…
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…
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.
Maximum Subarray With Equal Products
This problem involves finding the longest subarray where the product equals the LCM multiplied by the GCD, leveraging a …
Maximum Coins From K Consecutive Bags
Solve the problem of maximizing coins from selecting k consecutive bags, using binary search and sliding window techniqu…
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.
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.
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…
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…
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.
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…