variable length sliding window

The Core Patterns of Variable-Length Sliding Window: Longest & Shortest Subarrays

Previously, we explored the fixed-length sliding window technique, which typically involves sliding a window of constant size by one element at a time. For a detailed explanation, refer to the article —— 📝How to Solve Fixed-Length Sliding Window Problems. Now, we encounter a new class of problems that also appear solvable with a sliding window approach, but with a crucial difference: the window size is variable. Find the Longest Subarray Given a string s, find the length of the longest substring without duplicate characters. ...

January 16, 2026 Â· 8 min Â· 1688 words Â· Robin Yang
math typesetting

Reverse Thinking With Fixed-Length Sliding Window

We previously learned about the fixed-length sliding window technique, which typically involves sliding one element at a time. For a detailed explanation, refer to the article —— 📝How to Solve Fixed-Length Sliding Window Problems. Now, we encounter a new problem that also appears solvable with a sliding window, but with a slight twist🔗. A Tricky Problem There are several cards arranged in a row, and each card has an associated number of points. The points are given in the integer array cardPoints. ...

January 1, 2026 Â· 6 min Â· 1227 words Â· Robin Yang
fixed length sliding window

How to Solve Fixed-Length Sliding Window Problems!

One Classic Problem Given an integer array nums consisting of n elements, and an integer k, find the maximum sum of any contiguous subarray of size k. Example: Input: arr = [2, 1, 5, 1, 3, 2], k = 3 Output: 9 Explanation: Subarray [5, 1, 3] has the maximum sum 9 Constraints: $n == nums.length$ $1 <= k <= n <= 10^5$ $-10^4 <= nums[i] <= 10^4$ Brute Force Approach The simplest solution checks each subarray independently: ...

December 24, 2025 Â· 7 min Â· 1314 words Â· Robin Yang