Last active
May 18, 2021 07:45
-
-
Save Fredpwol/3aa69dad0f58905431aeba1e3472600f to your computer and use it in GitHub Desktop.
Class Shuffle problem
This file contains 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
from collections import deque | |
def shuffleClass(arr, n): | |
if arr is None or len(arr) == 0: return [] | |
if n is None: return arr | |
arr = deque(arr) | |
if n >= 0: | |
for _ in range(n % len(arr)): | |
arr.appendleft(arr.pop()) | |
else: | |
for _ in range(abs(n) % len(arr)): | |
arr.append(arr.popleft()) | |
return list(arr) | |
print(shuffleClass([2,3], 3)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello @meekg33k, thanks for the feedback I really appreciate it, and I've updated my code to handle edge cases where I failed at. Thank you.