Given string S consisting of only lowercase English letters. The task is to find if there exists any string which has left shift and right shift both equal to string S. If there exists any string then print Yes, otherwise print No.
Input: S = “abcd”
There is no string which have left shift and right shift both equal to string “abcd”.
The left shift and right shift both of string “apap” equals to string “papa”.
- The main target is to check the left shift and right shift both of any string equals to given string or not.
- For that we just have to check every character of given string is equal to its next to next character or not (i.e. character at (i)th position must be equal to character at (i+2)th position ).
- If it’s true for every position on the given stringm then we can say there exist any string whose left shift and right shift equal to given string otherwise not.
Below is the implementation of the above approach:
Time Complexity: O(N) where N is the size of the string S.
Auxiliary Space Complexity: O(1)
- Left Shift and Right Shift Operators in C/C++
- Bitwise right shift operators in Java
- Number of odd and even results for every value of x in range [min, max] after performing N steps
- Maximize count of 0s in left and 1s in right substring by splitting given Binary string
- Check if string is right to left diagonal or not
- Left Rotation and Right Rotation of a String
- Minimize characters to be changed to make the left and right rotation of a string same
- String formed with middle character of every right substring followed by left sequentially
- Minimum flips to make all 1s in left and 0s in right | Set 1 (Using Bitmask)
- Queries for number of elements on right and left
- Count smaller elements on right side and greater elements on left side using Binary Index Tree
- Find Partition Line such that sum of values on left and right is equal
- Rotate all odd numbers right and all even numbers left in an Array of 1 to N
- Longest subsequence of a number having same left and right rotation
- Check if a decreasing Array can be sorted using Triple cyclic shift
- Left-Right traversal of all the levels of Binary tree
- Minimize flips required to make all shortest paths from top-left to bottom-right of a binary matrix equal to S
- Shift all prefixes by given lengths
- Check if any square (with one colored cell) can be divided into two equal parts
- Maximum count of elements divisible on the left for any element
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.