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.

&nbsp;
Example 1:

Input: s1 = "ab", s2 = "eidbaooo"
Output: true
Explanation: s2 contains one permutation of s1 ("ba").


Example 2:

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


&nbsp;
Constraints:


	1 &lt;= s1.length, s2.length &lt;= 104
	s1 and s2 consist of lowercase English letters.


class Solution:
    def checkInclusion(self, s1: str, s2: str) -> bool:
        if len(s1) > len(s2):
            return False
        s1_map = {}
        s2_map = {}
        for i in range(ord('a') , ord('z') + 1):
            s1_map[chr(i)] = 0
            s2_map[chr(i)] = 0
        
        for i in s1:
            s1_map[i] += 1
            
        l = 0
        r = 0
        
        while r < len(s2):
            print(s2_map , l ,r)
            if r == 0:
                while r < len(s1):
                    s2_map[s2[r]] += 1
                    r += 1
                if s2_map == s1_map:
                    return True

            else:
                s2_map[s2[l]] -= 1
                s2_map[s2[r]] += 1
                
                if s2_map == s1_map:
                    return True
                else:
                    l += 1
                    r += 1
            
        return False      
class Solution {
    public boolean checkInclusion(String s1, String s2) {
        if(s1.length() > s2.length()) {
            return false;
        }
        
        int[]s1Count = new int[26];
        int[]s2Count = new int[26];
        
        for(int i = 0; i < s1.length(); i++) {
            char c = s1.charAt(i);
            char s = s2.charAt(i);
            s1Count[c - 'a'] += 1;
            s2Count[s - 'a'] += 1;
        }
        
        int matches = 0;
        
        for(int i = 0; i < 26;i++) {
            if(s1Count[i] == s2Count[i]) {
                matches+=1;
            }
        }
        
        int left = 0;
        for(int right = s1.length(); right < s2.length();right++) {
            if(matches == 26) {
                return true;
            }
            
            int index = s2.charAt(right) - 'a';
            s2Count[index] += 1;
            if(s1Count[index] == s2Count[index]) {
                matches += 1;
            }
            else if(s1Count[index] + 1 == s2Count[index]) {
                matches -= 1;
            }
            
            index = s2.charAt(left) - 'a';
            s2Count[index] -= 1;
            if(s1Count[index] == s2Count[index]) {
                matches += 1;
            }
            else if(s1Count[index] - 1 == s2Count[index]) {
                matches -= 1;
            }
            left += 1;
        }
        
        if(matches == 26) {
            return true;
        }
        
        return false;
    }
}
class Solution {
public:
	bool checkInclusion(string s1, string s2) {
		sort(s1.begin(),s1.end());
		int n = s1.size(), m = s2.size();
		for(int i=0;i<=m-n;i++)
		{
			string s = s2.substr(i,n);
			sort(s.begin(),s.end());
			if(s1 == s)     return true;
		}
		return false;
	}
};
const getCharIdx = (c) => c.charCodeAt(0) - 'a'.charCodeAt(0);
const isEqual = (a, b) => a.every((v, i) => v == b[i]);

var checkInclusion = function(s1, s2) {
    const occS1 = new Array(26).fill(0);
    const occS2 = new Array(26).fill(0);

    const s1Len = s1.length, s2Len = s2.length;

    if(s1Len > s2Len) return false;

    let l = 0, r = 0;
    for(; r < s1Len ; r++) {
        occS1[getCharIdx(s1[r])]++;
        occS2[getCharIdx(s2[r])]++;
    }

    if(isEqual(occS1, occS2)) {
        return true;
    }

    for(; r < s2Len; r++) {
        occS2[getCharIdx(s2[r])]++;
        occS2[getCharIdx(s2[l++])]--;

        if(isEqual(occS1, occS2)) return true;
    }

    return false;
};
Permutation in String