<p>Given a binary string <code>s</code> and a positive integer <code>n</code>, return <code>true</code><em> if the binary representation of all the integers in the range </em><code>[1, n]</code><em> are <strong>substrings</strong> of </em><code>s</code><em>, or </em><code>false</code><em> otherwise</em>.</p>

<p>A <strong>substring</strong> is a contiguous sequence of characters within a string.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> s = "0110", n = 3
<strong>Output:</strong> true
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> s = "0110", n = 4
<strong>Output:</strong> false
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= s.length &lt;= 1000</code></li>
	<li><code>s[i]</code> is either <code>&#39;0&#39;</code> or <code>&#39;1&#39;</code>.</li>
	<li><code>1 &lt;= n &lt;= 10<sup>9</sup></code></li>
</ul>

class Solution:
    def queryString(self, s: str, n: int) -> bool:
        # the length of s is at most 1000, so it can represent numbers up to 2^1000-1
        # binary string, so its elements are either '0' or '1'
        # n is going to be up to 10^9
        if n == 1 and '1' in s:
            return True
        # [1, n]
        # brute force:
        # iterate through the range [1, n]
            # construct the binary substring representing that number
            # check if that substring is in s.
        # Since s is relatively small, what if we find every substring first, and add it to a set of the numbers. If the size of the set is less than n, then false.
        # generating the substrings is O(N^2). We also need to put in something to limit it so it doesn't go over n. So we might not need to convert it, we just know how big N is in terms of binary, and we don't put like a filter so that
        substr = set()
        max_len = math.ceil(math.log(n, 2)) # this is the maximum length the string can take
        s = s.lstrip('0')
        # print(s, len(s))
        for i in range(len(s)):
            for j in range(i + 1, min(i + max_len, len(s)) + 1):
                print(i, j)
                # print(i, j)
                string = s[i:j]
                # this will always be only up to max len
                string = string.lstrip('0')
                base_10 = 0
                for k in range(len(string) - 1, -1, -1):
                    base_10 += int(string[k]) * 2 ** (len(string) - 1 - k)
                if base_10 <= n:
                    substr.add(base_10)
        print(substr)
        if 0 in substr:
            substr.remove(0)
        return len(substr) == n

16900