Class Solution
java.lang.Object
g2301_2400.s2311_longest_binary_subsequence_less_than_or_equal_to_k.Solution
2311 - Longest Binary Subsequence Less Than or Equal to K.<p>Medium</p>
<p>You are given a binary string <code>s</code> and a positive integer <code>k</code>.</p>
<p>Return <em>the length of the <strong>longest</strong> subsequence of</em> <code>s</code> <em>that makes up a <strong>binary</strong> number less than or equal to</em> <code>k</code>.</p>
<p>Note:</p>
<ul>
<li>The subsequence can contain <strong>leading zeroes</strong>.</li>
<li>The empty string is considered to be equal to <code>0</code>.</li>
<li>A <strong>subsequence</strong> is a string that can be derived from another string by deleting some or no characters without changing the order of the remaining characters.</li>
</ul>
<p><strong>Example 1:</strong></p>
<p><strong>Input:</strong> s = “1001010”, k = 5</p>
<p><strong>Output:</strong> 5</p>
<p><strong>Explanation:</strong> The longest subsequence of s that makes up a binary number less than or equal to 5 is “00010”, as this number is equal to 2 in decimal.</p>
<p>Note that “00100” and “00101” are also possible, which are equal to 4 and 5 in decimal, respectively.</p>
<p>The length of this subsequence is 5, so 5 is returned.</p>
<p><strong>Example 2:</strong></p>
<p><strong>Input:</strong> s = “00101001”, k = 1</p>
<p><strong>Output:</strong> 6</p>
<p><strong>Explanation:</strong> “000001” is the longest subsequence of s that makes up a binary number less than or equal to 1, as this number is equal to 1 in decimal.</p>
<p>The length of this subsequence is 6, so 6 is returned.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>1 <= s.length <= 1000</code></li>
<li><code>s[i]</code> is either <code>'0'</code> or <code>'1'</code>.</li>
<li><code>1 <= k <= 10<sup>9</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
longestSubsequence
-