Skip to content

Instantly share code, notes, and snippets.

@diaasami
Last active November 13, 2023 15:58
Show Gist options
  • Save diaasami/4a434d7b204582cf8635dea3e378de26 to your computer and use it in GitHub Desktop.
Save diaasami/4a434d7b204582cf8635dea3e378de26 to your computer and use it in GitHub Desktop.
LeetCode - 1461. Check If a String Contains All Binary Codes of Size K
class Solution:
def hasAllCodes(self, s: str, k: int) -> bool:
num_perms = math.pow(2, k)
substrings_of_len_k = len(s) - k + 1
if substrings_of_len_k < num_perms:
return False
perms = set()
for i in range(k, len(s)+1):
perms.add(s[i-k:i])
return len(perms) == num_perms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment