Master programming syntax, solve interactive challenges & run live code in Syntaxis Explore Arena →
menu_book Course Curriculum (Data Structures & Algorithms) expand_more
Complexity & Foundations
Arrays & Strings
Linked Lists
Stacks & Queues
Hashing
Trees & Heaps
Graphs
Sorting Searching & DP
Data Structures & Algorithms / Arrays & Strings

Sliding window

Learn Sliding window in Data Structures & Algorithms with a focused explanation, a topic-specific example, edge guidance, and a mastery check.

12 min read • Beginner
data-structures-algorithms-015.py
python
a=[2,1,5,1,3,2]; k=3
window=sum(a[:k]); best=window
for i in range(k,len(a)):
    window+=a[i]-a[i-k]; best=max(best,window)
print(best)
What to watch
Content source & attribution
Original Syntaxis Content · Original Syntaxis Content