All Rotations of a String

Published by Helen Yu in

Create a left rotation and a right rotation function that returns all the left rotations and right rotations of a string.

Examples

left_rotations("abc") ➞ ["abc", "bca", "cab"]

right_rotations("abc") ➞ ["abc", "cab", "bca"]

left_rotations("abcdef") 
➞ ["abcdef", "bcdefa", "cdefab", "defabc", "efabcd", "fabcde"]

right_rotations("abcdef") 
➞ ["abcdef", "fabcde", "efabcd", "defabc", "cdefab", "bcdefa"]

Notes

N/A

Watch a quick demo on how Edabit works.