Skip to content

Instantly share code, notes, and snippets.

@anchitarnav
Created October 13, 2021 08:54
Show Gist options
  • Save anchitarnav/e92982731b3ff6158c64454fdab21cc9 to your computer and use it in GitHub Desktop.
Save anchitarnav/e92982731b3ff6158c64454fdab21cc9 to your computer and use it in GitHub Desktop.
Cyclic Sliding Window
# Sliding Windows
x = [1,2,3,4,5,6,7,8]
# Maintain a window of size n (e.g. 3) such that the window can slide to the other end
# 3,2,1 --> 2,1,8 --> 1,8,7 --> 8,7,6
win_size = 3
start = win_size
end = len(x)
for _ in range(win_size + 1):
if start>=0:
print(x[:start], end='')
if end < len(x):
print(x[end:], end='')
print('\n')
start -=1
end -=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment