Skip to content

Practice Binary String With Substrings Representing 1 To N

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

Medium#1016
LeetCode Problem

Binary String With Substrings Representing 1 To N

Problem Statement

Given a binary string s and a positive integer n, return true if the binary representation of all the integers in the range [1, n] are substrings of s, or false otherwise. A substring is a contiguous sequence of characters within a string.

Source: Binary String With Substrings Representing 1 To N on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "0110", n = 3
Output
true

# Example 2

Input
s = "0110", n = 4
Output
false

Constraints

1 <= s.length <= 1000
s[i] is either '0' or '1'.
1 <= n <= 10^9

Related LeetCode Problems

Practice more problems similar to Binary String With Substrings Representing 1 To N.

Review your practice with PhantomCodeAI

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