This week's learning is Sliding Window Problem. The characteristics of this problem topic are:
- 🔢Sequentialinput typically consists of strings or arrays, such ase []int or string.
The problem is asking about continuous segments, not scattered elements. - ⏱️Fixed or variable-length window; You're asked to identify or improve something over a range that moves:
- "Find all substrings of length 10…"
- Variable: "Find the smallest subarray whose sum is greater than or equal to the target."
- 🔄If you used a brute-force method, you wouldneed to check the overlapping parts again during repeated calculations over ranges; however, the sliding window technique avoids this by updating values instead of recalculating them.
- 📊 Aggregate property—this is how you keep track of things like:
- Inside the window, you can see the sum, count, frequency, or max/min.
- For example, "max sum of k elements" or "count of distinct chars ≤ k."
- 🚫 The window only moves forward, so you don't have to go back.
- ⚖️ Often means keeping things in balance or under control, like:
- "At most k different characters."
- "Sum less than target."
