<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 {
    int getNumForBinary(string binaryNum) {
        int num = 0;
        for (int i = 0; i < binaryNum.size(); i++) {
            num += (binaryNum[i] - '0')*pow(2, binaryNum.size() - i - 1);
        }
        return num;
    }
public:
    bool queryString(string s, int n) {
        set<string> createdNumbers;
        string binaryRepresentationN = "";
        int tempN = n;
        while (tempN > 0) {
            binaryRepresentationN += char((tempN%2) + '0');
            tempN /= 2;
        }
        reverse(binaryRepresentationN.begin(), binaryRepresentationN.end());
        int left = 0, right = 32;
        int currLastPosition = 32;
        while (currLastPosition >= 0) {
            while (right < s.length()) {
                string str = "";
                for (int i = left; i <= right; i++) {
                    str += s[i];
                }
                if (str.length() <= binaryRepresentationN.length() && str[0] != '0') {
                    if (str.length() == binaryRepresentationN.length() && getNumForBinary(str) <= n) {
                        createdNumbers.insert(str);
                    } else if (str.length() < binaryRepresentationN.length()) {
                        createdNumbers.insert(str);
                    }
                }
                left++;
                right++;
            }
            currLastPosition--;
            right = currLastPosition;
            left = 0;
        }
        return createdNumbers.size() == n;
    }
};
19200