We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Functional Programming
  3. Ad Hoc
  4. Rotate String

Rotate String

Problem
Submissions
Leaderboard
Discussions
Editorial

Scturtle likes strings very much. He is getting bored today, because he has already completed this week's task and doesn't have anything else to do. So he starts left-rotating a string. If the length of the string is , then he will rotate it times and note down the result of each rotation on a paper.

For a string rotations are possible. Let's represent these rotations by . Rotating it once will result in string , rotating it again will result in string and so on. Formally, rotation will be equal to . Note that .

Your task is to display all rotations of string .

For example, if = abc then it has 3 rotations. They are = bca, = cab and = abc.

Input Format
The first line contains an integer, , which represents the number of test cases to follow. Then follows lines, which represent a test case each.
Each test case contains a string, , which consists of lower case latin characters only.

Output Format
For each test case, print all the rotations, , separated by a space.

Constraints


will consist of lower case latin character, only.

Sample Input

5
abc
abcde
abab
aaa
z

Sample Output

bca cab abc
bcdea cdeab deabc eabcd abcde
baba abab baba abab
aaa aaa aaa
z

Explanation
Test case #1: This case is mentioned in the problem statment.
Test case #2: Rotations of abcde are: bcdea -> cdeab -> deabc -> eabcd -> abcde.
Test case #3: Rotations of abab are: baba -> abab -> baba -> abab.
Test case #4: All three rotations will result into same string.
Test case #5: Only one rotation is possible, and that will result into original string.


Tested by: Lalit Kundu

Author

abhiranjan

Difficulty

Easy

Max Score

20

Submitted By

4402

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy