Created
October 13, 2021 08:54
-
-
Save anchitarnav/e92982731b3ff6158c64454fdab21cc9 to your computer and use it in GitHub Desktop.
Cyclic Sliding Window
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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