dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
import sys
def findMinInsertions ( str , l , h ) :
    if ( l > h ) :
        return sys . maxsize
    if ( l == h ) :
        return 0
    if ( l == h - 1 ) :
        return 0 if ( str [ l ] == str [ h ] ) else 1
    if ( str [ l ] == str [ h ] ) :
        return findMinInsertions ( str , l + 1 , h - 1 )
    else :
        return ( min ( findMinInsertions ( str , l , h - 1 ) , findMinInsertions ( str , l + 1 , h ) ) + 1 )
if __name__ == " _ _ main _ _ " :
    str = " geeks "
    print ( findMinInsertions ( str , 0 , len ( str ) - 1 ) )

Index/key variables: h, l
Python program:
def max ( x , y ) :
    if ( x > y ) :
        return x
    return y
def lps ( seq , i , j ) :
    if ( i == j ) :
        return 1
    if ( seq [ i ] == seq [ j ] and i + 1 == j ) :
        return 2
    if ( seq [ i ] == seq [ j ] ) :
        return lps ( seq , i + 1 , j - 1 ) + 2
    return max ( lps ( seq , i , j - 1 ) , lps ( seq , i + 1 , j ) )
if __name__ == ' _ _ main _ _ ' :
    seq = " GEEKSFORGEEKS "
    n = len ( seq )
    print ( " The ▁ length ▁ of ▁ the ▁ LPS ▁ is " , lps ( seq , 0 , n - 1 ) )

Index/key variables: i, j
Python program:
INT_MAX = 1000006
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def heightoftree ( root ) :
    if ( root == None ) :
        return 0 ;
    left = heightoftree ( root . left ) ;
    right = heightoftree ( root . right ) ;
    return ( ( left if left > right else right ) + 1 ) ;
def printPerLevelMinimum ( root , res , level ) :
    if ( root != None ) :
        res = printPerLevelMinimum ( root . left , res , level + 1 ) ;
        if ( root . data < res [ level ] ) :
            res [ level ] = root . data ;
        res = printPerLevelMinimum ( root . right , res , level + 1 ) ;
    return res
def perLevelMinimumUtility ( root ) :
    n = heightoftree ( root )
    i = 0
    res = [ INT_MAX for i in range ( n ) ]
    res = printPerLevelMinimum ( root , res , 0 ) ;
    print ( " Every ▁ level ▁ minimum ▁ is " )
    for i in range ( n ) :
        print ( ' level ▁ ' + str ( i ) + ' ▁ min ▁ is ▁ = ▁ ' + str ( res [ i ] ) )
def newNode ( data ) :
    temp = Node ( data )
    return temp ;
if __name__ == " _ _ main _ _ " :
    root = newNode ( 7 ) ;
    root . left = newNode ( 6 ) ;
    root . right = newNode ( 5 ) ;
    root . left . left = newNode ( 4 ) ;
    root . left . right = newNode ( 3 ) ;
    root . right . left = newNode ( 2 ) ;
    root . right . right = newNode ( 1 ) ;
    perLevelMinimumUtility ( root ) ;

Index/key variables: i, level
Iterator variables: i
Class/struct names: Node
Python program:
from queue import Queue
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
def heightoftree ( root ) :
    if ( root == None ) :
        return 0
    left = heightoftree ( root . left )
    right = heightoftree ( root . right )
    if left > right :
        return left + 1
    else :
        return right + 1
def printPerLevelMinimum ( root ) :
    if ( root == None ) :
        return
    q = Queue ( )
    q . put ( root )
    q . put ( None )
    Min = 9999999999999
    level = 0
    while ( q . empty ( ) == False ) :
        node = q . queue [ 0 ]
        q . get ( )
        if ( node == None ) :
            print ( " level " , level , " min ▁ is ▁ = " , Min )
            if ( q . empty ( ) ) :
                break
            q . put ( None )
            level += 1
            Min = 999999999999
            continue
        if ( Min > node . data ) :
            Min = node . data
        if ( node . left != None ) :
            q . put ( node . left )
        if ( node . right != None ) :
            q . put ( node . right )
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 7 )
    root . left = newNode ( 6 )
    root . right = newNode ( 5 )
    root . left . left = newNode ( 4 )
    root . left . right = newNode ( 3 )
    root . right . left = newNode ( 2 )
    root . right . right = newNode ( 1 )
    print ( " Every ▁ Level ▁ minimum ▁ is " )
    printPerLevelMinimum ( root )

Accumulator variables: level
Class/struct names: newNode
Python program:
import sys
def findCount ( str1 , str2 ) :
    len1 = len ( str1 )
    len2 = len ( str2 )
    ans = sys . maxsize
    hash1 = [ 0 ] * 26
    hash2 = [ 0 ] * 26
    for i in range ( 0 , len1 ) :
        hash1 [ ord ( str1 [ i ] ) - 97 ] = hash1 [ ord ( str1 [ i ] ) - 97 ] + 1
    for i in range ( 0 , len2 ) :
        hash2 [ ord ( str2 [ i ] ) - 97 ] = hash2 [ ord ( str2 [ i ] ) - 97 ] + 1
    for i in range ( 0 , 26 ) :
        if ( hash2 [ i ] != 0 ) :
            ans = min ( ans , hash1 [ i ] // hash2 [ i ] )
    return ans
str1 = " geeksclassesatnoida "
str2 = " sea "
print ( findCount ( str1 , str2 ) )

Index/key variables: i
Iterator variables: i
Python program:
def isVowel ( c ) :
    vowel = " aeiou "
    for i in range ( len ( vowel ) ) :
        if ( vowel [ i ] == c ) :
            return True
    return False
def printRLE ( str , typed ) :
    n = len ( str )
    m = len ( typed )
    j = 0
    for i in range ( n ) :
        if str [ i ] != typed [ j ] :
            return False
        if isVowel ( str [ i ] ) == False :
            j = j + 1
            continue
        count1 = 1
        while ( i < n - 1 and ( str [ i ] == str [ i + 1 ] ) ) :
            count1 = count1 + 1
            i = i + 1
        count2 = 1
        while ( j < m - 1 and typed [ j ] == str [ i ] ) :
            count2 = count2 + 1
            j = j + 1
        if count1 > count2 :
            return False
    return True
name = " alex "
typed = " aaalaeex "
if ( printRLE ( name , typed ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i, j
Iterator variables: i
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def getLevelUtil ( node , data , level ) :
    if ( node == None ) :
        return 0
    if ( node . data == data ) :
        return level
    downlevel = getLevelUtil ( node . left , data , level + 1 )
    if ( downlevel != 0 ) :
        return downlevel
    downlevel = getLevelUtil ( node . right , data , level + 1 )
    return downlevel
def getLevel ( node , data ) :
    return getLevelUtil ( node , data , 1 )
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 3 )
    root . left = newNode ( 2 )
    root . right = newNode ( 5 )
    root . left . left = newNode ( 1 )
    root . left . right = newNode ( 4 )
    for x in range ( 1 , 6 ) :
        level = getLevel ( root , x )
        if ( level ) :
            print ( " Level ▁ of " , x , " is " , getLevel ( root , x ) )
        else :
            print ( x , " is ▁ not ▁ present ▁ in ▁ tree " )

Iterator variables: x
Class/struct names: newNode
Python program:
def censor ( text , word ) :
    word_list = text . split ( )
    result = ' '
    stars = ' * ' * len ( word )
    count = 0
    index = 0 ;
    for i in word_list :
        if i == word :
            word_list [ index ] = stars
        index += 1
    result = ' ▁ ' . join ( word_list )
    return result
if __name__ == ' _ _ main _ _ ' :
    extract = " GeeksforGeeks ▁ is ▁ a ▁ computer ▁ science ▁ portal ▁ for ▁ geeks . \ STRNEWLINE TABSYMBOL TABSYMBOL TABSYMBOL I ▁ am ▁ pursuing ▁ my ▁ major ▁ in ▁ computer ▁ science . ▁ "
    cen = " computer "
    print ( censor ( extract , cen ) )

Index/key variables: index
Iterator variables: i
Python program:
def generateLetters ( S , P , M ) :
    if ( P == len ( S ) ) :
        print ( S ) ;
        return
    generateLetters ( S , P + 1 , M ) ;
    S = S . replace ( S [ P ] , M [ S [ P ] ] )
    generateLetters ( S , P + 1 , M ) ;
S = " aBc " ;
M = { } ;
M [ ' a ' ] = ' $ '
M [ ' B ' ] = ' # '
M [ ' c ' ] = ' ^ '
M [ ' d ' ] = ' & '
M [ '1' ] = ' * '
M [ '2' ] = ' ! '
M [ ' E ' ] = ' @ '
generateLetters ( S , 0 , M ) ;

Index/key variables: P
Python program:
import sys
ansSwaps = 0
def check ( S ) :
    for i in range ( 1 , len ( S ) ) :
        if ( S [ i - 1 ] == S [ i ] ) :
            return False
    return True
def minimumSwaps ( S , swaps , idx ) :
    global ansSwaps
    if ( check ( S ) ) :
        ansSwaps = 1 + min ( ansSwaps , swaps )
    for i in range ( idx , len ( S ) ) :
        for j in range ( i + 1 , len ( S ) ) :
            swap ( S , i , j )
            minimumSwaps ( S , swaps + 1 , i + 1 )
            S = swap ( S , i , j )
def swap ( arr , i , j ) :
    temp = arr [ i ]
    arr [ i ] = arr [ j ]
    arr [ j ] = temp
    return arr
def findMinimumSwaps ( S ) :
    global ansSwaps
    ansSwaps = sys . maxsize
    minimumSwaps ( S , 0 , 0 )
    if ( ansSwaps == sys . maxsize ) :
        print ( " - 1" )
    else :
        print ( ansSwaps )
S = " ABAACD "
findMinimumSwaps ( S . split ( ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
_MIN = - 2147483648
_MAX = 2147483648
class getnode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def getlevel ( root , data ) :
    q = [ ]
    level = 1
    q . append ( root )
    q . append ( None )
    while ( len ( q ) ) :
        temp = q [ 0 ]
        q . pop ( 0 )
        if ( temp == None ) :
            if len ( q ) == 0 :
                return 0
            if ( q [ 0 ] != None ) :
                q . append ( None )
            level += 1
        else :
            if ( temp . data == data ) :
                return level
            if ( temp . left ) :
                q . append ( temp . left )
            if ( temp . right ) :
                q . append ( temp . right )
    return 0
if __name__ == ' _ _ main _ _ ' :
    root = getnode ( 20 )
    root . left = getnode ( 10 )
    root . right = getnode ( 30 )
    root . left . left = getnode ( 5 )
    root . left . right = getnode ( 15 )
    root . left . right . left = getnode ( 12 )
    root . right . left = getnode ( 25 )
    root . right . right = getnode ( 40 )
    level = getlevel ( root , 30 )
    if level != 0 :
        print ( " level ▁ of ▁ node ▁ 30 ▁ is " , level )
    else :
        print ( " node ▁ 30 ▁ not ▁ found " )
    level = getlevel ( root , 12 )
    if level != 0 :
        print ( " level ▁ of ▁ node ▁ 12 ▁ is " , level )
    else :
        print ( " node ▁ 12 ▁ not ▁ found " )
    level = getlevel ( root , 25 )
    if level != 0 :
        print ( " level ▁ of ▁ node ▁ 25 ▁ is " , level )
    else :
        print ( " node ▁ 25 ▁ not ▁ found " )
    level = getlevel ( root , 27 )
    if level != 0 :
        print ( " level ▁ of ▁ node ▁ 27 ▁ is " , level )
    else :
        print ( " node ▁ 27 ▁ not ▁ found " )

Accumulator variables: level, q
Class/struct names: getnode
Python program:
class Node :
    def __init__ ( self , d ) :
        self . data = d
        self . left = None
        self . right = None
def checkPalindrome ( s ) :
    low , high = 0 , len ( s ) - 1
    while ( low < high ) :
        if ( s [ low ] != s [ high ] ) :
            return False
        low += 1
        high -= 1
    return True
def lexicographicallySmall ( root , s ) :
    global finalAns
    if ( root == None ) :
        return
    s += root . data
    if ( not root . left and not root . right ) :
        if ( checkPalindrome ( s ) ) :
            if ( finalAns == " $ " ) :
                finalAns = s
            else :
                finalAns = min ( finalAns , s )
        return
    lexicographicallySmall ( root . left , s )
    lexicographicallySmall ( root . right , s )
def getPalindromePath ( root ) :
    global finalAns
    finalAns = " $ "
    lexicographicallySmall ( root , " " )
    if ( finalAns == " $ " ) :
        print ( " No ▁ Palindromic ▁ Path ▁ exists " )
    else :
        print ( finalAns )
if __name__ == ' _ _ main _ _ ' :
    finalAns = " "
    root = Node ( ' a ' )
    root . left = Node ( ' c ' )
    root . left . left = Node ( ' a ' )
    root . left . right = Node ( ' g ' )
    root . right = Node ( ' b ' )
    root . right . left = Node ( ' b ' )
    root . right . right = Node ( ' x ' )
    root . right . left . right = Node ( ' a ' )
    getPalindromePath ( root )

Index/key variables: high, low
Class/struct names: Node
Python program:
class Node :
    def __init__ ( self , key , lchild = None , rchild = None ) :
        self . key = key
        self . lchild = None
        self . rchild = None
def findMirrorRec ( target , left , right ) :
    if left == None or right == None :
        return None
    if left . key == target :
        return right . key
    if right . key == target :
        return left . key
    mirror_val = findMirrorRec ( target , left . lchild , right . rchild )
    if mirror_val != None :
        return mirror_val
    findMirrorRec ( target , left . rchild , right . lchild )
def findMirror ( root , target ) :
    if root == None :
        return None
    if root . key == target :
        return target
    return findMirrorRec ( target , root . lchild , root . rchild )
def main ( ) :
    root = Node ( 1 )
    n1 = Node ( 2 )
    n2 = Node ( 3 )
    root . lchild = n1
    root . rchild = n2
    n3 = Node ( 4 )
    n4 = Node ( 5 )
    n5 = Node ( 6 )
    n1 . lchild = n3
    n2 . lchild = n4
    n2 . rchild = n5
    n6 = Node ( 7 )
    n7 = Node ( 8 )
    n8 = Node ( 9 )
    n3 . rchild = n6
    n4 . lchild = n7
    n4 . rchild = n8
    target = n3 . key
    mirror = findMirror ( root , target )
    print ( " Mirror ▁ of ▁ node ▁ { } ▁ is ▁ node ▁ { } " . format ( target , mirror ) )
if __name__ == ' _ _ main _ _ ' :
    main ( )

Class/struct names: Node
Python program:
import sys
def balanced ( small , caps ) :
    for i in range ( 26 ) :
        if ( small [ i ] != 0 and ( caps [ i ] == 0 ) ) :
            return 0
        elif ( ( small [ i ] == 0 ) and ( caps [ i ] != 0 ) ) :
            return 0
    return 1
def smallestBalancedSubstring ( s ) :
    small = [ 0 for i in range ( 26 ) ]
    caps = [ 0 for i in range ( 26 ) ]
    for i in range ( len ( s ) ) :
        if ( ord ( s [ i ] ) >= 65 and ord ( s [ i ] ) <= 90 ) :
            caps [ ord ( s [ i ] ) - 65 ] += 1
        else :
            small [ ord ( s [ i ] ) - 97 ] += 1
    mp = { }
    for i in range ( 26 ) :
        if ( small [ i ] and caps [ i ] == 0 ) :
            mp [ chr ( i + 97 ) ] = 1
        elif ( caps [ i ] and small [ i ] == 0 ) :
            mp [ chr ( i + 65 ) ] = 1
    for i in range ( len ( small ) ) :
        small [ i ] = 0
        caps [ i ] = 0
    i = 0
    st = 0
    start = - 1
    end = - 1
    minm = sys . maxsize
    while ( i < len ( s ) ) :
        if ( s [ i ] in mp ) :
            while ( st < i ) :
                if ( ord ( s [ st ] ) >= 65 and ord ( s [ st ] ) <= 90 ) :
                    caps [ ord ( s [ st ] ) - 65 ] -= 1
                else :
                    small [ ord ( s [ st ] ) - 97 ] -= 1
                st += 1
            i += 1
            st = i
        else :
            if ( ord ( s [ i ] ) >= 65 and ord ( s [ i ] ) <= 90 ) :
                caps [ ord ( s [ i ] ) - 65 ] += 1
            else :
                small [ ord ( s [ i ] ) - 97 ] += 1
            while ( 1 ) :
                if ( ord ( s [ st ] ) >= 65 and ord ( s [ st ] ) <= 90 and caps [ ord ( s [ st ] ) - 65 ] > 1 ) :
                    caps [ ord ( s [ st ] ) - 65 ] -= 1
                    st += 1
                elif ( ord ( s [ st ] ) >= 97 and ord ( s [ st ] ) <= 122 and small [ ord ( s [ st ] ) - 97 ] > 1 ) :
                    small [ ord ( s [ st ] ) - 97 ] -= 1
                    st += 1
                else :
                    break
            if ( balanced ( small , caps ) ) :
                if ( minm > ( i - st + 1 ) ) :
                    minm = i - st + 1
                    start = st
                    end = i
            i += 1
    if ( start == - 1 or end == - 1 ) :
        print ( - 1 )
    else :
        ans = " "
        for i in range ( start , end + 1 , 1 ) :
            ans += s [ i ]
        print ( ans )
if __name__ == ' _ _ main _ _ ' :
    s = " azABaabba "
    smallestBalancedSubstring ( s )

Index/key variables: i, st
Accumulator variables: ans
Iterator variables: i
Python program:
def transformString ( str1 , str2 ) :
    N = len ( str1 )
    convChar = [ ]
    str1array = [ ]
    for i in range ( 26 ) :
        convChar . append ( [ ] )
        str1array . append ( [ ] )
    convertMap = { }
    for i in range ( N ) :
        str1array [ ord ( str1 [ i ] ) - ord ( ' a ' ) ] . append ( i )
    for i in range ( N ) :
        if ( str1 [ i ] < str2 [ i ] ) :
            print ( - 1 )
            return
        elif ( str1 [ i ] == str2 [ i ] ) :
            continue
        else :
            convChar [ ord ( str2 [ i ] ) - ord ( ' a ' ) ] . append ( i )
            convertMap [ i ] = str2 [ i ]
    ret = 0
    retv = [ ]
    for i in range ( 25 , - 1 , - 1 ) :
        v = convChar [ i ]
        if ( len ( v ) == 0 ) :
            continue
        ret += 1 ;
        v1 = str1array [ i ]
        if ( len ( v1 ) == 0 ) :
            print ( - 1 )
            return
        isScompleted = False
        for j in range ( len ( v1 ) ) :
            if ( v1 [ j ] in convertMap ) :
                a = v1 [ j ]
                if ( a > i + ord ( ' a ' ) ) :
                    continue
                else :
                    v . append ( v1 [ j ] )
                    isScompleted = True
                    retv . append ( v )
                    break
            else :
                v . append ( v1 [ j ] )
                isScompleted = True
                retv . append ( v )
                break
        if ( isScompleted == False ) :
            print ( - 1 )
            return
    print ( ret )
A = " abcab "
B = " aabab "
transformString ( A , B )

Index/key variables: i, j
Accumulator variables: convChar, ret, retv, str1array, v
Iterator variables: i, j
Boolean variables: isScompleted
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
def largestSubtreeUtil ( root , Str , maxSize , maxNode ) :
    if ( root == None ) :
        return 0
    left = [ " " ]
    right = [ " " ]
    ls = largestSubtreeUtil ( root . left , left , maxSize , maxNode )
    rs = largestSubtreeUtil ( root . right , right , maxSize , maxNode )
    size = ls + rs + 1
    if ( left [ 0 ] == right [ 0 ] ) :
        if ( size > maxSize [ 0 ] ) :
            maxSize [ 0 ] = size
            maxNode [ 0 ] = root
    Str [ 0 ] = Str [ 0 ] + " | " + left [ 0 ] + " | "
    Str [ 0 ] = Str [ 0 ] + " | " + str ( root . data ) + " | "
    Str [ 0 ] = Str [ 0 ] + " | " + right [ 0 ] + " | "
    return size
def largestSubtree ( node , maxNode ) :
    maxSize = [ 0 ]
    Str = [ " " ]
    largestSubtreeUtil ( node , Str , maxSize , maxNode )
    return maxSize
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 50 )
    root . left = newNode ( 10 )
    root . right = newNode ( 60 )
    root . left . left = newNode ( 5 )
    root . left . right = newNode ( 20 )
    root . right . left = newNode ( 70 )
    root . right . left . left = newNode ( 65 )
    root . right . left . right = newNode ( 80 )
    root . right . right = newNode ( 70 )
    root . right . right . left = newNode ( 65 )
    root . right . right . right = newNode ( 80 )
    maxNode = [ None ]
    maxSize = largestSubtree ( root , maxNode )
    print ( " Largest ▁ Subtree ▁ is ▁ rooted ▁ at ▁ node ▁ " , maxNode [ 0 ] . data )
    print ( " and ▁ its ▁ size ▁ is ▁ " , maxSize )

Class/struct names: newNode
Python program:
visited = set ( )
ans = [ ]
def dfs ( curr , D ) :
    for c in range ( D ) :
        c = str ( c )
        neighbour = curr + c
        if neighbour not in visited :
            visited . add ( neighbour )
            dfs ( neighbour [ 1 : ] , D )
            ans . append ( c )
def reqString ( N , D ) :
    if ( N == 1 and D == 1 ) :
        return "0"
    start = ' ' . join ( [ '0' ] * ( N - 1 ) )
    dfs ( start , D )
    ans . extend ( [ '0' ] * ( N - 1 ) )
    return ' ' . join ( ans )
if __name__ == ' _ _ main _ _ ' :
    N , D = 2 , 2
    print ( reqString ( N , D ) )

Accumulator variables: ans, visited
Iterator variables: c
Python program:
def isScramble ( S1 : str , S2 : str ) :
    if len ( S1 ) != len ( S2 ) :
        return False
    n = len ( S1 )
    if not n :
        return True
    if S1 == S2 :
        return True
    if sorted ( S1 ) != sorted ( S2 ) :
        return False
    for i in range ( 1 , n ) :
        if ( isScramble ( S1 [ : i ] , S2 [ : i ] ) and isScramble ( S1 [ i : ] , S2 [ i : ] ) ) :
            return True
        if ( isScramble ( S1 [ - i : ] , S2 [ : i ] ) and isScramble ( S1 [ : - i ] , S2 [ i : ] ) ) :
            return True
    return False
if __name__ == " _ _ main _ _ " :
    S1 = " coder "
    S2 = " ocred "
    if ( isScramble ( S1 , S2 ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Iterator variables: i
Python program:
def findAns ( s ) :
    odd = [ ]
    even = [ ]
    for c in s :
        digit = int ( c )
        if ( digit & 1 ) :
            odd . append ( digit )
        else :
            even . append ( digit )
    i = 0
    j = 0
    ans = " "
    while ( i < len ( odd ) and j < len ( even ) ) :
        if ( odd [ i ] < even [ j ] ) :
            ans += str ( odd [ i ] )
            i = i + 1
        else :
            ans += str ( even [ j ] )
            j = j + 1
    while ( i < len ( odd ) ) :
        ans += str ( odd [ i ] )
        i = i + 1
    while ( j < len ( even ) ) :
        ans += str ( even [ j ] )
        j = j + 1
    while ( ans [ 0 ] == '0' ) :
        ans = ans [ 1 : ]
    return ans
s = "894687536"
print ( findAns ( s ) )

Index/key variables: i, j
Accumulator variables: ans, even, odd
Iterator variables: c
Python program:
def bcdToDecimal ( s ) :
    length = len ( s ) ;
    check = 0 ;
    check0 = 0 ;
    num = 0 ;
    sum = 0 ;
    mul = 1 ;
    rev = 0 ;
    for i in range ( length - 1 , - 1 , - 1 ) :
        sum += ( ord ( s [ i ] ) - ord ( '0' ) ) * mul ;
        mul *= 2 ;
        check += 1 ;
        if ( check == 4 or i == 0 ) :
            if ( sum == 0 and check0 == 0 ) :
                num = 1 ;
                check0 = 1 ;
            else :
                num = num * 10 + sum ;
            check = 0 ;
            sum = 0 ;
            mul = 1 ;
    while ( num > 0 ) :
        rev = rev * 10 + ( num % 10 ) ;
        num //= 10 ;
    if ( check0 == 1 ) :
        return rev - 1 ;
    return rev ;
if __name__ == " _ _ main _ _ " :
    s = "100000101000" ;
    print ( bcdToDecimal ( s ) ) ;

Index/key variables: i
Accumulator variables: check, mul, num, sum
Iterator variables: i
Python program:
def CountSwap ( s , n ) :
    s = list ( s )
    count = 0
    ans = True
    for i in range ( n // 2 ) :
        left = i
        right = n - left - 1
        while left < right :
            if s [ left ] == s [ right ] :
                break
            else :
                right -= 1
        if left == right :
            ans = False
            break
        else :
            for j in range ( right , n - left - 1 ) :
                ( s [ j ] , s [ j + 1 ] ) = ( s [ j + 1 ] , s [ j ] )
                count += 1
    if ans :
        return ( count )
    else :
        return - 1
s = ' geeksfgeeks '
n = len ( s )
ans1 = CountSwap ( s , n )
ans2 = CountSwap ( s [ : : - 1 ] , n )
print ( max ( ans1 , ans2 ) )

Index/key variables: j, left, right
Accumulator variables: count
Iterator variables: i, j
Boolean variables: ans