Back to DSA

Permutation in String

medium
Acceptance: 50%
StringsSliding Window

Two 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:true
Explanation: The substring 'xy' starting at index 1 is itself a permutation of 'xy'.
Example 2:
Input:pattern = "ab", text = "acbddd"
Output:false
Explanation: No contiguous substring of length 2 in the text is a rearrangement of 'ab'.

Hints

00:00
1234567