Skip to content

Practice Longest Binary Subsequence Less Than or Equal to K

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2311
LeetCode Problem

Longest Binary Subsequence Less Than or Equal to K

Problem Statement

Choose a subsequence of binary string s, preserving character order, whose binary numeric value is at most k. Leading zeros are allowed and the empty subsequence has value 0. Return the greatest possible length.

Source: Longest Binary Subsequence Less Than or Equal to K on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "1001010", k = 5
Output
5

# Example 2

Input
s = "00101001", k = 1
Output
6

Constraints

1 <= s.length <= 1000
s[i] is either '0' or '1'.
1 <= k <= 10^9

Related LeetCode Problems

Practice more problems similar to Longest Binary Subsequence Less Than or Equal to K.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.