
Asked in Amazon
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...
Top Software Developer Interview Questions Asked at Amazon
Q. Could you describe the process for designing a data structure that allows for al...read more
Q. What is Java?
Q. Given two strings s and t, return true if they are equal when both are typed int...read more
Interview Questions Asked to Software Developer at Other Companies
Top Skill-Based Questions for Amazon Software Developer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 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

