Skip to content

Practice Check If a String Contains All Binary Codes of Size K

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1461
LeetCode Problem

Check If a String Contains All Binary Codes of Size K

Problem Statement

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.

Source: Check If a String Contains All Binary Codes of Size K on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "00110110", k = 2
Output
true

# Example 2

Input
s = "0110", k = 1
Output
true

# Example 3

Input
s = "0110", k = 2
Output
false

Constraints

1 <= s.length <= 5 * 10^5
s[i] is either '0' or '1'.
1 <= k <= 20

Related LeetCode Problems

Practice more problems similar to Check If a String Contains All Binary Codes of Size K.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.