Back to DSA
Permutation in String
mediumTwo strings are provided. Determine whether the second string contains any substring that is a rearrangement (permutation) of the first string. Return true if such a substring exists, false otherwise.
Examples
Example 1:
Input:
pattern = "xy", text = "axyzbxyx"Output:
trueExplanation: The substring 'xy' starting at index 1 is itself a permutation of 'xy'.
Example 2:
Input:
pattern = "ab", text = "acbddd"Output:
falseExplanation: No contiguous substring of length 2 in the text is a rearrangement of 'ab'.
Hints
1234567