dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def convertToString ( sum ) :
    str1 = " "
    while ( sum ) :
        str1 = str1 + chr ( ( sum % 10 ) + ord ( '0' ) )
        sum = sum // 10
    return str1
def GetIndividulaDigitSum ( str1 , len1 ) :
    sum = 0
    for i in range ( len1 ) :
        sum = sum + ord ( str1 [ i ] ) - ord ( '0' )
    return convertToString ( sum )
def GetDigitalRoot ( str1 ) :
    if ( len ( str1 ) == 1 ) :
        return ord ( str1 [ 0 ] ) - ord ( '0' )
    str1 = GetIndividulaDigitSum ( str1 , len ( str1 ) )
    return GetDigitalRoot ( str1 )
if __name__ == ' _ _ main _ _ ' :
    str1 = "675987890789756545689070986776987"
    print ( GetDigitalRoot ( str1 ) )

Index/key variables: i
Iterator variables: i
Python program:
def count ( str1 , str2 ) :
    c = 0 ; j = 0 ;
    for i in range ( len ( str1 ) ) :
        if str1 [ i ] in str2 :
            c += 1 ;
        j += 1 ;
    print ( " No . ▁ of ▁ matching ▁ characters ▁ are : ▁ " , c ) ;
if __name__ == " _ _ main _ _ " :
    str1 = " aabcddekll12 @ " ;
    str2 = " bb2211@55k " ;
    count ( str1 , str2 ) ;

Index/key variables: i
Accumulator variables: c, j
Iterator variables: i
Python program:
def countOfLetters ( string ) :
    letter = 0 ;
    for i in range ( len ( string ) ) :
        if ( ( string [ i ] >= ' A ' and string [ i ] <= ' Z ' ) or ( string [ i ] >= ' a ' and string [ i ] <= ' z ' ) ) :
            letter += 1 ;
    return letter ;
def countOfNumbers ( string ) :
    number = 0 ;
    for i in range ( len ( string ) ) :
        if ( string [ i ] >= '0' and string [ i ] <= '9' ) :
            number += 1 ;
    return number ;
def check ( string ) :
    if ( countOfLetters ( string ) == countOfNumbers ( string ) ) :
        print ( " Yes " ) ;
    else :
        print ( " No " ) ;
if __name__ == " _ _ main _ _ " :
    string = " GeeKs01324" ;
    check ( string ) ;

Index/key variables: i
Accumulator variables: letter, number
Iterator variables: i
Python program:
def twoColorUtil ( G , src , N , colorArr ) :
    colorArr [ src ] = 1
    q = [ src ]
    while len ( q ) > 0 :
        u = q . pop ( 0 )
        for v in range ( 0 , len ( G [ u ] ) ) :
            if colorArr [ G [ u ] [ v ] ] == - 1 :
                colorArr [ G [ u ] [ v ] ] = 1 - colorArr [ u ]
                q . append ( G [ u ] [ v ] )
            elif colorArr [ G [ u ] [ v ] ] == colorArr [ u ] :
                return False
    return True
def twoColor ( G , N ) :
    colorArr = [ - 1 ] * N
    for i in range ( N ) :
        if colorArr [ i ] == - 1 :
            if twoColorUtil ( G , i , N , colorArr ) == False :
                return False
            return True
def isOddSum ( info , n , m ) :
    G = [ [ ] for i in range ( 2 * n ) ]
    pseudo , pseudo_count = n + 1 , 0
    for i in range ( 0 , m ) :
        if info [ i ] [ 2 ] % 2 == 1 :
            u , v = info [ i ] [ 0 ] , info [ i ] [ 1 ]
            G [ u ] . append ( v )
            G [ v ] . append ( u )
        else :
            u , v = info [ i ] [ 0 ] , info [ i ] [ 1 ]
            G [ u ] . append ( pseudo )
            G [ pseudo ] . append ( u )
            G [ v ] . append ( pseudo )
            G [ pseudo ] . append ( v )
            pseudo_count += 1
            pseudo += 1
    return twoColor ( G , n + pseudo_count )
if __name__ == " _ _ main _ _ " :
    n , m = 4 , 3
    info = [ [ 1 , 2 , 12 ] , [ 2 , 3 , 1 ] , [ 4 , 3 , 1 ] , [ 4 , 1 , 20 ] ]
    if isOddSum ( info , n , m ) == True :
        print ( " No " )
    else :
        print ( " Yes " )

Index/key variables: i, pseudo, src, u, v
Accumulator variables: pseudo_count, q
Iterator variables: i, v
Python program:
import numpy as np
MAX = 26 ;
def performQueries ( string , q , type_arr , ch , freq ) :
    n = len ( string ) ;
    L = np . zeros ( ( MAX , n ) ) ;
    F = np . zeros ( ( MAX , n ) ) ;
    cnt = [ 0 ] * MAX ;
    for i in range ( n ) :
        k = ord ( string [ i ] ) - ord ( ' a ' ) ;
        cnt [ k ] += 1 ;
        for j in range ( MAX ) :
            if ( k == j ) :
                L [ j ] [ cnt [ j ] ] = i ;
                F [ j ] [ cnt [ j ] ] = i ;
            else :
                L [ j ] [ cnt [ j ] ] = L [ j ] [ cnt [ j ] ] + 1 ;
    for i in range ( q ) :
        if ( type_arr [ i ] == 1 ) :
            print ( L [ ord ( ch [ i ] ) - ord ( ' a ' ) ] [ freq [ i ] ] , end = " " ) ;
        else :
            print ( F [ ord ( ch [ i ] ) - ord ( ' a ' ) ] [ freq [ i ] ] , end = " " ) ;
        print ( )
if __name__ == " _ _ main _ _ " :
    string = " geeksforgeeks " ;
    type_arr = [ 1 , 2 ] ;
    ch = [ ' e ' , ' k ' ] ;
    freq = [ 2 , 2 ] ;
    q = len ( type_arr ) ;
    performQueries ( string , q , type_arr , ch , freq ) ;

Index/key variables: i, j, k
Iterator variables: i, j
Python program:
def anagram_pairs ( s , n ) :
    mp = dict ( )
    for i in range ( n ) :
        temp_str = " " . join ( sorted ( s [ i ] ) )
        if temp_str in mp :
            mp [ temp_str ] += 1
        else :
            mp [ temp_str ] = 1
    ans = 0
    for k in mp . values ( ) :
        ans += ( k * ( k - 1 ) ) // 2
    return ans
if __name__ == " _ _ main _ _ " :
    s = [ " aaab " , " aaba " , " baaa " , " cde " , " dec " ]
    n = len ( s )
    print ( anagram_pairs ( s , n ) )

Index/key variables: i, temp_str
Accumulator variables: ans
Iterator variables: i, k
Python program:
def insert ( arr : list , n : int , k : int ) -> chr :
    ind = 0
    sz = 0
    s = " "
    ch = arr [ 0 ]
    s += ch
    sz = 1
    ind = 0
    for i in range ( 1 , n ) :
        ch = arr [ i ]
        s1 = s [ 0 : ind + 1 ]
        temp = k % sz
        ro = temp - min ( temp , sz - ind - 1 )
        if ro == 0 :
            s2 = s [ ind + 1 : ind + 1 + temp ]
            s3 = s [ ind + temp + 1 : sz ]
            s = s1 + s2 + ch + s3
            ind = len ( s1 ) + len ( s2 )
            sz = len ( s )
        else :
            s2 = s [ : ro ]
            s3 = s [ ro : sz ]
            s = s2 + ch + s3
            ind = len ( s2 )
            sz = len ( s )
    if ind == 0 :
        return s [ sz - 1 ]
    else :
        return s [ ind - 1 ]
if __name__ == " _ _ main _ _ " :
    arr = [ '1' , '2' , '3' , '4' , '5' ]
    k = 2
    n = len ( arr )
    print ( insert ( arr , n , k ) )

Index/key variables: i
Iterator variables: i
Python program:
N = 100005
ans = [ 0 ] * N ;
def Rearrange ( s , n ) :
    sieve = [ 1 ] * ( N + 1 ) ;
    sz = 0 ;
    for i in range ( 2 , n // 2 + 1 ) :
        if ( sieve [ i ] ) :
            for j in range ( 1 , n // i + 1 ) :
                if ( sieve [ i * j ] ) :
                    sz += 1 ;
                sieve [ i * j ] = 0 ;
    m = dict . fromkeys ( s , 0 ) ;
    for it in s :
        m [ it ] += 1 ;
    v = [ ] ;
    for key , value in m . items ( ) :
        v . append ( [ value , key ] ) ;
    v . sort ( ) ;
    if ( v [ - 1 ] [ 0 ] < sz ) :
        print ( - 1 , end = " " ) ;
        return ;
    for i in range ( 2 , n + 1 ) :
        if ( not sieve [ i ] ) :
            ans [ i ] = v [ - 1 ] [ 1 ] ;
    idx = 0 ;
    for i in range ( 1 , n + 1 ) :
        if ( sieve [ i ] ) :
            ans [ i ] = v [ idx ] [ 1 ] ;
            v [ idx ] [ 0 ] -= 1 ;
            if ( v [ idx ] [ 0 ] == 0 ) :
                idx += 1 ;
        print ( ans [ i ] , end = " " ) ;
if __name__ == " _ _ main _ _ " :
    string = " aabaaaa " ;
    n = len ( string ) ;
    Rearrange ( string , n ) ;

Index/key variables: i, idx, it
Accumulator variables: sz, v
Iterator variables: i, it, j, key, value
Python program:
def isCycleRec ( v , adj , visited , recur ) :
    visited [ v ] = True
    recur [ v ] = True
    for i in range ( len ( adj [ v ] ) ) :
        if ( visited [ adj [ v ] [ i ] ] == False ) :
            if ( isCycleRec ( adj [ v ] [ i ] , adj , visited , recur ) ) :
                return True
        elif ( visited [ adj [ v ] [ i ] ] == True and recur [ adj [ v ] [ i ] ] == True ) :
            return True
    recur [ v ] = False
    return False
def isCycle ( arr , n ) :
    adj = [ [ ] for i in range ( n ) ]
    for i in range ( n ) :
        if ( i != ( i + arr [ i ] + n ) % n ) :
            adj [ i ] . append ( ( i + arr [ i ] + n ) % n )
    visited = [ False ] * n
    recur = [ False ] * n
    for i in range ( n ) :
        if ( visited [ i ] == False ) :
            if ( isCycleRec ( i , adj , visited , recur ) ) :
                return True
    return True
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , - 1 , 1 , 2 , 2 ]
    n = len ( arr )
    if ( isCycle ( arr , n ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i, v
Iterator variables: i
Python program:
MAX = 256
freq = [ [ 0 for i in range ( 256 ) ] for j in range ( 1000 ) ]
def preCalculate ( string , n ) :
    freq [ ord ( string [ 0 ] ) ] [ 0 ] = 1
    for i in range ( 1 , n ) :
        ch = string [ i ]
        for j in range ( MAX ) :
            charToUpdate = chr ( j )
            if charToUpdate == ch :
                freq [ j ] [ i ] = freq [ j ] [ i - 1 ] + 1
            else :
                freq [ j ] [ i ] = freq [ j ] [ i - 1 ]
def getFrequency ( ch , l , r ) :
    if l == 0 :
        return freq [ ord ( ch ) ] [ r ]
    else :
        return ( freq [ ord ( ch ) ] [ r ] - freq [ ord ( ch ) ] [ l - 1 ] )
def lastNonRepeating ( string , n , l , r ) :
    for i in range ( r , l - 1 , - 1 ) :
        ch = string [ i ]
        if getFrequency ( ch , l , r ) == 1 :
            return ch
    return " - 1"
if __name__ == " _ _ main _ _ " :
    string = " GeeksForGeeks "
    n = len ( string )
    queries = [ ( 2 , 9 ) , ( 2 , 3 ) , ( 0 , 12 ) ]
    q = len ( queries )
    preCalculate ( string , n )
    for i in range ( q ) :
        print ( lastNonRepeating ( string , n , queries [ i ] [ 0 ] , queries [ i ] [ 1 ] ) )

Index/key variables: i, j, r
Iterator variables: i, j
Python program:
def pre_process ( substrings , s ) :
    n = len ( s ) ;
    for i in range ( n ) :
        dup = " " ;
        for j in range ( i , n ) :
            dup += s [ j ] ;
            substrings . append ( dup ) ;
    substrings . sort ( ) ;
    return substrings ;
if __name__ == " _ _ main _ _ " :
    s = " geek " ;
    substrings = [ ] ;
    substrings = pre_process ( substrings , s ) ;
    queries = [ 1 , 5 , 10 ] ;
    q = len ( queries ) ;
    for i in range ( q ) :
        print ( substrings [ queries [ i ] - 1 ] ) ;

Index/key variables: i, j
Accumulator variables: dup, substrings
Iterator variables: i, j
Python program:
def minCost ( str1 , K ) :
    n = len ( str1 )
    res = 999999999
    count = 0
    cnt = [ 0 for i in range ( 27 ) ]
    for i in range ( n ) :
        cnt [ ord ( str1 [ i ] ) - ord ( ' a ' ) + 1 ] += 1
    for i in range ( 1 , 26 - K + 1 , 1 ) :
        a = i
        b = i + K
        count = 0
        for j in range ( 1 , 27 , 1 ) :
            if ( cnt [ j ] > 0 ) :
                if ( j >= a and j >= b ) :
                    count = count + ( min ( j - b , 25 - j + a + 1 ) ) * cnt [ j ]
                elif ( j <= a and j <= b ) :
                    count = count + ( min ( a - j , 25 + j - b + 1 ) ) * cnt [ j ]
        res = min ( res , count )
    for i in range ( 26 - K + 1 , 27 , 1 ) :
        a = i
        b = ( i + K ) % 26
        count = 0
        for j in range ( 1 , 27 , 1 ) :
            if ( cnt [ j ] > 0 ) :
                if ( j >= b and j <= a ) :
                    count = count + ( min ( j - b , a - j ) ) * cnt [ j ]
        res = min ( res , count )
    return res
if __name__ == ' _ _ main _ _ ' :
    str1 = " abcdefghi "
    K = 2
    print ( minCost ( str1 , K ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def printBinStr ( string , length ) :
    for i in range ( 0 , length ) :
        print ( string [ i ] , end = " " )
    print ( )
def generateBinStr ( string , length , currlen , occur , nextbit ) :
    if currlen == length :
        if occur == 2 and nextbit == 0 :
            printBinStr ( string , length )
        return
    if currlen == 0 :
        string [ 0 ] = nextbit
        generateBinStr ( string , length , currlen + 1 , occur , 0 )
        generateBinStr ( string , length , currlen + 1 , occur , 1 )
    else :
        if occur < 2 :
            string [ currlen ] = nextbit
            if string [ currlen - 1 ] == 0 and nextbit == 1 :
                occur += 1
            generateBinStr ( string , length , currlen + 1 , occur , 0 )
            generateBinStr ( string , length , currlen + 1 , occur , 1 )
        else :
            if string [ currlen - 1 ] == 0 and nextbit == 1 :
                return
            else :
                string [ currlen ] = nextbit
                generateBinStr ( string , length , currlen + 1 , occur , 0 )
                generateBinStr ( string , length , currlen + 1 , occur , 1 )
if __name__ == " _ _ main _ _ " :
    n = 5
    if n < 4 :
        print ( - 1 )
    else :
        string = [ None ] * n
        generateBinStr ( string , n , 0 , 0 , 0 )
        generateBinStr ( string , n , 0 , 0 , 1 )

Index/key variables: currlen, i
Iterator variables: i
Python program:
def printLastChar ( string ) :
    string = string + " ▁ "
    for i in range ( len ( string ) ) :
        if string [ i ] == ' ▁ ' :
            print ( string [ i - 1 ] , end = " ▁ " )
string = " Geeks ▁ for ▁ Geeks "
printLastChar ( string )

Index/key variables: i
Iterator variables: i
Python program:
def strBitwiseOR ( arr , n ) :
    res = " "
    max_size = - ( 2 ** 32 )
    for i in range ( n ) :
        max_size = max ( max_size , len ( arr [ i ] ) )
        arr [ i ] = arr [ i ] [ : : - 1 ]
    for i in range ( n ) :
        s = " "
        for j in range ( max_size - len ( arr [ i ] ) ) :
            s += '0'
        arr [ i ] = arr [ i ] + s
    for i in range ( max_size ) :
        curr_bit = 0
        for j in range ( n ) :
            curr_bit = curr_bit | ord ( arr [ j ] [ i ] )
        res += chr ( curr_bit )
    res = res [ : : - 1 ]
    return res
arr = [ "10" , "11" , "1000001" ]
n = len ( arr )
print ( strBitwiseOR ( arr , n ) )

Index/key variables: i, j
Accumulator variables: res, s
Iterator variables: i, j
Python program:
def findCost ( s1 , s2 , a , b , c , d , n ) :
    cost = 0
    for i in range ( n ) :
        if ( s1 [ i ] == s2 [ i ] ) :
            continue
        else :
            if ( ( s1 [ i ] == '1' and s2 [ i ] == '2' ) or ( s2 [ i ] == '1' and s1 [ i ] == '2' ) ) :
                cost += min ( d , min ( a , b + c ) )
            elif ( ( s1 [ i ] == '2' and s2 [ i ] == '3' ) or ( s2 [ i ] == '2' and s1 [ i ] == '3' ) ) :
                cost += min ( d , min ( b , a + c ) )
            elif ( ( s1 [ i ] == '1' and s2 [ i ] == '3' ) or ( s2 [ i ] == '1' and s1 [ i ] == '3' ) ) :
                cost += min ( d , min ( c , a + b ) )
    return cost
if __name__ == ' _ _ main _ _ ' :
    s1 = "121"
    s2 = "223"
    a = 2
    b = 3
    c = 4
    d = 10
    n = len ( s1 )
    print ( findCost ( s1 , s2 , a , b , c , d , n ) )

Index/key variables: i
Accumulator variables: cost
Iterator variables: i
Python program:
def check ( s , k ) :
    for i in range ( 0 , len ( s ) ) :
        if ( s [ i ] != s [ i % k ] ) :
            return False
    return True
def countCommonDivisors ( a , b ) :
    ct = 0
    n = len ( a )
    m = len ( b )
    for i in range ( 1 , min ( n , m ) + 1 ) :
        if ( n % i == 0 and m % i == 0 ) :
            if ( a [ 0 : i ] == b [ 0 : i ] ) :
                if ( check ( a , i ) and check ( b , i ) ) :
                    ct = ct + 1
    return ct
a = " xaxa "
b = " xaxaxaxa "
print ( countCommonDivisors ( a , b ) )

Index/key variables: i
Iterator variables: i
Python program:
def nextZero ( i , occurrences ) :
    while i < 26 :
        if occurrences [ i ] == 0 :
            return i
        i += 1
    return - 1
def getModifiedString ( str ) :
    n = len ( str )
    if n > 26 :
        return " - 1"
    ch = str
    ch = list ( ch )
    occurrences = [ 0 ] * 26
    for i in range ( n ) :
        occurrences [ ord ( ch [ i ] ) - ord ( ' a ' ) ] += 1
    index = nextZero ( 0 , occurrences )
    for i in range ( n ) :
        if occurrences [ ord ( ch [ i ] ) - ord ( ' a ' ) ] > 1 :
            occurrences [ ord ( ch [ i ] ) - ord ( ' a ' ) ] -= 1
            ch [ i ] = chr ( ord ( ' a ' ) + index )
            occurrences [ index ] = 1
            index = nextZero ( index + 1 , occurrences )
    ch = ' ' . join ( ch )
    print ( ch )
if __name__ == " _ _ main _ _ " :
    str = " geeksforgeeks "
    getModifiedString ( str )

Index/key variables: i, index
Iterator variables: i
Python program:
def subStringsStartingHere ( string , n , startIndex ) :
    count = 0
    i = startIndex + 1
    while ( i <= n ) :
        if string . startswith ( string [ startIndex : i ] ) :
            count += 1
        else :
            break
        i += 1
    return count
def countSubStrings ( string , n ) :
    count = 0
    for i in range ( n ) :
        if string [ i ] == string [ 0 ] :
            count += subStringsStartingHere ( string , n , i )
    return count
if __name__ == " _ _ main _ _ " :
    string = " ababc "
    n = len ( string )
    print ( countSubStrings ( string , n ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def binarySearch ( arr , x ) :
    l = 0
    r = len ( arr )
    while ( l <= r ) :
        m = l + ( ( r - l ) // 2 )
        res = ( x == arr [ m ] )
        if ( res == 0 ) :
            return m - 1
        if ( res > 0 ) :
            l = m + 1
        else :
            r = m - 1
    return - 1
if __name__ == " _ _ main _ _ " :
    arr = [ " contribute " , " geeks " , " ide " , " practice " ] ;
    x = " ide "
    result = binarySearch ( arr , x )
    if ( result == - 1 ) :
        print ( " Element ▁ not ▁ present " )
    else :
        print ( " Element ▁ found ▁ at ▁ index " , result )

Index/key variables: m
Python program:
from math import sqrt
max_val = 257
def PrimeCharacters ( s ) :
    prime = [ True ] * ( max_val + 1 )
    prime [ 0 ] = False
    prime [ 1 ] = False
    for p in range ( 2 , int ( sqrt ( max_val ) ) + 1 ) :
        if ( prime [ p ] == True ) :
            for i in range ( 2 * p , max_val + 1 , p ) :
                prime [ i ] = False
    count = 0
    for i in range ( len ( s ) ) :
        if ( prime [ ord ( s [ i ] ) ] ) :
            count += 1
    return count
if __name__ == " _ _ main _ _ " :
    S = " geeksforgeeks " ;
    print ( PrimeCharacters ( S ) )

Index/key variables: i, p
Accumulator variables: count
Iterator variables: i, p
Python program:
def getStudentsList ( file ) :
    maxAvgScore = 0
    names = [ ]
    for i in range ( 0 , len ( file ) , 4 ) :
        avgScore = ( int ( file [ i + 1 ] ) + int ( file [ i + 2 ] ) + int ( file [ i + 3 ] ) ) // 3
        if avgScore > maxAvgScore :
            maxAvgScore = avgScore
            names . clear ( )
            names . append ( file [ i ] )
        elif avgScore == maxAvgScore :
            names . add ( file [ i ] )
    for i in range ( len ( names ) ) :
        print ( names [ i ] , end = " ▁ " )
    print ( maxAvgScore )
if __name__ == " _ _ main _ _ " :
    file = [ " Shrikanth " , "20" , "30" , "10" , " Ram " , "100" , "50" , "10" ]
    getStudentsList ( file )

Index/key variables: i
Accumulator variables: names
Iterator variables: i
Python program:
ALL_CHARS = 256
def compare ( arr1 , arr2 ) :
    for i in range ( ALL_CHARS ) :
        if arr1 [ i ] != arr2 [ i ] :
            return False
    return True
def search ( pat , txt ) :
    M = len ( pat )
    N = len ( txt )
    countP = [ 0 ] * ALL_CHARS
    countTW = [ 0 ] * ALL_CHARS
    for i in range ( M ) :
        countP [ ord ( pat [ i ] ) ] += 1
        countTW [ ord ( txt [ i ] ) ] += 1
    for i in range ( M , N ) :
        if compare ( countP , countTW ) :
            return True
        countTW [ ord ( txt [ i ] ) ] += 1
        countTW [ ord ( txt [ i - M ] ) ] -= 1
    if compare ( countP , countTW ) :
        return True
    return False
def calculateSubString ( s1 , s2 , n ) :
    count , j , x = 0 , 0 , 0
    for i in range ( n ) :
        for length in range ( 1 , n - i + 1 ) :
            if search ( s1 [ i : i + length ] , s2 ) :
                count += 1
    return count
if __name__ == " _ _ main _ _ " :
    str1 = " PLEASEHELPIMTRAPPED "
    str2 = " INAKICKSTARTFACTORY "
    length = len ( str1 )
    print ( calculateSubString ( str1 , str2 , length ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i, length
Python program:
def strScore ( str , s , n ) :
    score = 0
    index = 0
    for i in range ( n ) :
        if ( str [ i ] == s ) :
            for j in range ( len ( s ) ) :
                score += ( ord ( s [ j ] ) - ord ( ' a ' ) + 1 )
            index = i + 1
            break
    score = score * index
    return score
str = [ " sahil " , " shashanak " , " sanjit " , " abhinav " , " mohit " ]
s = " abhinav "
n = len ( str )
score = strScore ( str , s , n ) ;
print ( score )

Index/key variables: i, j
Accumulator variables: score
Iterator variables: i, j
Python program:
from sys import maxsize
def sameCharAdj ( string ) :
    n = len ( string )
    st = set ( )
    st . add ( string [ 0 ] )
    for i in range ( 1 , n ) :
        if string [ i ] == string [ i - 1 ] :
            continue
        if string [ i ] in st :
            return False
        st . add ( string [ i ] )
    return True
def minSwaps ( string , l , r , cnt , minm ) :
    if l == r :
        if sameCharAdj ( string ) :
            return cnt
        else :
            return maxsize
    for i in range ( l + 1 , r + 1 , 1 ) :
        string [ i ] , string [ l ] = string [ l ] , string [ i ]
        cnt += 1
        x = minSwaps ( string , l + 1 , r , cnt , minm )
        string [ i ] , string [ l ] = string [ l ] , string [ i ]
        cnt -= 1
        y = minSwaps ( string , l + 1 , r , cnt , minm )
        minm = min ( minm , min ( x , y ) )
    return minm
if __name__ == " _ _ main _ _ " :
    string = " abbaacb "
    string = list ( string )
    n = len ( string )
    cnt = 0
    minm = maxsize
    print ( minSwaps ( string , 0 , n - 1 , cnt , minm ) )

Index/key variables: i, l
Accumulator variables: cnt, st
Iterator variables: i
Python program:
def find ( parent , i ) :
    if ( parent [ i ] == - 1 ) :
        return i
    return find ( parent , parent [ i ] )
def Union ( parent , x , y ) :
    xset = find ( parent , x )
    yset = find ( parent , y )
    parent [ xset ] = yset

Index/key variables: i, xset
Python program:
def minParentheses ( p ) :
    bal = 0
    ans = 0
    for i in range ( 0 , len ( p ) ) :
        if ( p [ i ] == ' ( ' ) :
            bal += 1
        else :
            bal += - 1
        if ( bal == - 1 ) :
            ans += 1
            bal += 1
    return bal + ans
if __name__ == ' _ _ main _ _ ' :
    p = " ( ) ) "
    print ( minParentheses ( p ) )

Index/key variables: i
Accumulator variables: ans, bal
Iterator variables: i
Python program:
def isPalindrome ( r ) :
    p = r [ : : - 1 ]
    return r == p
def CheckStr ( s ) :
    l = len ( s )
    i = 0
    for i in range ( 2 , l + 1 ) :
        if isPalindrome ( s [ 0 : i ] ) == True :
            break
    if i == ( l + 1 ) :
        return False
    for i in range ( 2 , l + 1 ) :
        if isPalindrome ( s [ l - i : l ] ) == True :
            return True
    return False
if __name__ == " _ _ main _ _ " :
    s = " abccbarfgdbd "
    if CheckStr ( s ) == True :
        print ( " YES " )
    else :
        print ( " NO " )

Iterator variables: i
Python program:
def oddEquivalent ( s , n ) :
    count = 0
    for i in range ( 0 , n ) :
        if ( s [ i ] == '1' ) :
            count = count + 1
    return count
if __name__ == ' _ _ main _ _ ' :
    s = "1011011"
    n = len ( s )
    print ( oddEquivalent ( s , n ) )

Index/key variables: i
Iterator variables: i