Skip to content

Instantly share code, notes, and snippets.

@Fredpwol
Last active May 18, 2021 07:45
Show Gist options
  • Save Fredpwol/3aa69dad0f58905431aeba1e3472600f to your computer and use it in GitHub Desktop.
Save Fredpwol/3aa69dad0f58905431aeba1e3472600f to your computer and use it in GitHub Desktop.
Class Shuffle problem
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))
@Fredpwol
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment