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)
- 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
- Number of odd and even results for every value of x in range [min, max] after performing N steps
- 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
- Queries for number of elements on right and left
- 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
- Check if any square (with one colored cell) can be divided into two equal parts
- Shift all prefixes by given lengths
- Maximum count of elements divisible on the left for any element
- String matching with * (that matches with any) in any of the two strings
- Check if there exists a permutation of given string which doesn't contain any monotonous substring
- Check if characters of a given string can be used to form any N equal strings
- Find minimum shift for longest common prefix
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.