Permutation in String

MediumSliding Window

You are given two strings s1 and s2. Return true if s2 contains a substring (a contiguous piece) that is a rearrangement of s1, and false otherwise.

A rearrangement uses exactly the same letters as s1, each the same number of times, in any order. s1 itself counts as one of its rearrangements.

Constraints

  • 1 <= s1.length, s2.length <= 10^4
  • s1 and s2 contain lowercase English letters only.

Examples

Example 1

Input: s1 = "abc", s2 = "xxbcay"
Output: true

"bca" (indices 2 to 4) uses exactly the letters of "abc".

Example 2

Input: s1 = "abc", s2 = "acxb"
Output: false

Every 3-letter stretch of "acxb" contains an x, so none rearranges into "abc".

Example 3

Input: s1 = "abcd", s2 = "abc"
Output: false

s1 is longer than s2, so it can't fit.

JavaScript you'll use: Arrays: create, read, update Strings and characters

/**
 * @param {string} s1
 * @param {string} s2
 * @return {boolean}
 */
function checkInclusion(s1, s2) {
  
}

Ctrl/⌘ + ' runs the examples, Ctrl/⌘ + Enter submits. Use console.log freely: output shows under Console. In the editor, press Esc then Tab to move focus out.