String Rotation
String Rotation
Problem Description
After each rotation make a note of the first character of the rotated String, After all rotation are performed the accumulated
first character as noted previously will form another string, say FIRSTCHARSTRING.
Input
The first line contains the original string s. The second line contains a single integer q. The ith of the next q lines contains
character d[i] denoting direction and integer r[i] denoting the magnitude.
Constraints
1 <= Length of original string <= 30
1<= q <= 10
Sample Test Case 1:
String Rotation Question
Input:
carrace
3
L2
R2
L3
Output:
No
Explanation
After applying all the rotations the FIRSTCHARSTRING string will be "rcr" which is not anagram of any sub string of
original string "carrace".
Step 1: Understand the question
Sample Test Case 1:
Input:
carrace
3 C A R R A C E
L2
R2
L3
Output:
No
Step 1: Understand the question
Sample Test Case 1:
Input:
carrace
3 R R A C E C
L2
R2
L3
Output:
No
A
FirstCharArray R
Step 1: Understand the question
Sample Test Case 1:
Input:
carrace
3 R
C R
A A C E C A
L2
R2
L3
Output:
No
FirstCharArray R C
Step 1: Understand the question
Sample Test Case 1:
Input:
carrace
3 RC AA CR ER AC AC E
R
L2
R2
L3
Output:
No
FirstCharArray R C R
Step 2: Figure Out the Logic
Sample Test Case 1: Convert to char array C, A, R, R, A, C, E
Input:
CARRACE Rotate the strings – Left or Right According to the given input
3
L2 Store the first characters of the rotated string - firstcharstring
R2
L3 Check if the characters in the firstcharstring is an anagram of subset of
Output: the character array using substr method
No
Anagrams:
Step 3: Rotate the character array – left or right to the number of positions given according to the input
Step 5: check if the first character array is an anagram of the subset of the given string