2311. Longest Binary Subsequence Less Than or Equal to K
On This Page
class Solution:
def longestSubsequence(self, s: str, k: int) -> int:
res = v = 0
for c in s[::-1]:
if c == "0":
res += 1
elif res < 30 and (v | 1 << res) <= k:
v |= 1 << res
res += 1
return res