Generate all cyclic permutations of a number
Submissions: 603   Accuracy:

24.48%

  Difficulty: Basic   Marks: 1

Given a number N, generate all the possible cyclic permutations of the number.

Input :  123
Output : 123
         312
         231

Input :  5674
Output : 5674
         4567
         7456
         6745

Input:
The first line consists of an integer T i.e number of test cases. The first line and only line of each test case consists of an integer n.

Output:
Print all cyclic permutations with spaces in between.

Constraints: 
1<=T<=100
1<=n<=109

Example:
Input:

2
123
5674

Output:
123 312 231
5674 4567 7456 6745

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Saksham Ashtputre
Author: saksham0751


If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.


to report an issue on this page.