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
4mo
Calculate the minimum number of left shift operations needed to achieve the longest common prefix between two strings.
Apply left shift operations to string B to find the longest common prefix with str...read more
Sonu kumar
9mo
A= abcd
B=cdab
B ko 2 bar left shift karne ke bad B= abcd
Help your peers!
Add answer anonymously...
Bharti Airtel Software Developer interview questions & answers
A Software Developer was asked 2d agoQ. What does a software developer do?
A Software Developer was asked 2d agoQ. What is this engineering
A Software Developer was asked Q. Write an SQL query to find the second highest salary.
Popular interview questions of Software Developer
A Software Developer was asked 2d agoQ1. What is this engineering
A Software Developer was asked Q2. Write an SQL query to find the second highest salary.
A Software Developer was asked Q3. Stack using Two Queues Problem Statement Develop a Stack Data Structure to store...read more
>
Bharti Airtel Software Developer 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

