dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def convertString ( S , k ) :
    n = len ( S )
    temp = S
    temp = list ( temp )
    for i in range ( k ) :
        for j in range ( n - 1 ) :
            if ( j == 0 and S [ j ] == '0' ) :
                temp [ j ] = S [ j + 1 ]
            elif ( j == n - 1 and S [ j ] == '0' ) :
                temp [ j ] = S [ j - 1 ]
            elif ( S [ j - 1 ] != S [ j + 1 ] and S [ j ] == '0' ) :
                temp [ j ] = '1'
        if ( S == temp ) :
            break
        temp = ' ' . join ( temp )
        S = temp
    print ( S )
if __name__ == ' _ _ main _ _ ' :
    S = "10010001"
    K = 1
    convertString ( S , K )

Index/key variables: j
Iterator variables: i, j
Python program:
def RemoveCharacters ( s ) :
    ans = " "
    c = [ 0 for i in range ( 26 ) ]
    pos = 0
    for i in range ( len ( s ) ) :
        if ( c [ ord ( s [ i ] ) - 97 ] == 0 ) :
            c [ ord ( s [ i ] ) - 97 ] = 1
            pos = i
            ans += s [ i ]
    for i in range ( pos + 1 , len ( s ) , 1 ) :
        if ( s [ i ] == s [ 0 ] ) :
            ans += s [ i ]
            break
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    S = " abcaadbcd "
    RemoveCharacters ( S )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def isPossible ( s , K ) :
    valid = False
    firstx = - 1
    n = len ( s )
    for i in range ( 1 , n // 2 + 1 , 1 ) :
        x = int ( s [ 0 : i ] )
        firstx = x
        test = str ( x )
        while ( len ( test ) < len ( s ) ) :
            x -= K
            test += str ( x )
        if ( test == s ) :
            valid = True
            break
    print ( " Yes " ) if valid == True else print ( " No " )
if __name__ == ' _ _ main _ _ ' :
    S = "8642"
    K = 2
    isPossible ( S , K )

Accumulator variables: test, x
Iterator variables: i
Boolean variables: valid
Python program:
def changeCharacters ( S , N , K ) :
    flag = 1
    count = 0
    st = [ ]
    for i in range ( N ) :
        if len ( st ) == 0 :
            if ( S [ i ] == '0' ) :
                flag = 0
                break
            count = 0
            st . append ( S [ i ] )
        else :
            if ( S [ i ] == '0' ) :
                count += 1
                if ( count == K ) :
                    del st [ - 1 ]
                    count = 0
            else :
                count = 0
    if ( flag ) :
        print ( " YES " )
    else :
        print ( " NO " )
if __name__ == ' _ _ main _ _ ' :
    S = "100100"
    N = len ( S )
    K = 2
    changeCharacters ( S , N , K )

Index/key variables: i
Accumulator variables: count, st
Iterator variables: i
Python program:
def prefixDivisble ( n ) :
    i = 1
    while n > 0 :
        if n % i != 0 :
            return False
        n = n // 10
        i += 1
    return True
n = 52248
if ( prefixDivisble ( n ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Accumulator variables: i
Python program:
def longestSubstring ( s ) :
    indexes = { }
    chars = { }
    chars [ ' a ' ] = 0
    chars [ ' e ' ] = 1
    chars [ ' i ' ] = 2
    chars [ ' o ' ] = 3
    chars [ ' u ' ] = 4
    evenOdd = "00000"
    evenOdd = [ i for i in evenOdd ]
    indexes [ " " . join ( evenOdd ) ] = - 1
    length = 0
    for i in range ( len ( s ) ) :
        c = s [ i ]
        if ( c in chars ) :
            evenOdd [ chars [ it ] ] = '1' if evenOdd [ chars [ it ] ] else '0'
        if ( " " . join ( evenOdd ) not in indexes ) :
            indexes [ " " . join ( evenOdd ) ] = i
        else :
            length = max ( length , i - indexes [ " " . join ( evenOdd ) ] )
    print ( length )
if __name__ == ' _ _ main _ _ ' :
    S = " bcbcbc "
    longestSubstring ( S )

Index/key variables: i, it
Iterator variables: i
Python program:
def isSubsequence ( str1 , str2 , m , n ) :
    j = 0
    i = 0
    while ( i < n and j < m ) :
        if ( str1 [ j ] == str2 [ i ] ) :
            j += 1
        i += 1
    return ( j == m )
def findMinimumNumber ( s ) :
    r = int ( s , 2 )
    ans = r + 1
    for i in range ( r + 1 ) :
        p = " "
        j = i
        while ( j > 0 ) :
            p += str ( j % 2 )
            j = j // 2
        m = len ( p )
        n = len ( s )
        p = p [ : : - 1 ]
        if ( isSubsequence ( p , s , m , n ) == False ) :
            ans = i
            break
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    s = "10101"
    findMinimumNumber ( s )

Index/key variables: i, j
Accumulator variables: p
Iterator variables: i
Python program:
def isPrime ( num ) :
    flag = False
    if num > 1 :
        for i in range ( 2 , num ) :
            if ( num % i ) == 0 :
                flag = True
                break
    if flag :
        return False
    else :
        return True
def order ( x ) :
    n = 0
    while ( x != 0 ) :
        n = n + 1
        x = x // 10
    return n
def isArmstrong ( x ) :
    n = order ( x )
    temp = x
    sum1 = 0
    while ( temp != 0 ) :
        r = temp % 10
        sum1 = sum1 + r ** n
        temp = temp // 10
    return ( sum1 == x )
def count_armstrong ( li ) :
    c = 0
    for ele in li :
        val = 0
        for che in ele :
            val += ord ( che )
        if isArmstrong ( val ) :
            c += 1
    return c
def count_prime ( li ) :
    c = 0
    for ele in li :
        val = 0
        for che in ele :
            val += ord ( che )
        if isPrime ( val ) :
            c += 1
    return c
arr = [ " geeksforgeeks " , " a " , " computer " , " science " , " portal " , " for " , " geeks " ]
print ( " Number ▁ of ▁ Armstrong ▁ Strings ▁ are : " , count_armstrong ( arr ) )
print ( " Number ▁ of ▁ Prime ▁ Strings ▁ are : " , count_prime ( arr ) )

Accumulator variables: c, val
Iterator variables: che, ele, i
Boolean variables: flag
Python program:
def findMinimumCost ( s , N ) :
    count_1 , count_0 = 0 , 0
    for i in range ( N ) :
        if ( s [ i ] == '1' ) :
            count_1 += 1
        else :
            count_0 += 1
    k = abs ( count_0 - count_1 )
    if ( count_1 == N or count_0 == N ) :
        print ( - 1 )
    else :
        print ( k // 2 )
if __name__ == ' _ _ main _ _ ' :
    S = "110110"
    N = len ( S )
    findMinimumCost ( S , N )

Index/key variables: i
Accumulator variables: count_0, count_1
Iterator variables: i
Python program:
import sys
from collections import defaultdict
def findMinimumTime ( S , N , K ) :
    if ( N == 0 ) :
        print ( 0 )
        return
    maxfreq = - sys . maxsize
    um = defaultdict ( int )
    for i in range ( N ) :
        um [ S [ i ] ] += 1
        if ( um [ S [ i ] ] > maxfreq ) :
            maxfreq = um [ S [ i ] ]
            maxchar = S [ i ]
    emptySlots = ( maxfreq - 1 ) * K
    for it in um :
        if ( it == maxchar ) :
            continue
        emptySlots -= min ( um [ it ] , maxfreq - 1 )
    ans = N + max ( 0 , emptySlots )
    print ( ans )
if __name__ == " _ _ main _ _ " :
    S = " AAABBB "
    K = 2
    N = len ( S )
    findMinimumTime ( S , N , K )

Index/key variables: i, it
Accumulator variables: emptySlots
Iterator variables: i, it
Python program:
def canMakeEqual ( S ) :
    N = len ( S )
    weightOfString = 0
    for i in range ( N ) :
        weightOfString += ord ( S [ i ] ) - ord ( ' a ' ) + 1
    if ( weightOfString % N == 0 ) :
        print ( " Yes " )
    else :
        print ( " No " )
S = " beb "
canMakeEqual ( S )

Index/key variables: i
Accumulator variables: weightOfString
Iterator variables: i
Python program:
def addFrequencyToCharacter ( S ) :
    frequency = [ 0 for i in range ( 26 ) ]
    N = len ( S )
    S = list ( S )
    for i in range ( N ) :
        frequency [ ord ( S [ i ] ) - ord ( ' a ' ) ] += 1
    for i in range ( N ) :
        add = frequency [ ord ( S [ i ] ) - ord ( ' a ' ) ] % 26
        if ord ( S [ i ] ) + add <= ord ( ' z ' ) :
            S [ i ] = chr ( ord ( S [ i ] ) + add )
        else :
            add = ord ( S [ i ] ) + add - ord ( ' z ' )
            S [ i ] = chr ( ord ( ' a ' ) + add - 1 )
    s = " "
    print ( s . join ( S ) )
if __name__ == ' _ _ main _ _ ' :
    S = " geeksforgeeks "
    addFrequencyToCharacter ( S )

Index/key variables: i
Iterator variables: i
Python program:
def minLength ( S ) :
    st = [ ]
    for ch in S :
        if ( len ( st ) == 0 ) :
            st . append ( ch )
        else :
            top = st [ - 1 ]
            if ( abs ( ord ( ch ) - ord ( top ) ) == 1 ) :
                st . pop ( )
            else :
                st . append ( ch )
    return len ( st )
if __name__ == " _ _ main _ _ " :
    S = "12213"
    print ( minLength ( S ) )

Accumulator variables: st
Iterator variables: ch
Python program:
def findMinimumTime ( tasks , K ) :
    map = { }
    curr_time = 0
    for c in tasks :
        if ( c in map ) :
            if ( curr_time - map <= K ) :
                curr_time += K - ( curr_time - map ) + 1
        map = curr_time
        curr_time += 1
    print ( curr_time )
if __name__ == " _ _ main _ _ " :
    S = " ABACCA "
    K = 2
    findMinimumTime ( S , K )

Accumulator variables: curr_time
Iterator variables: c
Python program:
def checkforSubsequence ( S , target ) :
    s = [ ]
    for i in range ( len ( target ) ) :
        s . append ( target [ i ] )
    for i in range ( len ( S ) - 1 , - 1 , - 1 ) :
        if ( len ( s ) == 0 ) :
            print ( " Yes " )
            return
        if ( S [ i ] == s [ - 1 ] ) :
            s . pop ( )
    if ( len ( s ) == 0 ) :
        print ( " Yes " )
    else :
        print ( " No " )
if __name__ == " _ _ main _ _ " :
    S = " KOTTAYAM "
    target = " KOTA "
    checkforSubsequence ( S , target )

Index/key variables: i
Accumulator variables: s
Iterator variables: i
Python program:
digits , sign = "0123456789" , " + - "
dot , ex = " . " , " eE "
dfa = [ [ 0 for i in range ( 5 ) ] for i in range ( 11 ) ]
def makeDFA ( ) :
    global dfa
    dfa [ 0 ] [ 0 ] = 1
    dfa [ 1 ] [ 0 ] = 1
    dfa [ 1 ] [ 2 ] = 3
    dfa [ 1 ] [ 3 ] = 2
    dfa [ 1 ] [ 4 ] = 6
    dfa [ 3 ] [ 0 ] = 4
    dfa [ 4 ] [ 0 ] = 4
    dfa [ 4 ] [ 3 ] = 5
    dfa [ 4 ] [ 4 ] = 6
    dfa [ 6 ] [ 0 ] = 8
    dfa [ 6 ] [ 1 ] = 7
    dfa [ 7 ] [ 0 ] = 8
    dfa [ 8 ] [ 0 ] = 8
    dfa [ 8 ] [ 3 ] = 9
def buildDFA ( ) :
    global dfa
    for i in range ( 11 ) :
        for j in range ( 5 ) :
            dfa [ i ] [ j ] = 10
    makeDFA ( )
def checkDFA ( s ) :
    buildDFA ( )
    currentstate = 0
    for i in range ( len ( s ) ) :
        if ( s [ i ] in digits ) :
            currentstate = dfa [ currentstate ] [ 0 ]
        elif ( s [ i ] in sign ) :
            currentstate = dfa [ currentstate ] [ 1 ]
        elif ( s [ i ] in dot ) :
            currentstate = dfa [ currentstate ] [ 2 ]
        elif ( s [ i ] in ex ) :
            currentstate = dfa [ currentstate ] [ 4 ]
        else :
            currentstate = dfa [ currentstate ] [ 3 ]
    if ( currentstate == 1 or currentstate == 4 or currentstate == 8 ) :
        print ( " Unsigned ▁ integer " )
    else :
        print ( " Not ▁ an ▁ unsigned ▁ integer " )
if __name__ == ' _ _ main _ _ ' :
    S = "1729"
    checkDFA ( S )

Index/key variables: currentstate, i, j
Iterator variables: i, j
Python program:
def printSentence ( str1 ) :
    nums = [ " " , " " , " ABC " , " DEF " , " GHI " , " JKL " , " MNO " , " PQRS " , " TUV " , " WXYZ " ]
    i = 0
    while ( i < len ( str1 ) ) :
        if ( str1 [ i ] == ' . ' ) :
            i += 1
            continue
        count = 0
        while ( i + 1 < len ( str1 ) and str1 [ i + 1 ] and str1 [ i ] == str1 [ i + 1 ] ) :
            if ( count == 2 and ( ( str1 [ i ] >= '2' and str1 [ i ] <= '6' ) or ( str1 [ i ] == '8' ) ) ) :
                break
            elif ( count == 3 and ( str1 [ i ] == '7' or str1 [ i ] == '9' ) ) :
                break
            count += 1
            i += 1
            if ( i < len ( str ) ) :
                break
        if ( str1 [ i ] == '7' or str1 [ i ] == '9' ) :
            print ( nums [ ord ( str1 [ i ] ) - 48 ] [ count % 4 ] , end = " " )
        else :
            print ( nums [ ord ( str1 [ i ] ) - 48 ] [ count % 3 ] , end = " " )
        i += 1
if __name__ == ' _ _ main _ _ ' :
    str1 = "234"
    printSentence ( str1 )

Index/key variables: i
Accumulator variables: count
Python program:
def getString ( N ) :
    ans = " "
    while ( N >= 26 ) :
        ans += ' z '
        N -= 26
    ans += chr ( N + ord ( ' a ' ) - 1 )
    return ans
if __name__ == ' _ _ main _ _ ' :
    N = 30
    print ( getString ( N ) )

Accumulator variables: N, ans
Python program:
def countSamePrefixSuffix ( s , n ) :
    prefix = " "
    for i in range ( n - 1 ) :
        prefix += s [ i ]
        suffix = s [ n - 1 - i : 2 * n - 2 - i ]
        if ( prefix == suffix ) :
            print ( len ( prefix ) , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    S = " ababababab "
    N = len ( S )
    countSamePrefixSuffix ( S , N )

Index/key variables: i
Accumulator variables: prefix
Iterator variables: i
Python program:
def countStringPairs ( a , n ) :
    ans = 0
    s = { }
    for i in range ( n ) :
        s [ a [ i ] ] = s . get ( a [ i ] , 0 ) + 1
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            p = [ i for i in a [ i ] ]
            q = [ j for j in a [ j ] ]
            if ( p [ 0 ] != q [ 0 ] ) :
                p [ 0 ] , q [ 0 ] = q [ 0 ] , p [ 0 ]
                if ( ( " " . join ( p ) not in s ) and ( " " . join ( q ) not in s ) ) :
                    ans += 1
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    arr = [ " good " , " bad " , " food " ]
    N = len ( arr )
    countStringPairs ( arr , N )

Index/key variables: i, j
Accumulator variables: ans
Iterator variables: i, j
Python program:
import random
def findRandom ( ) :
    num = random . randint ( 0 , 1 )
    return num
def generateBinaryString ( N ) :
    S = " "
    for i in range ( N ) :
        x = findRandom ( )
        S += str ( x )
    print ( S )
N = 7
generateBinaryString ( N )

Accumulator variables: S
Iterator variables: i
Python program:
def checkPalindrome ( s ) :
    a = [ 0 ] * 26
    o , e = 0 , 0
    for i in s :
        a [ ord ( i ) - 97 ] += 1
    for i in range ( 26 ) :
        if ( a [ i ] == 1 ) :
            o += 1
        elif ( a [ i ] % 2 == 0 and a [ i ] != 0 ) :
            e += ( a [ i ] // 2 )
    if ( e >= o ) :
        print ( " Yes " )
    else :
        o = o - e
        for i in range ( 26 ) :
            if ( o <= 0 ) :
                break
            if ( o > 0 and a [ i ] % 2 == 1 and a [ i ] > 2 ) :
                k = o
                o = o - a [ i ] // 2
                if ( o > 0 or 2 * k + 1 == a [ i ] ) :
                    o += 1
                    a [ i ] = 1
        if ( o <= 0 ) :
            print ( " Yes " )
        else :
            print ( " No " )
if __name__ == ' _ _ main _ _ ' :
    S = " abbbaddzcz "
    checkPalindrome ( S )

Index/key variables: i
Accumulator variables: e, o
Iterator variables: i
Python program:
from math import log2 , pow
def nearestPowerOfTwoUtil ( freq ) :
    temp = { }
    for key , value in freq . items ( ) :
        lg = int ( log2 ( value ) )
        a = int ( pow ( 2 , lg ) )
        b = int ( pow ( 2 , lg + 1 ) )
        if ( ( value - a ) < ( b - value ) ) :
            temp [ ( int ( a ) ) ] = key
        else :
            temp [ ( int ( b ) ) ] = key
    for key , value in temp . items ( ) :
        print ( value , " - > " , key )
def nearestPowerOfTwo ( S ) :
    N = len ( S )
    freq = { }
    for i in range ( N ) :
        if ( S [ i ] in freq ) :
            freq [ S [ i ] ] += 1
        else :
            freq [ S [ i ] ] = 1
    nearestPowerOfTwoUtil ( freq )
if __name__ == ' _ _ main _ _ ' :
    N = "16333331163"
    nearestPowerOfTwo ( N )

Index/key variables: i
Iterator variables: i, key, value
Python program:
def gcd ( a , b ) :
    if ( b == 0 ) :
        return a
    return gcd ( b , a % b )
def lcm ( a , b ) :
    return ( a // gcd ( a , b ) ) * b
def findSmallestString ( s , t ) :
    n , m = len ( s ) , len ( t )
    l = lcm ( n , m )
    s1 , t1 = " " , " "
    for i in range ( l // n ) :
        s1 += s
    for i in range ( l // m ) :
        t1 += t
    if ( s1 == t1 ) :
        print ( s1 )
    else :
        print ( - 1 )
if __name__ == ' _ _ main _ _ ' :
    S , T = " baba " , " ba "
    findSmallestString ( S , T )

Accumulator variables: s1, t1
Iterator variables: i
Python program:
def canMakeSame ( s1 , s2 ) :
    ans = - 1
    if ( len ( s1 ) != len ( s2 ) ) :
        return - 1
    N = len ( s1 )
    for i in range ( 0 , N ) :
        if ( s1 [ i ] != s2 [ i ] ) :
            while ( i < len ( s1 ) and s1 [ i ] != s2 [ i ] ) :
                i += 1
            ans += 1
    return ans
S1 = "100001"
S2 = "110111"
print ( canMakeSame ( S1 , S2 ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def count ( S , X , Y ) :
    N = len ( S )
    temp_x , temp_y = 0 , 0
    count = 0
    s = { }
    s [ ( X , Y ) ] = 1
    for i in range ( N ) :
        temp_x = X
        temp_y = Y
        if ( S [ i ] == ' U ' ) :
            X += 1
        elif ( S [ i ] == ' D ' ) :
            X -= 1
        elif ( S [ i ] == ' R ' ) :
            Y += 1
        else :
            Y -= 1
        if ( ( temp_x + X , temp_y + Y ) in s ) :
            count += 1
        else :
            s [ ( temp_x + X , temp_y + Y ) ] = 1
    return count
if __name__ == ' _ _ main _ _ ' :
    S = " RDDUDL "
    X , Y = 0 , 0
    print ( count ( S , X , Y ) )

Index/key variables: i
Accumulator variables: X, Y, count
Iterator variables: i
Python program:
def countTotalFrequencies ( S1 , S2 ) :
    bset = set ( S1 )
    count = 0
    for x in S2 :
        if x in bset :
            count += 1
    print ( count )
S1 = " geEksFOR "
S2 = " GeEksforgeEKS "
countTotalFrequencies ( S1 , S2 )

Accumulator variables: count
Iterator variables: x
Python program:
def min_length ( str ) :
    n = len ( str )
    total_zeros = 0
    total_ones = 0
    for i in range ( n ) :
        if ( str [ i ] == '0' ) :
            total_zeros += 1
        else :
            total_ones += 1
    ans = min ( total_zeros , total_ones )
    cur_zeros = 0
    cur_ones = 0
    for x in str :
        if ( x == '0' ) :
            cur_zeros += 1
        else :
            cur_ones += 1
        ans = min ( ans , cur_ones + ( total_zeros - cur_zeros ) )
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    str = "10011"
    min_length ( str )

Index/key variables: i
Accumulator variables: cur_ones, cur_zeros, total_ones, total_zeros
Iterator variables: i, x
Python program:
def kFreqWords ( S , K ) :
    l = list ( S . split ( " ▁ " ) )
    for i in l :
        if l . count ( i ) == K :
            print ( i )
            l . remove ( i )
if __name__ == " _ _ main _ _ " :
    S = " banana ▁ is ▁ in ▁ yellow ▁ and ▁ sun ▁ flower ▁ is ▁ also ▁ in ▁ yellow "
    K = 2
    kFreqWords ( S , K )

Iterator variables: i
Python program:
def make_palindrome ( S1 , S2 , S3 ) :
    maskA , maskC = 0 , 0
    for i in S1 :
        maskA |= ( 1 << ( ord ( i ) - ord ( ' a ' ) ) )
    for i in S3 :
        maskC |= ( 1 << ( ord ( i ) - ord ( ' a ' ) ) )
    if ( ( maskA & maskC ) > 0 ) :
        return " YES "
    return " NO "
if __name__ == ' _ _ main _ _ ' :
    S1 , S2 , S3 = " adcb " , " bcdb " , " abe "
    print ( make_palindrome ( S1 , S2 , S3 ) )

Accumulator variables: maskA, maskC
Iterator variables: i
Python program:
SIZE = 26
def longHelper ( freq1 , freq2 ) :
    for i in range ( 26 ) :
        if ( freq1 [ i ] != freq2 [ i ] ) :
            return False
    return True
def longCommomPrefixAnagram ( s1 , s2 , n1 , n2 ) :
    freq1 = [ 0 ] * 26
    freq2 = [ 0 ] * 26
    ans = 0
    mini_len = min ( n1 , n2 )
    for i in range ( mini_len ) :
        freq1 [ ord ( s1 [ i ] ) - ord ( ' a ' ) ] += 1
        freq2 [ ord ( s2 [ i ] ) - ord ( ' a ' ) ] += 1
        if ( longHelper ( freq1 , freq2 ) ) :
            ans = i + 1
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    str1 = " abaabcdezzwer "
    str2 = " caaabbttyh "
    N = len ( str1 )
    M = len ( str2 )
    longCommomPrefixAnagram ( str1 , str2 , N , M )

Index/key variables: i
Iterator variables: i
Python program:
def findRank ( s ) :
    N = len ( s ) ;
    sb = " " ;
    for i in range ( 0 , N ) :
        if ( s [ i ] == '0' ) :
            sb += str ( '0' ) ;
        else :
            sb += str ( '1' ) ;
    bin = str ( sb ) ;
    X = pow ( 2 , N ) ;
    Y = int ( bin ) ;
    ans = X + Y - 1 ;
    print ( ans ) ;
if __name__ == ' _ _ main _ _ ' :
    S = "001" ;
    findRank ( S ) ;

Index/key variables: i
Accumulator variables: sb
Iterator variables: i
Python program:
def canBeBalanced ( sequence ) :
    if ( len ( sequence ) % 2 ) :
        return False
    stack_ , stack2_ = [ ] , [ ]
    countOpen , countClosed = 0 , 0
    countSymbol = 0
    for i in range ( len ( sequence ) ) :
        if ( sequence [ i ] == ' ) ' ) :
            countClosed += 1
            if ( len ( stack_ ) == 0 ) :
                return False
            else :
                del stack_ [ - 1 ]
        else :
            if ( sequence [ i ] == ' $ ' ) :
                countSymbol += 1
            else :
                countOpen += 1
            stack_ . append ( sequence [ i ] )
    for i in range ( len ( sequence ) - 1 , - 1 , - 1 ) :
        if ( sequence [ i ] == ' ( ' ) :
            if ( len ( stack2_ ) == 0 ) :
                return False
            else :
                del stack2_ [ - 1 ]
        else :
            stack2_ . append ( sequence [ i ] )
    extra = abs ( countClosed - countOpen )
    if ( countSymbol < extra ) :
        return False
    else :
        countSymbol -= extra
        if ( countSymbol % 2 == 0 ) :
            return True
    return False
if __name__ == ' _ _ main _ _ ' :
    S = " ( ) ( $ "
    if ( canBeBalanced ( S ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Accumulator variables: countClosed, countOpen, countSymbol, stack2_, stack_
Iterator variables: i
Python program:
def maxDiffFreq ( queries , S ) :
    N = len ( S )
    Q = len ( queries )
    for i in range ( Q ) :
        l = queries [ i ] [ 0 ] - 1
        r = queries [ i ] [ 1 ] - 1
        freq = [ 0 ] * 26
        for j in range ( l , r + 1 ) :
            freq [ ord ( S [ j ] ) - ord ( ' a ' ) ] += 1
        mx = 0
        mn = 99999999
        for j in range ( 26 ) :
            mx = max ( mx , freq [ j ] )
            if ( freq [ j ] ) :
                mn = min ( mn , freq [ j ] )
        print ( mx - mn )
if __name__ == " _ _ main _ _ " :
    S = " abaabac "
    queries = [ [ 2 , 6 ] , [ 1 , 7 ] ]
    maxDiffFreq ( queries , S )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def countStrings ( S , list ) :
    valid = { }
    for x in S :
        valid [ x ] = 1
    cnt = 0
    for i in range ( len ( list ) ) :
        j = 0
        while j < len ( list [ i ] ) :
            if ( list [ i ] [ j ] in valid ) :
                j += 1
                continue
            else :
                break
            j += 1
        if ( j == len ( list [ i ] ) ) :
            cnt += 1
    return cnt
if __name__ == ' _ _ main _ _ ' :
    arr = [ " ab " , " aab " , " abaaaa " , " bbd " ]
    S , l = " ab " , [ ]
    print ( countStrings ( S , arr ) )

Index/key variables: i, j, x
Accumulator variables: cnt
Iterator variables: i, x
Python program:
def minLength ( Str , N , K , M ) :
    stackOfChar = [ ]
    for i in range ( N ) :
        stackOfChar . append ( Str [ i ] )
        if ( len ( stackOfChar ) >= M ) :
            l = " "
            for j in range ( M - 1 , - 1 , - 1 ) :
                if ( K [ j ] != stackOfChar [ - 1 ] ) :
                    f = 0
                    while ( f != len ( l ) ) :
                        stackOfChar . append ( l [ f ] )
                        f += 1
                    break
                else :
                    l = stackOfChar [ - 1 ] + l
                    stackOfChar . pop ( )
    return len ( stackOfChar )
S1 = " fffoxoxoxfxo "
S2 = " fox "
N = len ( S1 )
M = len ( S2 )
print ( minLength ( S1 , N , S2 , M ) )

Index/key variables: f, i, j
Accumulator variables: stackOfChar
Iterator variables: i, j