for english version: https://dev.to/yunshu67/intro-to-sliding-window-o56

滑动窗口笔记 Sliding Window Notes

Table of Contents




Intro

This technique shows how a nested for loop in some problems can be converted to a single for loop to reduce the time complexity.


Tipps:

 

Examples

5624. Minimum Adjacent Swaps for K Consecutive Ones

You are given an integer array nums, and an integer k. nums comprises of only 0's and 1's. In one move, you can choose two adjacent indices and swap their values.

Return the minimum number of moves required so that nums has k consecutive 1's.