dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def addZeros ( strr , n ) :
    for i in range ( n ) :
        strr = "0" + strr
    return strr
def getXOR ( a , b ) :
    aLen = len ( a )
    bLen = len ( b )
    if ( aLen > bLen ) :
        b = addZeros ( b , aLen - bLen )
    elif ( bLen > aLen ) :
        a = addZeros ( a , bLen - aLen )
    lenn = max ( aLen , bLen ) ;
    res = " "
    for i in range ( lenn ) :
        if ( a [ i ] == b [ i ] ) :
            res += "0"
        else :
            res += "1"
    return res
a = "11001"
b = "111111"
print ( getXOR ( a , b ) )

Index/key variables: i
Accumulator variables: res
Iterator variables: i
Python program:
MAX = 26 ;
def minOperation ( str , len ) :
    first , last = [ 0 ] * MAX , [ 0 ] * MAX ;
    for i in range ( MAX ) :
        first [ i ] = - 1 ;
        last [ i ] = - 1 ;
    for i in range ( len ) :
        index = ( ord ( str [ i ] ) - ord ( ' a ' ) ) ;
        if ( first [ index ] == - 1 ) :
            first [ index ] = i ;
        last [ index ] = i ;
    minOp = - 1 ;
    for i in range ( MAX ) :
        if ( first [ i ] == - 1 or first [ i ] == last [ i ] ) :
            continue ;
        cnt = len - ( last [ i ] - first [ i ] + 1 ) ;
        if ( minOp == - 1 or cnt < minOp ) :
            minOp = cnt ;
    return minOp ;
str = " abcda " ;
len = len ( str ) ;
print ( minOperation ( str , len ) ) ;

Index/key variables: i, index
Iterator variables: i
Python program:
N = 2 ;
def isVowel ( ch ) :
    return ( ch == ' a ' or ch == ' e ' or ch == ' i ' or ch == ' o ' or ch == ' u ' ) ;
def countVowels ( string , l , r ) :
    cnt = 0 ;
    for i in range ( l , r + 1 ) :
        if ( isVowel ( string [ i ] ) ) :
            cnt += 1 ;
    return cnt ;
def performQueries ( string , queries , q ) :
    for i in range ( q ) :
        print ( countVowels ( string , queries [ i ] [ 0 ] , queries [ i ] [ 1 ] ) ) ;
if __name__ == " _ _ main _ _ " :
    string = " geeksforgeeks " ;
    queries = [ [ 1 , 3 ] , [ 2 , 4 ] , [ 1 , 9 ] ] ;
    q = len ( queries )
    performQueries ( string , queries , q ) ;

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
class node :
    def __init__ ( self ) :
        data = None
        next = None
def add ( data ) :
    newnode = node ( )
    newnode . data = data
    newnode . next = None
    return newnode
def string_to_SLL ( text , head ) :
    head = add ( text [ 0 ] )
    curr = head
    for i in range ( len ( text ) - 1 ) :
        curr . next = add ( text [ i + 1 ] )
        curr = curr . next
    return head
def print_ ( head ) :
    curr = head
    while ( curr != None ) :
        print ( ( curr . data ) , end = " ▁ - ▁ > ▁ " )
        curr = curr . next
text = " GEEKS "
head = None
head = string_to_SLL ( text , head )
print_ ( head )

Iterator variables: i
Class/struct names: node
Python program:
def minLength ( string , l ) :
    s = [ ] ;
    for i in range ( l ) :
        if ( len ( s ) == 0 ) :
            s . append ( string [ i ] ) ;
        else :
            c = s [ - 1 ] ;
            if ( c != string [ i ] and c . upper ( ) == string [ i ] . upper ( ) ) :
                s . pop ( ) ;
            else :
                s . append ( string [ i ] ) ;
    return len ( s ) ;
if __name__ == " _ _ main _ _ " :
    string = " ASbBsd " ;
    l = len ( string ) ;
    print ( minLength ( string , l ) ) ;

Index/key variables: i
Accumulator variables: s
Iterator variables: i
Python program:
MAX = 26
def canBeMadeEqual ( str1 , str2 ) :
    len1 = len ( str1 )
    len2 = len ( str2 )
    if ( len1 == len2 ) :
        freq = [ 0 for i in range ( MAX ) ]
        for i in range ( len1 ) :
            freq [ ord ( str1 [ i ] ) - ord ( ' a ' ) ] += 1
        for i in range ( len2 ) :
            if ( freq [ ord ( str2 [ i ] ) - ord ( ' a ' ) ] > 0 ) :
                return True
    return False
str1 = " abc "
str2 = " defa "
if ( canBeMadeEqual ( str1 , str2 ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i
Iterator variables: i
Python program:
def getCount ( str1 , n ) :
    cnt = 0 ;
    i = 0 ;
    while ( i < n - 2 ) :
        if ( str1 [ i ] == str1 [ i + 1 ] and str1 [ i ] == str1 [ i + 2 ] ) :
            cnt += 1
            i = i + 2
        else :
            i += 1
    return cnt
str1 = " aabbbcc "
n = len ( str1 )
print ( getCount ( str1 , n ) )

Index/key variables: i
Accumulator variables: cnt
Python program:
def fact ( n ) :
    fact = 1 ;
    for i in range ( 1 , n + 1 ) :
        fact *= i ;
    return fact ;
def countStrings ( string , n ) :
    distinct_char = set ( ) ;
    for i in range ( n ) :
        distinct_char . add ( string [ i ] ) ;
    return fact ( len ( distinct_char ) ) ;
if __name__ == " _ _ main _ _ " :
    string = " geeksforgeeks " ;
    n = len ( string ) ;
    print ( countStrings ( string , n ) ) ;

Index/key variables: i
Accumulator variables: distinct_char, fact
Iterator variables: i
Python program:
def getChar ( strr ) :
    summ = 0
    for i in range ( len ( strr ) ) :
        summ += ( ord ( strr [ i ] ) - ord ( ' a ' ) + 1 )
    if ( summ % 26 == 0 ) :
        return ord ( ' z ' )
    else :
        summ = summ % 26
        return chr ( ord ( ' a ' ) + summ - 1 )
strr = " gfg "
print ( getChar ( strr ) )

Index/key variables: i
Accumulator variables: summ
Iterator variables: i
Python program:
def reverse ( string , length , l , r ) :
    if ( l < 0 or r >= length or l > r ) :
        return string ;
    string = list ( string )
    while ( l < r ) :
        c = string [ l ] ;
        string [ l ] = string [ r ] ;
        string [ r ] = c ;
        l += 1 ;
        r -= 1 ;
    return " " . join ( string ) ;
if __name__ == " _ _ main _ _ " :
    string = " geeksforgeeks " ;
    length = len ( string ) ;
    l = 5 ; r = 7 ;
    print ( reverse ( string , length , l , r ) ) ;

Index/key variables: l, r
Python program:
def IsRedundantBraces ( A ) :
    a , b = 0 , 0 ;
    for i in range ( len ( A ) ) :
        if ( A [ i ] == ' ( ' and A [ i + 2 ] == ' ) ' ) :
            return True ;
        if ( A [ i ] == ' * ' or A [ i ] == ' + ' or A [ i ] == ' - ' or A [ i ] == ' / ' ) :
            a += 1 ;
        if ( A [ i ] == ' ( ' ) :
            b += 1 ;
    if ( b > a ) :
        return True ;
    return False ;
if __name__ == ' _ _ main _ _ ' :
    A = " ( ( ( a + b ) ▁ + ▁ c ) ▁ + ▁ d ) " ;
    if ( IsRedundantBraces ( A ) ) :
        print ( " YES " ) ;
    else :
        print ( " NO " ) ;

Index/key variables: i
Accumulator variables: a, b
Iterator variables: i
Python program:
def balancedBrackets ( Str ) :
    dep = 0
    minDep = 0
    for i in Str :
        if ( i == ' ( ' ) :
            dep += 1
        else :
            dep -= 1
        if ( minDep > dep ) :
            minDep = dep
    if ( minDep < 0 ) :
        for i in range ( abs ( minDep ) ) :
            Str = ' ( ' + Str
    dep = 0
    for i in Str :
        if ( i == ' ( ' ) :
            dep += 1
        else :
            dep -= 1
    if ( dep != 0 ) :
        for i in range ( dep ) : Str = Str + ' ) '
    return Str
Str = " ) ) ) ( ) "
print ( balancedBrackets ( Str ) )

Accumulator variables: dep
Iterator variables: i
Python program:
def minOperations ( str , n ) :
    count = 0
    for i in range ( n - 1 ) :
        if ( str [ i ] != str [ i + 1 ] ) :
            count += 1
    return ( count + 1 ) // 2
str = "000111"
n = len ( str )
print ( minOperations ( str , n ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def find_digit ( s , n ) :
    first_digit = - 1
    for i in range ( n - 1 , - 1 , - 1 ) :
        if s [ i ] < '0' or s [ i ] > '9' :
            first_digit = i
            break
    first_digit += 1
    s_len = first_digit
    num = 0
    pw = 1
    i = n - 1
    while i >= 0 :
        if s [ i ] >= '0' and s [ i ] <= '9' :
            digit = ord ( s [ i ] ) - ord ( '0' )
            num = num + ( pw * digit )
            if num >= s_len :
                return - 1
            pw = pw * 10
        i -= 1
    num = num * 10
    req = s_len - num
    if req > 9 or req < 0 :
        return - 1
    return req
if __name__ == " _ _ main _ _ " :
    s = " abcd0"
    n = len ( s )
    print ( find_digit ( s , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def canConvert ( str1 , str2 ) :
    i , j = 0 , 0 ;
    while ( i < len ( str1 ) and j < len ( str2 ) ) :
        if ( str1 [ i ] != str2 [ j ] ) :
            if ( str1 [ i ] == '0' and str2 [ j ] == '1' and i + 1 < len ( str1 ) and str1 [ i + 1 ] == '0' ) :
                i += 2 ;
                j += 1 ;
            else :
                return False ;
        else :
            i += 1 ;
            j += 1 ;
    if ( i == len ( str1 ) and j == len ( str2 ) ) :
        return True ;
    return False ;
str1 = "00100" ;
str2 = "111" ;
if ( canConvert ( str1 , str2 ) ) :
    print ( " Yes " ) ;
else :
    print ( " No " ) ;

Index/key variables: i, j
Python program:
def printMatrix ( n , m ) :
    if ( n < 5 or m < 5 ) :
        print ( - 1 , end = " ▁ " ) ;
        return ;
    s = " aeiou " ;
    s = list ( s ) ;
    for i in range ( n ) :
        for j in range ( m ) :
            print ( s [ j % 5 ] , end = " ▁ " ) ;
        print ( )
        c = s [ 0 ] ;
        for i in range ( 4 ) :
            s [ i ] = s [ i + 1 ] ;
        s [ 4 ] = c ;
if __name__ == " _ _ main _ _ " :
    n = 5 ; m = 5 ;
    printMatrix ( n , m ) ;

Index/key variables: i
Iterator variables: i, j
Python program:
def isTwoAlter ( s ) :
    for i in range ( len ( s ) - 2 ) :
        if ( s [ i ] != s [ i + 2 ] ) :
            return False
    if ( s [ 0 ] == s [ 1 ] ) :
        return False
    return True
if __name__ == " _ _ main _ _ " :
    str = " ABAB "
    if ( isTwoAlter ( str ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Iterator variables: i
Python program:
def minOperations ( n , a , b , c ) :
    ans = 0
    for i in range ( n ) :
        x = a [ i ]
        y = b [ i ]
        z = c [ i ]
        if ( x == y and y == z ) :
            continue
        elif ( x == y or y == z or x == z ) :
            ans += 1
        else :
            ans += 2
    return ans
if __name__ == ' _ _ main _ _ ' :
    a = " place "
    b = " abcde "
    c = " plybe "
    n = len ( a )
    print ( minOperations ( n , a , b , c ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def check ( s ) :
    n = len ( s )
    for i in range ( n - 1 ) :
        if ( s [ i ] > s [ i + 1 ] ) :
            return True
    return False
if __name__ == ' _ _ main _ _ ' :
    s = " geeksforgeeks "
    if ( check ( s ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Iterator variables: i
Python program:
def countSubStr ( str , n , x ) :
    res = 0 ; count = 0 ;
    for i in range ( n ) :
        if ( str [ i ] == x ) :
            res += ( ( count + 1 ) * ( n - i ) ) ;
            count = 0 ;
        else :
            count += 1 ;
    return res ;
str = " abcabc " ;
n = len ( str ) ;
x = ' c ' ;
print ( countSubStr ( str , n , x ) ) ;

Index/key variables: i
Accumulator variables: count, res
Iterator variables: i
Python program:
def countSubstrings ( s , c ) :
    n = len ( s )
    cnt = 0
    Sum = 0
    for i in range ( n ) :
        if ( s [ i ] != c ) :
            cnt += 1
        else :
            Sum += ( cnt * ( cnt + 1 ) ) // 2
            cnt = 0
    Sum += ( cnt * ( cnt + 1 ) ) // 2
    return Sum
s = " baa "
c = ' b '
print ( countSubstrings ( s , c ) )

Index/key variables: i
Accumulator variables: Sum, cnt
Iterator variables: i
Python program:
import sys
def getMinimizedSum ( string , length ) :
    maxVal = - ( sys . maxsize - 1 )
    sum = 0 ;
    occurrences = [ 0 ] * 26 ;
    for i in range ( length ) :
        occurrences [ ord ( string [ i ] ) - ord ( ' a ' ) ] += 1 ;
        sum += ord ( string [ i ] ) ;
    for i in range ( 26 ) :
        count = occurrences [ i ] * ( i + ord ( ' a ' ) )
        maxVal = max ( maxVal , count ) ;
    return ( sum - maxVal ) ;
if __name__ == " _ _ main _ _ " :
    string = " geeksforgeeks " ;
    length = len ( string ) ;
    print ( getMinimizedSum ( string , length ) ) ;

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def isPalindrome ( s ) :
    i = 0 ;
    j = len ( s ) - 1 ;
    while ( i < j ) :
        if ( s [ i ] is not s [ j ] ) :
            return False ;
        i += 1 ;
        j -= 1 ;
    return True ;
def getIndex ( S1 , S2 , n ) :
    S = " " ;
    for i in range ( n ) :
        S = S + S1 [ i ] ;
        Temp = " " ;
        for j in range ( i + 1 , n ) :
            Temp += S2 [ j ] ;
        if ( isPalindrome ( S + Temp ) ) :
            return i ;
    return - 1 ;
S1 = " abcdf " ; S2 = " sfgba " ;
n = len ( S1 ) ;
print ( getIndex ( S1 , S2 , n ) ) ;

Index/key variables: i, j
Accumulator variables: Temp
Iterator variables: i, j
Python program:
def isPalindrome ( s , i , j ) :
    while ( i < j ) :
        if ( s [ i ] != s [ j ] ) :
            return False ;
        i += 1 ;
        j -= 1 ;
    return True ;
def getIndex ( s1 , s2 , length ) :
    i = 0 ; j = length - 1 ;
    while ( i < j ) :
        if ( s1 [ i ] != s2 [ j ] ) :
            break ;
        i += 1 ;
        j -= 1 ;
    if ( i == j ) :
        return i - 1 ;
    elif ( isPalindrome ( s2 , i , j ) ) :
        return i - 1 ;
    elif ( isPalindrome ( s1 , i , j ) ) :
        return j ;
    return - 1 ;
if __name__ == " _ _ main _ _ " :
    s1 = " abcdf " ;
    s2 = " sfgba " ;
    length = len ( s1 ) ;
    print ( getIndex ( s1 , s2 , length ) ) ;

Index/key variables: i, j
Python program:
def count_acronym ( n , arr ) :
    freq = [ 0 ] * 26
    for i in range ( n ) :
        freq [ ord ( arr [ i ] [ 0 ] ) - ord ( ' a ' ) ] += 1
    cnt = 0
    for i in range ( n ) :
        st = arr [ i ]
        num = [ 0 ] * 26
        for j in range ( len ( st ) ) :
            num [ ord ( st [ j ] ) - ord ( ' a ' ) ] += 1
        flag = True
        for j in range ( 1 , 26 ) :
            if num [ j ] > freq [ j ] :
                flag = False
                break
        x = ord ( st [ 0 ] ) - ord ( ' a ' )
        if freq [ x ] - 1 < num [ x ] :
            flag = False
        if flag :
            cnt += 1
    return cnt
if __name__ == " _ _ main _ _ " :
    arr = [ " abc " , " bcad " , " cabd " , " cba " , " dzzz " ]
    n = 5
    print ( count_acronym ( n , arr ) )

Index/key variables: i, j, x
Accumulator variables: cnt
Iterator variables: i, j
Boolean variables: flag
Python program:
def valid ( cnt ) :
    for i in range ( 0 , 26 ) :
        if cnt [ i ] >= 2 :
            return False
    return True
def getGoodString ( s , n ) :
    if n < 26 :
        return " - 1"
    for i in range ( 25 , n ) :
        cnt = [ 0 ] * 26
        for j in range ( i , i - 26 , - 1 ) :
            if s [ j ] != ' ? ' :
                cnt [ ord ( s [ j ] ) - ord ( ' a ' ) ] += 1
        if valid ( cnt ) :
            cur = 0
            while cur < 26 and cnt [ cur ] > 0 :
                cur += 1
            for j in range ( i - 25 , i + 1 ) :
                if s [ j ] == ' ? ' :
                    s [ j ] = chr ( cur + ord ( ' a ' ) )
                    cur += 1
                    while cur < 26 and cnt [ cur ] > 0 :
                        cur += 1
            return ' ' . join ( s )
    return " - 1"
if __name__ == " _ _ main _ _ " :
    s = " abcdefghijkl ? nopqrstuvwxy ? "
    n = len ( s )
    print ( getGoodString ( list ( s ) , n ) )

Index/key variables: cur, i, j
Iterator variables: i, j
Python program:
def isVowel ( c ) :
    c = c . lower ( ) ;
    if ( c == ' a ' or c == ' e ' or c == ' i ' or c == ' o ' or c == ' u ' ) :
        return True ;
    return False ;
def swapRepeated ( string ) :
    for i in range ( len ( string ) - 1 ) :
        if ( ( isVowel ( string [ i ] ) and isVowel ( string [ i + 1 ] ) ) or ( not ( isVowel ( string [ i ] ) ) and not ( isVowel ( string [ i + 1 ] ) ) ) ) :
            ( string [ i ] , string [ i + 1 ] ) = ( string [ i + 1 ] , string [ i ] ) ;
    string = " " . join ( string )
    return string ;
if __name__ == " _ _ main _ _ " :
    string = " geeksforgeeks " ;
    print ( swapRepeated ( list ( string ) ) ) ;

Index/key variables: i
Iterator variables: i
Python program:
def largestPalinSub ( s ) :
    res = " "
    mx = s [ 0 ]
    for i in range ( 1 , len ( s ) ) :
        mx = max ( mx , s [ i ] )
    for i in range ( 0 , len ( s ) ) :
        if s [ i ] == mx :
            res += s [ i ]
    return res
if __name__ == " _ _ main _ _ " :
    s = " geeksforgeeks "
    print ( largestPalinSub ( s ) )

Index/key variables: i
Accumulator variables: res
Iterator variables: i
Python program:
def printString ( Str1 , n ) :
    ones = 0
    for i in range ( n ) :
        if ( Str1 [ i ] == '1' ) :
            ones += 1
    used = False
    for i in range ( n ) :
        if ( Str1 [ i ] == '2' and used == False ) :
            used = 1
            for j in range ( ones ) :
                print ( "1" , end = " " )
        if ( Str1 [ i ] != '1' ) :
            print ( Str1 [ i ] , end = " " )
    if ( used == False ) :
        for j in range ( ones ) :
            print ( "1" , end = " " )
Str1 = "100210"
n = len ( Str1 )
printString ( Str1 , n )

Index/key variables: i
Accumulator variables: ones
Iterator variables: i, j
Boolean variables: used
Python program:
import math as mt
def findPermutation ( string , k ) :
    has = [ False for i in range ( 26 ) ]
    cnt = 0
    for i in range ( len ( string ) ) :
        if ( has [ ord ( string [ i ] ) - ord ( ' a ' ) ] == False ) :
            cnt += 1
            has [ ord ( string [ i ] ) - ord ( ' a ' ) ] = True
    ans = 1
    for i in range ( 2 , cnt + 1 ) :
        ans *= i
    for i in range ( cnt - k , 1 , - 1 ) :
        ans //= i
    return ans
string = " geeksforgeeks "
k = 4
print ( findPermutation ( string , k ) )

Index/key variables: i
Accumulator variables: ans, cnt
Iterator variables: i
Python program:
def product ( x ) :
    prod = 1
    while ( x ) :
        prod *= ( x % 10 )
        x //= 10 ;
    return prod
def findNumber ( l , r ) :
    a = str ( l ) ;
    b = str ( r ) ;
    ans = r
    for i in range ( len ( b ) ) :
        if ( b [ i ] == '0' ) :
            continue
        curr = list ( b )
        curr [ i ] = str ( ( ( ord ( curr [ i ] ) - ord ( '0' ) ) - 1 ) + ord ( '0' ) )
        for j in range ( i + 1 , len ( curr ) ) :
            curr [ j ] = str ( ord ( '9' ) )
        num = 0
        for c in curr :
            num = num * 10 + ( int ( c ) - ord ( '0' ) )
        if ( num >= l and product ( ans ) < product ( num ) ) :
            ans = num
    return ans
if __name__ == " _ _ main _ _ " :
    l , r = 1 , 10
    print ( findNumber ( l , r ) )
    l , r = 51 , 62
    print ( findNumber ( l , r ) )

Index/key variables: i, j
Accumulator variables: prod, x
Iterator variables: c, i, j
Python program:
def printExpansion ( str ) :
    for i in range ( len ( str ) - 1 , - 1 , - 1 ) :
        for j in range ( i , len ( str ) ) :
            print ( str [ j ] , end = " " )
str = " geeks "
printExpansion ( str )

Index/key variables: j
Iterator variables: i, j
Python program:
def constructBinString ( a , b , x ) :
    d = x // 2
    if x % 2 == 0 and x // 2 != a :
        d -= 1
        print ( "0" , end = " " )
        a -= 1
    for i in range ( d ) :
        print ( "10" , end = " " )
    a = a - d
    b = b - d
    for i in range ( b ) :
        print ( "1" , end = " " )
    for i in range ( a ) :
        print ( "0" , end = " " )
if __name__ == " _ _ main _ _ " :
    a , b , x = 4 , 3 , 2
    constructBinString ( a , b , x )

Iterator variables: i
Python program:
def matchPattern ( s ) :
    count = 0 ;
    n = len ( s ) ;
    i = 0 ;
    while ( i < n ) :
        while ( i < n and s [ i ] == ' a ' ) :
            count += 1 ;
            i = + 1 ;
        while ( i < n and s [ i ] == ' b ' ) :
            count -= 1 ;
            i += 1 ;
        if ( count != 0 ) :
            return False ;
    return True ;
s = " bb " ;
if ( matchPattern ( s ) == True ) :
    print ( " Yes " ) ;
else :
    print ( " No " ) ;

Index/key variables: i
Accumulator variables: count
Python program:
def maximum_one ( s , n ) :
    cnt_one = 0
    cnt , max_cnt = 0 , 0
    for i in range ( n ) :
        if ( s [ i ] == '1' ) :
            cnt_one += 1
            cnt += 1
        else :
            max_cnt = max ( max_cnt , cnt )
            cnt = 0
    max_cnt = max ( max_cnt , cnt )
    left = [ 0 ] * n
    right = [ 0 ] * n
    if ( s [ 0 ] == '1' ) :
        left [ 0 ] = 1
    else :
        left [ 0 ] = 0
    if ( s [ n - 1 ] == '1' ) :
        right [ n - 1 ] = 1
    else :
        right [ n - 1 ] = 0
    for i in range ( 1 , n ) :
        if ( s [ i ] == '1' ) :
            left [ i ] = left [ i - 1 ] + 1
        else :
            left [ i ] = 0
    for i in range ( n - 2 , - 1 , - 1 ) :
        if ( s [ i ] == '1' ) :
            right [ i ] = right [ i + 1 ] + 1
        else :
            right [ i ] = 0
    for i in range ( 1 , n - 1 ) :
        if ( s [ i ] == '0' ) :
            sum = left [ i - 1 ] + right [ i + 1 ]
            if ( sum < cnt_one ) :
                max_cnt = max ( max_cnt , sum + 1 )
            else :
                max_cnt = max ( max_cnt , sum )
    return max_cnt
if __name__ == " _ _ main _ _ " :
    s = "111011101"
    print ( maximum_one ( s , len ( s ) ) )

Index/key variables: i
Accumulator variables: cnt, cnt_one
Iterator variables: i
Python program:
def maxFreq ( s , a , b ) :
    fre = [ 0 for i in range ( 10 ) ]
    n = len ( s )
    if ( a > b ) :
        swap ( a , b )
    for i in range ( 0 , n , 1 ) :
        a = ord ( s [ i ] ) - ord ( '0' )
        fre [ a ] += 1
    if ( fre [ a ] == 0 and fre [ b ] == 0 ) :
        return - 1
    elif ( fre [ a ] >= fre [ b ] ) :
        return a
    else :
        return b
if __name__ == ' _ _ main _ _ ' :
    a = 4
    b = 7
    s = "47744"
    print ( maxFreq ( s , a , b ) )

Index/key variables: a, b, i
Iterator variables: i
Python program:
def convert ( n , a , b ) :
    l = [ 0 ] * n
    for i in range ( n ) :
        if ( a [ i ] != b [ i ] ) :
            l [ i ] = 1
    cc = 0
    vl = 0
    for i in range ( n ) :
        if ( l [ i ] == 0 ) :
            if ( vl != 0 ) :
                cc += 1
            vl = 0
        else :
            vl += 1
    if ( vl != 0 ) :
        cc += 1
    print ( cc )
a = "101010"
b = "110011"
n = len ( a )
convert ( n , a , b )

Index/key variables: i
Accumulator variables: cc, vl
Iterator variables: i
Python program:
def StringMatch ( S ) :
    lo , hi = 0 , len ( S )
    ans = [ ]
    for x in S :
        if x == ' I ' :
            ans . append ( lo )
            lo += 1
        else :
            ans . append ( hi )
            hi -= 1
    return ans + [ lo ]
S = " IDID "
print ( StringMatch ( S ) )

Accumulator variables: ans, hi, lo
Iterator variables: x
Python program:
def countWays ( s1 , s2 , n ) :
    a = b = c = d = 0
    result = 0 ;
    for i in range ( 0 , n , 1 ) :
        if ( s2 [ i ] == '0' ) :
            if ( s1 [ i ] == '0' ) :
                c += 1 ;
            else :
                d += 1
        else :
            if ( s1 [ i ] == '0' ) :
                a += 1
            else :
                b += 1
    result = a * d + b * c + c * d
    return result
if __name__ == ' _ _ main _ _ ' :
    n = 5
    s1 = "01011"
    s2 = "11001"
    print ( countWays ( s1 , s2 , n ) )

Index/key variables: i
Accumulator variables: a, b, c, d
Iterator variables: i
Python program:
def returnWinner ( s , l ) :
    freq = [ 0 for i in range ( 26 ) ]
    for i in range ( 0 , l , 1 ) :
        freq [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1
    cnt = 0
    for i in range ( 26 ) :
        if ( freq [ i ] % 2 != 0 ) :
            cnt += 1
    if ( cnt == 0 or cnt & 1 == 1 ) :
        return 1
    else :
        return 2
if __name__ == ' _ _ main _ _ ' :
    s = " abaaab "
    l = len ( s )
    winner = returnWinner ( s , l )
    print ( " Player - " , winner )

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i