Illustration showing sliding window technique to find minimum window substring

Minimum Window Substring: Sliding Window Explained

Problem Overview Given strings s and t of length m and n respectively, return the minimum length substring of s such that every character in t is present in the substring. The substring can contain duplicate characters. LeetCode - Rotate Image Example: Input: s = "ADOBECODEBANC", t = "ABC" Output: "BANC" BANC is the minimum window containing all characters from t. ...

March 11, 2026 · 3 min · 504 words · Hitesh Patel
Illustration showing sliding window technique to find longest repeating character replacement

Longest Repeating Character Replacement: Sliding Window Explained

Problem Overview You’re given a string s (uppercase letters only) and an integer k. You can replace any character in the string up to k times. Return the length of the longest substring containing the same letter after performing those replacements. Brute Force Intuition The idea is straightforward — generate every possible substring, track the frequency of each character inside it, and check if the window is “valid.” Try all possible substrings with two nested loops Track character frequency within the current substring Track maxFreq — the count of the most frequent character If len - maxFreq <= k, the window is valid — update the result How this works, we have the maxFreq of that substring if we subract it from the len then we got len of other chars. The string is only valid if the no of conversion we have to make is less than k that is length - maxFreq; ...

March 10, 2026 · 3 min · 563 words · Hitesh Patel
Illustration showing sliding window technique to find longest substring without repeating characters

Longest Substring Without Repeating Characters: Sliding Window Explained

Problem Overview We are given a string s. Our goal is to find the longest substring that does not contain repeating characters. In other words, the length of the substring should equal the number of unique characters in it. If found → return the length, otherwise → return 0. There can be multiple valid substring of length LeetCode - Longest Substring Without Repeating Characters A substring is continous part of string. The string itself is a valid substring. ...

March 9, 2026 · 3 min · 637 words · Hitesh Patel