Permutation in String Problem Statement
Determine if the string str2
contains a permutation of the string str1
as one of its substrings.
Input:
The first line contains an integer 'T', representing the number of test cases. For each test case, the first line contains two space-separated integers, 'N' and 'M', indicating the lengths of 'str1' and 'str2'. The second line contains the strings 'str1' and 'str2'.
Output:
For each test case, print "Yes" if any permutation of "str1" is a substring of "str2". Otherwise, print "No".
Example:
Input:
str1 = "ab", str2 = "aoba"
Output:
Yes
Explanation:
The permutations of "ab" are ["ab", "ba"]. The substring "ba" is found in "aoba".
Constraints:
1 <= T <= 100
1 <= N <= 5000
1 <= M <= 5000
- Time limit: 1 second
Note:
No printing of the result is needed; implement the function to return the answer.

AnswerBot
4mo
Check if a permutation of one string is a substring of another string.
Create a frequency map of characters in str1.
Iterate through str2 with a window of size N and check if the frequency map matches.
R...read more
Help your peers!
Add answer anonymously...
Amazon Software Developer interview questions & answers
A Software Developer was asked 1mo agoQ. Could you describe the process for designing a data structure that allows for al...read more
A Software Developer was asked 1mo agoQ. What is HTML?
A Software Developer was asked 1mo agoQ. What is MySQL?
Popular interview questions of Software Developer
A Software Developer was asked 1mo agoQ1. Could you describe the process for designing a data structure that allows for al...read more
A Software Developer was asked 1mo agoQ2. What is MySQL?
A Software Developer was asked 1mo agoQ3. What is Java?
Top HR questions asked in Amazon Software Developer
A Software Developer was asked 1mo agoQ1. Tell me about a time you had to get to the root cause of a problem
A Software Developer was asked 5mo agoQ2. What are the short-term and long-term goals for the team or organization?
A Software Developer was asked 5mo agoQ3. Why do you want to work at Amazon?
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

