
Asked in Grey Orange
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.

AnswerBot
4mo
Implement a function to find all starting indices of anagram substrings of a given string in another string.
Create a frequency map of characters in the 'PTR' string.
Use a sliding window approach to ch...read more
Help your peers!
Add answer anonymously...
Top Senior Software Engineer Interview Questions Asked at Grey Orange
Q. Projects you have worked on. 1. vector implementation in C++
Q. What are some common testing questions related to Linux and operating systems?
Q. Prime Numbers within a Range Given an integer N, determine and print all the pri...read more
Interview Questions Asked to Senior Software Engineer at Other Companies
Top Skill-Based Questions for Grey Orange Senior Software Engineer
Web Development Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
Algorithms Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
SQL 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

