<doocs>2311.Longest Binary Subsequence Less Than or Equal to K_1.py
def longestSubsequence( s: str, k: int) -> int:
    n = len(s)
    ans = s.count('0')
    v = 0
    for i in range(n - 1, -1, -1):
        if s[i] == '1':
            if v + (1 << (n - i - 1)) > k:
                break
            ans += 1
            v += 1 << (n - i - 1)
    return ans
def sample_funcname ( var_0 : str , var_2 : int ) -> int :
    var_5 = len ( var_0 )
    var_8 = var_0.count ( '0' )
    var_10 = 0
    for var_13 in range ( var_5 - 1 , - 1 , - 1 ) :
        if var_0 [ var_13 ] == '1' :
            if var_10 + ( 1 << ( var_5 - var_13 - 1 ) ) > var_2 :
                break
            var_8 += 1
            var_10 += 1 << ( var_5 - var_13 - 1 )
    return var_8
