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++
- String slicing in Python to check if a string can become empty by recursive deletion
- Check if a string can be converted to another string by replacing vowels and consonants
- Check if a string can be formed from another string by at most X circular clockwise shifts
- Queries to check if string B exists as substring in string A
- Check if any permutation of string is a K times repeated string
- Check if a string can become empty by recursively deleting a given sub-string
- Check if a string can be obtained by rotating another string d places
- Check if a string can be obtained by rotating another string 2 places
- Check whether second string can be formed from characters of first string
- Check if a string can be repeated to make another string
- Check if a given string is a Reverse Bitonic String or not
- Check if a string contains a palindromic sub-string of even length
- Check if the given string is shuffled substring of another string
- Check if a string can be formed from another string using given constraints
- Check if a string is a scrambled form of another string
- String formed with middle character of every right substring followed by left sequentially
- Maximize count of 0s in left and 1s in right substring by splitting given Binary string
- Check if a given string is sum-string
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
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.