Anagram Substring Search

Given two strings 'STR' and 'PTR', identify all starting indices of 'PTR' anagram substrings in 'STR'. Two strings are anagrams if one can be rearranged to form the other.

Input:

First line: Integer T (number of test cases).
Each test case consists of:
Line 1: Two integers N and M.
Line 2: String 'STR' with N characters.
Line 3: String 'PTR' with M characters.

Output:

For each test case, output the list of starting indices of 'PTR' anagram substrings in 'STR', each consecutive list on a new line.

Example:

Input:
1
9 4
BACDGABCD
ABCD
Output:
0 5
Explanation:

The substrings at indices 0-3 ('BACD') and 5-8 ('ABCD') in 'STR' are anagrams of 'PTR'.

Constraints:

  • 1 ≤ T ≤ 50
  • 1 ≤ N, M ≤ 10⁴
  • Strings consist of only uppercase English letters.

Note:

No need to print anything in the function; return the answer.
Be the first one to answer
Add answer anonymously...
Grey Orange Senior Software Engineer 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