Zepruv › Coding problems

Permutation in String

Medium · Hash Table, Two Pointers, String, Sliding Window

Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise.
In other words, return true if one of s1's permutations is the substring of s2.

Example 1

Input: s1 = "ab", s2 = "eidbaooo"
Output: true

s2 contains one permutation of s1 ("ba").

Example 2

Input: s1 = "ab", s2 = "eidboaoo"
Output: false

Constraints

Starter code (python)

class Solution(object):
    def checkInclusion(self, s1, s2):
        """
        :type s1: str
        :type s2: str
        :rtype: bool
        """
        

Related problems

Previous: Subarray Sum Equals K · Next: Shortest Unsorted Continuous Subarray · All problems

Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.