As reported: SentinelOne Senior Software Engineer (Bangalore), 2025, screening round: a string problem solved with a sliding window, followed by questions on general software-engineering principles.
You are given a string s and a pattern p. Return true if the pattern exists in s but not in the same relative order as in p: some substring of s with length |p| uses exactly the letters of p (a rearrangement of p) and is not p itself. Otherwise return false.
Example 1
s = "abcde", p = "abc"
Output: false
The only window made of a, b, c is "abc", which is the pattern in its original order.
Example 2
s = "bacde", p = "abc"
Output: true
The window "bac" holds the pattern's letters in a different order.
Example 3
s = "xyzcab", p = "abc"
Output: true
Constraints: 1 <= s.length, p.length <= 10^5; both consist of lowercase English letters.
Code runner format: two JSON strings, one per line: s, p. Implement hasShuffledPattern(s, p) returning a boolean.
Clarifications
- Only contiguous substrings count, and each must have exactly the letter counts of
p. - If
scontainspexactly in one place and a rearrangement elsewhere, the answer istrue— one rearranged occurrence is enough. - If
pis longer thans, returnfalse. When every rearrangement ofpequalsp(e.g.p = "aaa"), the answer is alwaysfalse.