menu_book Course Curriculum (Data Structures & Algorithms) expand_more
Complexity & Foundations
Arrays & Strings
Linked Lists
Stacks & Queues
Hashing
Trees & Heaps
Graphs
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