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.
Be the first one to answer
Add answer anonymously...
Amazon Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter