Posts

Showing posts from September 26, 2021

BACKWARD AND FORWARD STRING

Image
BACKWARD AND FORWARD STRING PROBLEM STATEMENT : Consider one string as input. You have to check whether the strings obtained from the input string with single backward and single forward shifts are the same or not. If they are the same, then print 1, otherwise, print 0. Hint: Backward shift: A single circular rotation of the string in which the first character becomes the last character and all the other characters are shifted one index to the left. For example, “abcde” becomes “bcdea” after one backward shift. Forward shift: A single circular rotation of the string in which the last character becomes the first character and all the other characters are shifted to the right. For example, “abcde” becomes “eabcd” after one forward shift. Constraints: String str should not allow space, special characters, and numbers. String str should only be in the English language. 1 <= len(str) <=1000 Example Input/Output 1: Input: ( ) sfdlmnop Output: 0 Explanation:  In the firs...