6
var hasAllCodes = function (s, k) {11
/* Max strings can be generated of k chars 0/1. */12
const max = Math.pow(2, k);16
* It will contain all unique values.18
const set = new Set();20
for (let i = 0; i < s.length - k + 1; i++) {21
/* Generate substring of size k from index i */22
const substr = s.substr(i, k);26
* if enough of unique strings are generated,27
* break the loop as there is no point of iterating28
* as we have found all necessary strings.30
if (set.size === max) {35
return set.size === max;