Skip to contentKEEP THE CRAFTTHE SANCTUARY

Permutation in String

Check whether some window of s2 holds exactly the same letters, in the same amounts, as s1.

The problem

Implement Solution.checkInclusion(s1, s2). Return True if some substring of s2 is a rearrangement of s1, meaning it uses exactly the same letters the same number of times, and False otherwise. For example, s1 = "ab" and s2 = "eidbaooo" returns True because s2 contains "ba". Both strings contain only lowercase English letters, and 1 <= len(s1), len(s2) <= 10000.

Starter code

class Solution:
    def checkInclusion(self, s1, s2):
        pass

Public examples

  1. s1 = "ab", s2 = "eidbaooo"givesTrue
  2. s1 = "abc", s2 = "bca"givesTrue
  3. s1 = "abcd", s2 = "abc"givesFalse

Solving it in the practice book needs an active paid plan.

Open it in the practice book
One thought at a time.