Sliding Window
Sliding Window
Thirty-five questions on the sliding window technique, for solving subarray and substring problems in linear time.
Alternating Groups I
easyThere is a circle of red and blue tiles.
Contains Duplicate II
easyGiven an integer array nums and an integer k, return true if there are two distinct indices i and j in the array such that nums[i] == nums[j] and abs(i - j) <= k.
Count Substrings That Satisfy K-Constraint I
easyYou are given a binary string s and an integer k.
Defuse the Bomb
easyYou have a bomb to defuse, and your time is running out!
Find the K-Beauty of a Number
easyThe k-beauty of an integer num is defined as the number of substrings of num when it is read as a string that meet the following conditions: Given integers num and k, return the...
Find X-Sum of All K-Long Subarrays I
easyYou are given an array nums of n integers and two integers k and x.
Longest Even Odd Subarray With Threshold
easyYou are given a 0-indexed integer array nums and an integer threshold.
Longest Harmonious Subsequence
easyWe define a harmonious array as an array where the difference between its maximum value and its minimum value is exactly 1.
Longest Nice Substring
easyA string s is nice if, for every letter of the alphabet that s contains, it appears both in uppercase and lowercase.
Maximum Average Subarray I
easyYou are given an integer array nums consisting of n elements, and an integer k.
Maximum Strong Pair XOR I
easyYou are given a 0-indexed integer array nums.
Maximum Subarray With Equal Products
easyYou are given an array of positive integers nums.
Minimum Difference Between Highest and Lowest of K Scores
easyYou are given a 0-indexed integer array nums, where nums[i] represents the score of the ith student.
Minimum Positive Sum Subarray
easyYou are given an integer array nums and two integers l and r.
Minimum Recolors to Get K Consecutive Black Blocks
easyYou are given a 0-indexed string blocks of length n, where blocks[i] is either 'W' or 'B', representing the color of the ith block.
Shortest Subarray With OR at Least K I
easyYou are given an array nums of non-negative integers and an integer k.
Substrings of Size Three with Distinct Characters
easyA string is good if there are no repeated characters.
Alternating Groups II
mediumThere is a circle of red and blue tiles.
Arithmetic Slices
mediumAn integer array is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.
Binary String With Substrings Representing 1 To N
mediumGiven a binary string s and a positive integer n, return true if the binary representation of all the integers in the range [1, n] are substrings of s, or false otherwise.
Binary Subarrays With Sum
mediumGiven a binary array nums and an integer goal, return the number of non-empty subarrays with a sum goal.
Continuous Subarrays
mediumYou are given a 0-indexed integer array nums.
Count Complete Subarrays in an Array
mediumYou are given an array nums consisting of positive integers.
Count Number of Nice Subarrays
mediumGiven an array of integers nums and an integer k.
Count of Substrings Containing Every Vowel and K Consonants I
mediumYou are given a string word and a non-negative integer k.
Count of Substrings Containing Every Vowel and K Consonants II
mediumYou are given a string word and a non-negative integer k.
Count Partitions With Max-Min Difference at Most K
mediumYou are given an integer array nums and an integer k.
Count Prime-Gap Balanced Subarrays
mediumYou are given an integer array nums and an integer k.
Count Subarrays Where Max Element Appears at Least K Times
mediumYou are given an integer array nums and a positive integer k.
Count Substrings That Can Be Rearranged to Contain a String I
mediumYou are given two strings word1 and word2.
Count Substrings With K-Frequency Characters I
mediumGiven a string s and an integer k, return the total number of substrings of s where at least one character appears at least k times.
Count the Number of Good Subarrays
mediumGiven an integer array nums and an integer k, return the number of good subarrays of nums.
Count the Number of Substrings With Dominant Ones
mediumYou are given a binary string s.
Count Zero Request Servers
mediumYou are given an integer n denoting the total number of servers and a 2D 0-indexed integer array logs, where logs[i] = [server_id, time] denotes that the server with id server_id...
Find All Anagrams in a String
mediumGiven two strings s and p, return an array of all the start indices of p's anagrams in s.