Given a binary string s and an integer k, return true if every binary code of length k is a substring of s. Otherwise, return false.

&nbsp;
Example 1:

Input: s = "00110110", k = 2
Output: true
Explanation: The binary codes of length 2 are "00", "01", "10" and "11". They can be all found as substrings at indices 0, 1, 3 and 2 respectively.


Example 2:

Input: s = "0110", k = 1
Output: true
Explanation: The binary codes of length 1 are "0" and "1", it is clear that both exist as a substring. 


Example 3:

Input: s = "0110", k = 2
Output: false
Explanation: The binary code "00" is of length 2 and does not exist in the array.


&nbsp;
Constraints:


	1 &lt;= s.length &lt;= 5 * 105
	s[i] is either '0' or '1'.
	1 &lt;= k &lt;= 20


class Solution:
    def hasAllCodes(self, s: str, k: int) -> bool:
        
        Z = set()

        for i in range(len(s)-k+1):
            Z.add(s[i:i+k])
            
        if len(Z) == 2**k:
            return True

        return False
class Solution {
    public boolean hasAllCodes(String s, int k) {
        HashSet<String> hs=new HashSet();
        for(int i=0;i<=s.length()-k;i++){
            hs.add(s.substring(i,i+k));
        }
        if(hs.size() == Math.pow(2,k))return true;
        return false;
    }
}
class Solution {
public:
    bool hasAllCodes(string s, int k) {
        if (s.size() < k)
        {
            return false;
        }
        unordered_set<string> binary_codes;
        for (int i = 0; i < s.size()-k+1; i++)
        {
            string str = s.substr(i, k);
            binary_codes.insert(str);
            if (binary_codes.size() == (int)pow(2, k))
            {
                return true;
            }
        }
        return false;
    }
};
/**
 * @param {string} s
 * @param {number} k
 * @return {boolean}
 */
var hasAllCodes = function(s, k) {
    
    if (k > s.length) {
        return false;
    }
    
    /* Max strings can be generated of k chars 0/1. */
    const max = Math.pow(2, k);
    
    /*
    * Create a set. 
    * It will contain all unique values.
    */ 
    const set = new Set();
    
    for(let i = 0; i < s.length - k + 1; i++) {
        /* Generate substring of size k from index i */
        const substr = s.substr(i, k);        
        set.add(substr);
        
        /* 
        * if enough of unique strings are generated, 
        * break the loop as there is no point of iterating
        * as we have found all necessary strings.
        */
        if (set.size === max) {
            return true;
        }
    }
          
    return set.size === max;
};
Check If a String Contains All Binary Codes of Size K