Lazy pasha string rotation: The lexicographically minimal string rotation or lexicographically least circular substring is the problem of finding the rotation of a string possessing the lowest lexicographical order of all such rotations.
Problem Statement:
Given a string s1 and a string s2, write a snippet to say whether s2 is a rotation of s1?
(eg given s1 = ABCD and s2 = CDAB, return true, given s1 = ABCD, and s2 = ACBD , return false).
Lazy Pasha String Rotation:
Copy the below java programs and execute it to see the real time program output.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | import java.util.*; import java.lang.*; import java.io.*; class ArrayLeftRoatateN { public static void fn(char a[],int n,Scanner ab,int q) { int index=-1; while(q-->0) { int type=ab.nextInt(); int desired=ab.nextInt()%n; if(type==1) { if(index==-1) index=(n-desired); else index=((n-desired)-(n-index)+n)%n; } else System.out.println(a[(index+desired)%n]); } } public static void main (String[] args) { Scanner ab=new Scanner(System.in); int t=ab.nextInt(); while(t-->0) { int n=ab.nextInt(); int q=ab.nextInt(); fn(ab.next().toCharArray(),n,ab,q); System.out.println(); } } } |
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.