#1016

Binary String With Substrings Representing 1 To N

specialist · 805 · lc medium +31 · verified · 58.4% accepted · 386 likes · top 55%

Description

Given a binary string s and a positive integer n, return true if the binary representations of every integer from 1 to n appear as substrings of s, or false otherwise.

A substring is a contiguous sequence of characters within a string.

Example 1:

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

Example 2:

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

Code

1
2
3