Binary String With Substrings Representing 1 To N

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.

Example 1
Inputs = "0110", n = 3
Outputtrue
The binary representations of 1, 2, and 3 are "1", "10", and "11", all of which are substrings of s.
Example 2
Inputs = "0110", n = 4
Outputfalse
The binary representation of 4 is "100", which is not a substring of s.

Constraints

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

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate