As reported: Microsoft SDE (15 Feb 2025 drive), round 1 (DSA), question 2: given a string and a pattern, find the first index where the pattern or any anagram of it occurs.
Given strings s and p, return the start indices of every substring of s that is an anagram of p (the same letters with the same counts, in any order), in increasing order. The first index asked for in the round is the first element; an empty result means no occurrence.
This is LeetCode 438 — Find All Anagrams in a String.
Example 1
s = "cbaebabacd", p = "abc" -> [0,6]
"cba" starts at 0 and "bac" at 6; the first occurrence is at index 0.
Example 2
s = "abab", p = "ab" -> [0,1,2]
Constraints: 1 ≤ s.length, p.length ≤ 3 · 10^4; lowercase English letters.
Code runner format: one JSON value per line: s, p (LeetCode's test-case format). Implement findAnagrams(s, p); the harness prints the result.