← Back to challenges

All Rotations of a String

PythonHardstringsloopsarrays

Instructions

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

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.