Zepruv › Coding problems

Binary String With Substrings Representing 1 To N

Medium · Hash Table, String, Bit Manipulation, Sliding Window

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

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

Example 2

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

Constraints

Starter code (python)

class Solution(object):
    def queryString(self, s, n):
        """
        :type s: str
        :type n: int
        :rtype: bool
        """
        

Related problems

Previous: Best Sightseeing Pair · Next: Next Greater Node In Linked List · All problems

Zepruv is a technical interview practice platform. Read any problem for free; sign in to run your code, submit and keep your progress.