Longest Common Prefix After Rotation
You are given two strings 'A' and 'B'. While string 'A' is constant, you may apply any number of left shift operations to string 'B'.
Explanation:
Your task is to calculate the minimum number of left shift operations needed to achieve the longest common prefix between strings 'A' and 'B'.
Note:
A left shift operation is defined as a circular rotation of the string, where the first character is moved to the last position and all other characters are moved one index to the left.
Example:
Input:
A = "an"
B = "can"
Output Explanation:
After one left shift, B = "anc".
After two left shifts, B = "nca".
It takes two left shift operations for the longest common prefix.
Constraints:
- 1 <= T <= 100
- 1 <= |A|, |B| <= 5 * 104
- Characters in A and B are lowercase English letters only.
- Time limit: 1 second
Input:
T, followed by T test cases where each test case comprises two lines:
1. First line contains string A
2. Second line contains string B
Output:
The minimum number of left shift operations needed for each test case.
Note:
You should implement the function that computes the result; printing is handled separately.

AnswerBot
1y
The question asks to find the minimum number of left shift operations required to obtain the longest common prefix of two given strings.
Perform left shift operations on string B to find the longest co...read more
Help your peers!
Add answer anonymously...
ZeMoSo Technologies Associate Software Engineer interview questions & answers
An Associate Software Engineer was asked 8mo agoQ. Write a program to check whether the parentheses are properly balanced, meaning ...read more
An Associate Software Engineer was asked 8mo agoQ. Given a Map of fruits with their price as a key-value pair respectively, find th...read more
An Associate Software Engineer was asked 8mo agoQ. Given a list of integers, find the first non-repeating integer using the Stream ...read more
Popular interview questions of Associate Software Engineer
An Associate Software Engineer was asked 9mo agoQ1. Write a program to check whether the parentheses are properly balanced, meaning ...read more
An Associate Software Engineer was asked 9mo agoQ2. Given a Map of fruits with their price as a key-value pair respectively, find th...read more
An Associate Software Engineer was asked 9mo agoQ3. Given a list of integers, find the first non-repeating integer using the Stream ...read more
>
ZeMoSo Technologies Associate Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

