Rotational Equivalence of Strings Problem Statement
Given two strings 'P' and 'Q' of equal length, determine if string 'P' can be transformed into string 'Q' by cyclically rotating it to the right any number of times (possibly zero).
Explanation:
A cyclic right rotation involves moving the rightmost character of string A to the leftmost position. For instance, if A = "pqrst", then it will become "tpqrs" after one right rotation.
Example:
Input:
P = "abfyg", Q = "gabfy"
Output:
1
Explanation:
If we cyclically rotate String P to the right once, it becomes "gabfy", which matches String Q. Thus, it is possible to convert String P to String Q.
Input:
The first line of the input contains an integer 'T', denoting the number of test cases. The first line of each test case contains the String 'P'. The second line of each test case contains the String 'Q'.
Output:
For each test case, print 1 if String 'P' can be cyclically rotated to form String 'Q', otherwise print 0. Print the result for each test case on a new line.
Constraints:
- 1 ≤ T ≤ 10
- 1 ≤ |P|, |Q| ≤ 105
- |P| = |Q|
- Strings 'P' and 'Q' consist only of lowercase English letters.
- Time Limit: 1 sec
Note:
You do not need to print anything; it is already handled. Just implement the given function.
Follow Up:
Can you solve this in O(N) time?
Be the first one to answer
Add answer anonymously...
Top Microsoft Corporation Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Microsoft Corporation Software Developer
>
Microsoft Corporation Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app