Skip to content

2311. Longest Binary Subsequence Less Than or Equal to K #1854

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to find the length of the longest subsequence of a given binary string that forms a binary number less than or equal to a positive integer k. The solution involves efficiently exploring possible subsequences while maximizing their length under the constraint that their numeric value does not exceed k.

Approach

  1. Problem Analysis: The problem requires selecting a subsequence (not necessarily contiguous) from the binary string such that the binary number formed by the subsequence is ≤ k. The subsequence can include leading zeros, which do not affect the numeric value but contribute to the length. The challenge is to maximize the length of such a subsequence.

  2. Key Insight: The solut…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Jun 26, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Jun 26, 2025
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants