dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def replaceDuplicates ( names ) :
    hash = { }
    for i in range ( 0 , len ( names ) ) :
        if names [ i ] not in hash :
            hash [ names [ i ] ] = 1
        else :
            count = hash [ names [ i ] ]
            hash [ names [ i ] ] += 1
            names [ i ] += str ( count )
    for i in range ( 0 , len ( names ) ) :
        print ( names [ i ] , end = ' ▁ ' )
if __name__ == ' _ _ main _ _ ' :
    str1 = [ " aa " , " bb " , " cc " , " bb " , " aa " , " aa " , " aa " ]
    replaceDuplicates ( str1 )

Index/key variables: i
Iterator variables: i
Python program:
def convert_to_allzeroes ( st , a , b ) :
    length = len ( st )
    left_1 = 0
    i = 0
    while ( i < length and st [ i ] == '0' ) :
        i += 1
    left_1 = i
    right_1 = 0
    i = length - 1
    while ( i >= 0 and st [ i ] == '0' ) :
        i -= 1
    right_1 = i
    if ( left_1 == length and right_1 == - 1 ) :
        print ( 0 )
        return
    cost = a
    for i in range ( left_1 , right_1 + 1 ) :
        zeroes = 0
        while ( i < length and st [ i ] == '0' ) :
            zeroes += 1
            i += 1
        if ( zeroes ) :
            cost += min ( zeroes * b , a )
    print ( cost )
if __name__ == " _ _ main _ _ " :
    st = "01101110"
    A = 5
    B = 1
    convert_to_allzeroes ( st , A , B )

Index/key variables: i
Accumulator variables: cost, zeroes
Iterator variables: i
Python program:
import sys
def MinDistK ( arr , N , K ) :
    res = sys . maxsize
    dist = 0
    for i in range ( N - K + 1 ) :
        if ( arr [ i ] >= 0 and arr [ i + K - 1 ] >= 0 ) :
            dist = max ( arr [ i ] , arr [ i + K - 1 ] )
        else :
            dist = ( abs ( arr [ i ] ) + abs ( arr [ i + K - 1 ] ) + min ( abs ( arr [ i ] ) , abs ( arr [ i + K - 1 ] ) ) )
        res = min ( res , dist )
    return res
if __name__ == ' _ _ main _ _ ' :
    K = 3
    arr = [ - 30 , - 10 , 10 , 20 , 50 ]
    N = len ( arr )
    print ( MinDistK ( arr , N , K ) )

Index/key variables: i
Iterator variables: i
Python program:
def min ( a , n ) :
    minIndex = 0
    minValue = a [ 0 ]
    for i in range ( 1 , n ) :
        if ( a [ i ] < minValue ) :
            minValue = a [ i ]
            minIndex = i
    return minIndex
def maximizeMin ( A , N , S , M ) :
    minIndex , left , right = 0 , 0 , 0
    for i in range ( M ) :
        minIndex = min ( A , N )
        A [ minIndex ] += 1
        left = minIndex - 1
        right = minIndex + 1
        for j in range ( S - 1 ) :
            if ( left == - 1 ) :
                A [ right ] += 1
                right += 1
            elif ( right == N ) :
                A [ left ] += 1
                left -= 1
            else :
                if ( A [ left ] < A [ right ] ) :
                    A [ left ] += 1
                    left -= 1
                else :
                    A [ right ] += 1
                    right += 1
    minIndex = min ( A , N )
    return A [ minIndex ]
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 4 , 5 , 6 ]
    N = len ( arr )
    S = 2
    M = 3
    print ( maximizeMin ( arr , N , S , M ) )

Index/key variables: i, left, minIndex, right
Iterator variables: i, j
Python program:
from bisect import bisect_left , bisect
def sumOfPathNodes ( N ) :
    if ( N == 1 ) :
        return 1
    elif ( N == 2 or N == 3 ) :
        return N + 1
    arr = [ ]
    arr . append ( 1 )
    k = 1
    flag = True
    while ( k < N ) :
        if ( flag == True ) :
            k *= 2
            flag = False
        else :
            k *= 4
            flag = True
        if ( k > N ) :
            break
        arr . append ( k )
    lenn = len ( arr )
    prefix = [ 0 ] * ( lenn )
    prefix [ 0 ] = 1
    for i in range ( 1 , lenn ) :
        prefix [ i ] = arr [ i ] + prefix [ i - 1 ]
    it = bisect_left ( prefix , N )
    ind = it
    final_ans = 0
    temp = N
    while ( ind > 1 ) :
        val = temp - prefix [ ind - 1 ]
        if ( ind % 2 != 0 ) :
            temp = prefix [ ind - 2 ] + ( val + 1 ) // 2
        else :
            temp = prefix [ ind - 2 ] + ( val + 3 ) // 4
        ind -= 1
        final_ans += temp
    final_ans += ( N + 1 )
    return final_ans
if __name__ == ' _ _ main _ _ ' :
    N = 13
    print ( sumOfPathNodes ( N ) )

Index/key variables: i
Accumulator variables: arr, final_ans, ind, k
Iterator variables: i
Boolean variables: flag
Python program:
from math import sqrt
def checkPointRange ( arr , X , Y , N ) :
    for i in range ( N ) :
        dist = sqrt ( ( arr [ i ] [ 0 ] - X ) * ( arr [ i ] [ 0 ] - X ) + ( arr [ i ] [ 1 ] - Y ) * ( arr [ i ] [ 1 ] - Y ) )
        if ( dist <= arr [ i ] [ 2 ] ) :
            return True
    return False
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 1 , 1 , 3 ] , [ 10 , 10 , 3 ] , [ 15 , 15 , 15 ] ]
    X = 5
    Y = 5
    N = len ( arr )
    if ( checkPointRange ( arr , X , Y , N ) ) :
        print ( " True " )
    else :
        print ( " False " )

Index/key variables: i
Iterator variables: i
Python program:
def findWinner ( arr , N ) :
    odd = 0
    even = 0
    for i in range ( N ) :
        if ( arr [ i ] % 2 == 1 ) :
            odd += 1
        else :
            even += 1
    if ( even == 0 ) :
        if ( odd % 2 == 0 ) :
            print ( " Player ▁ 2" )
        elif ( odd % 2 == 1 ) :
            print ( " Player ▁ 1" )
    elif ( even == 1 and odd % 2 == 1 ) :
        print ( " Player ▁ 1" )
    else :
        print ( - 1 )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 1 , 9 , 7 ]
    N = len ( arr )
    findWinner ( arr , N )

Index/key variables: i
Accumulator variables: even, odd
Iterator variables: i
Python program:
def rearrangeArrMaxcntMinima ( arr , N ) :
    arr . sort ( )
    left = 0
    right = N // 2
    while ( left < N // 2 or right < N ) :
        if ( right < N ) :
            print ( arr [ right ] , end = " ▁ " )
            right += 1
        if ( left < N // 2 ) :
            print ( arr [ left ] , end = " ▁ " )
            left += 1
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 4 , 5 ]
    N = len ( arr )
    rearrangeArrMaxcntMinima ( arr , N )

Index/key variables: left, right
Python program:
MOD = 10 ** 9 + 7
def minJumps ( seats ) :
    position = [ ]
    count = 0
    lenn = len ( seats )
    for i in range ( lenn ) :
        if ( seats [ i ] == ' x ' ) :
            position . append ( i - count )
            count += 1
    if ( count == lenn or count == 0 ) :
        return 0
    med_index = ( count - 1 ) // 2
    med_val = position [ med_index ]
    ans = 0
    for i in range ( len ( position ) ) :
        ans = ( ans % MOD + abs ( position [ i ] - med_val ) % MOD ) % MOD
    return ans % MOD
if __name__ == ' _ _ main _ _ ' :
    S = " . . . . x . . xx . . . x . . "
    print ( minJumps ( S ) )

Index/key variables: i, med_index
Accumulator variables: count, position
Iterator variables: i
Python program:
def singlePrimeFactor ( N ) :
    disPrimeFact = { }
    for i in range ( 2 , N + 1 ) :
        if i * i > N :
            break
        while ( N % i == 0 ) :
            disPrimeFact [ i ] = 1
            N //= i
    if ( N != 1 ) :
        disPrimeFact [ N ] = 1
    if ( len ( disPrimeFact ) == 1 ) :
        return list ( disPrimeFact . keys ( ) ) [ 0 ]
    return - 1
def cntsingleFactorPair ( arr , N ) :
    countOf1 = 0
    mp = { }
    for i in range ( N ) :
        if ( arr [ i ] == 1 ) :
            countOf1 += 1
            continue
        factorValue = singlePrimeFactor ( arr [ i ] )
        if ( factorValue == - 1 ) :
            continue
        else :
            mp [ factorValue ] = mp . get ( factorValue , 0 ) + 1
    res = 0
    for it in mp :
        X = mp [ it ]
        res += countOf1 * X + ( X * ( X - 1 ) ) // 2
    return res
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 4 ]
    N = len ( arr )
    print ( cntsingleFactorPair ( arr , N ) )

Index/key variables: N, factorValue, i, it
Accumulator variables: countOf1, res
Iterator variables: i, it
Python program:
def MincntBothPalin ( str1 , str2 , N ) :
    i = 0
    j = N - 1
    cntOp = 0
    while ( i < j ) :
        if ( str1 [ i ] == str1 [ j ] and str2 [ i ] != str2 [ j ] ) :
            cntOp += 1
        elif ( str1 [ i ] != str1 [ j ] and str2 [ i ] == str2 [ j ] ) :
            cntOp += 1
        elif ( str1 [ i ] != str1 [ j ] and str2 [ i ] != str2 [ j ] ) :
            if ( str1 [ i ] == str2 [ j ] and str2 [ i ] == str1 [ j ] ) :
                cntOp += 1
            else :
                cntOp += 2
        i += 1
        j -= 1
    return cntOp
if __name__ == " _ _ main _ _ " :
    str1 = " dbba "
    str2 = " abcd "
    N = len ( str1 )
    print ( MincntBothPalin ( str1 , str2 , N ) )

Index/key variables: i, j
Accumulator variables: cntOp
Python program:
from bisect import bisect_left , bisect_right
def countPairs ( v1 , v2 , n , m , k ) :
    count = 0
    if ( n <= m ) :
        v1 = sorted ( v1 )
        for j in range ( m ) :
            index = bisect_left ( v1 , v2 [ j ] - k )
            count += index
    else :
        v2 = sorted ( v2 )
        for i in range ( n ) :
            index = bisect_right ( v2 , v1 [ i ] + k )
            count += m - index
    return count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 5 , 9 , 1 , 8 ]
    brr = [ 10 , 12 , 7 , 4 , 2 , 3 ]
    K = 3
    N = len ( arr )
    M = len ( brr )
    print ( countPairs ( arr , brr , N , M , K ) )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
def maxSumSubarr ( A , N , K , X ) :
    sum_K = 0
    for i in range ( 0 , K ) :
        sum_K += A [ i ]
    Max_Sum = 0
    if ( sum_K < X ) :
        Max_Sum = sum_K
    for i in range ( K , N ) :
        sum_K -= ( A [ i - K ] - A [ i ] )
        if ( sum_K < X ) :
            Max_Sum = max ( Max_Sum , sum_K )
    print ( Max_Sum )
arr = [ - 5 , 8 , 7 , 2 , 10 , 1 , 20 , - 4 , 6 , 9 ]
K = 5
X = 30
N = len ( arr )
maxSumSubarr ( arr , N , K , X )

Index/key variables: i
Accumulator variables: sum_K
Iterator variables: i
Python program:
def rearrangeArray ( a , N ) :
    sum = 0
    for i in range ( N ) :
        sum += a [ i ]
    if ( sum == 0 ) :
        print ( " - 1" )
        return
    sum = 0
    b = 0
    a = sorted ( a )
    for i in range ( N ) :
        sum += a [ i ]
        if ( sum == 0 ) :
            if ( a [ i ] != a [ N - 1 ] ) :
                sum -= a [ i ]
                a [ i ] , a [ N - 1 ] = a [ N - 1 ] , a [ i ]
                sum += a [ i ]
            else :
                b = 1
                break
    if ( b == 1 ) :
        b = 0
        sum = 0
        a = sorted ( a )
        a = a [ : : - 1 ]
        for i in range ( N - 1 , - 1 , - 1 ) :
            sum += a [ i ]
            if ( sum == 0 ) :
                if ( a [ i ] != a [ 0 ] ) :
                    sum -= a [ i ]
                    a [ i ] , a [ 0 ] = a [ 0 ] , a [ i ]
                    sum += a [ i ]
                else :
                    b = 1
                    break
    if ( b == 1 ) :
        print ( " - 1" )
        return
    for i in range ( N ) :
        print ( a [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , - 1 , 2 , 4 , 0 ]
    N = len ( arr )
    rearrangeArray ( arr , N )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
import sys
def removeSmallestSubarray ( arr , n , k ) :
    mod_arr = [ 0 ] * n
    total_sum = 0
    for i in range ( n ) :
        mod_arr [ i ] = ( arr [ i ] + k ) % k
        total_sum += arr [ i ]
    target_remainder = total_sum % k
    if ( target_remainder == 0 ) :
        print ( "0" )
        return
    map1 = { }
    map1 [ 0 ] = - 1
    curr_remainder = 0
    res = sys . maxsize
    for i in range ( n ) :
        curr_remainder = ( curr_remainder + arr [ i ] + k ) % k
        map1 [ curr_remainder ] = i
        mod = ( curr_remainder - target_remainder + k ) % k
        if ( mod in map1 . keys ( ) ) :
            res = min ( res , i - map1 [ mod ] )
    if ( res == sys . maxsize or res == n ) :
        res = - 1
    print ( res )
arr = [ 3 , 1 , 4 , 2 ]
N = len ( arr )
K = 6
removeSmallestSubarray ( arr , N , K )

Index/key variables: curr_remainder, i, mod
Accumulator variables: total_sum
Iterator variables: i
Python program:
def toggleQuery ( strr , Q , M ) :
    strr = [ i for i in strr ]
    N = len ( strr )
    prefixCnt = [ 0 ] * ( N + 1 )
    for i in range ( M ) :
        prefixCnt [ Q [ i ] [ 0 ] ] += 1
        prefixCnt [ Q [ i ] [ 1 ] + 1 ] -= 1
    for i in range ( 1 , N + 1 ) :
        prefixCnt [ i ] += prefixCnt [ i - 1 ]
    for i in range ( N ) :
        if ( prefixCnt [ i ] % 2 ) :
            strr [ i ] = ( chr ( ord ( '1' ) - ord ( strr [ i ] ) + ord ( '0' ) ) )
    return " " . join ( strr )
if __name__ == ' _ _ main _ _ ' :
    strr = "101010" ;
    Q = [ [ 0 , 1 ] , [ 2 , 5 ] , [ 2 , 3 ] , [ 1 , 4 ] , [ 0 , 5 ] ]
    M = len ( Q )
    print ( toggleQuery ( strr , Q , M ) )

Index/key variables: i
Iterator variables: i
Python program:
def isValid ( wood , N , len , K ) :
    count = 0
    for i in range ( N ) :
        count += wood [ i ] // len
    return ( count >= K )
def findMaxLen ( wood , N , K ) :
    left = 1
    right = max ( wood )
    while ( left <= right ) :
        mid = left + ( right - left ) // 2
        if ( isValid ( wood , N , mid , K ) ) :
            left = mid + 1
        else :
            right = mid - 1
    return right
if __name__ == ' _ _ main _ _ ' :
    wood = [ 5 , 9 , 7 ]
    N = len ( wood )
    K = 4
    print ( findMaxLen ( wood , N , K ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def countSum ( a , n , sum ) :
    count = 0
    for i in range ( n - 3 ) :
        for j in range ( i + 1 , n - 2 ) :
            for k in range ( j + 1 , n - 1 ) :
                for l in range ( k + 1 , n ) :
                    if ( a [ i ] + a [ j ] + a [ k ] + a [ l ] == sum ) :
                        count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 5 , 3 , 1 , 2 , 4 ]
    S = 13
    N = len ( arr )
    print ( countSum ( arr , N , S ) )

Index/key variables: i, j, k, l
Accumulator variables: count
Iterator variables: i, j, k, l
Python program:
def minSwaps ( S , n ) :
    swaps = 0
    arr = [ [ ] for i in range ( 26 ) ]
    for i in range ( n ) :
        pos = ord ( S [ i ] ) - ord ( ' a ' )
        arr [ pos ] . append ( i )
    for ch in range ( ord ( ' a ' ) , ord ( ' z ' ) + 1 ) :
        pos = ch - ord ( ' a ' )
        for i in range ( 1 , len ( arr [ pos ] ) ) :
            swaps += abs ( arr [ pos ] [ i ] - arr [ pos ] [ i - 1 ] - 1 )
    return swaps
if __name__ == ' _ _ main _ _ ' :
    S = " abbccabbcc "
    N = len ( S )
    print ( minSwaps ( S , N ) )

Index/key variables: i, pos
Accumulator variables: swaps
Iterator variables: ch, i
Python program:
def printConnections ( store , ind , ind1 ) :
    for pr in store :
        print ( pr [ 0 ] , pr [ 1 ] )
    if ( len ( ind ) != 0 ) :
        for x in ind :
            print ( ind1 , x + 1 )
def constructGraph ( arr , N ) :
    ind = [ ]
    store = [ ]
    x = arr [ 0 ]
    count , ind1 = 0 , 0
    for i in range ( 1 , N ) :
        if ( arr [ i ] != x ) :
            ind1 = i + 1
            count += 1
            store . append ( [ 1 , i + 1 ] )
        else :
            ind . append ( i )
    if count == 0 :
        print ( " Not ▁ Possible " )
    else :
        print ( " Possible " )
        printConnections ( store , ind , ind1 )
if __name__ == ' _ _ main _ _ ' :
    N = 5
    arr = [ ' a ' , ' b ' , ' a ' , ' b ' , ' c ' ]
    constructGraph ( arr , N )

Index/key variables: i
Accumulator variables: count, ind, store
Iterator variables: i, pr, x
Python program:
def findMinimumOperations ( a , b ) :
    step = 0
    last_index = 0
    while ( a != b ) :
        a = [ i for i in a ]
        for i in range ( len ( a ) ) :
            if ( a [ i ] != b [ i ] ) :
                last_index = i
        for i in range ( last_index + 1 ) :
            if ( a [ i ] == '0' ) :
                a [ i ] = '1'
            else :
                a [ i ] = '0'
        a = " " . join ( a )
        step += 1
    print ( step )
if __name__ == ' _ _ main _ _ ' :
    A = "101010"
    B = "110011"
    findMinimumOperations ( A , B )

Index/key variables: i
Accumulator variables: step
Iterator variables: i
Python program:
def isValid ( arr , n , m , d ) :
    for i in range ( m ) :
        if ( abs ( arr [ n - m + i ] - arr [ i ] ) < d ) :
            return 0
    return 1
def countPairs ( arr , N , K ) :
    ans = 0
    left = 0
    right = N // 2 + 1
    arr . sort ( reverse = False )
    while ( left < right ) :
        mid = ( left + right ) // 2
        if ( isValid ( arr , N , mid , K ) ) :
            ans = mid
            left = mid + 1
        else :
            right = mid - 1
    print ( ans , end = " " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 3 , 3 , 5 ]
    K = 2
    N = len ( arr )
    countPairs ( arr , N , K )

Index/key variables: i
Iterator variables: i
Python program:
def max_distance ( a , temp , n ) :
    mp = { }
    for i in range ( 1 , n + 1 ) :
        temp [ i ] = - 1
    for i in range ( n ) :
        if ( a [ i ] not in mp ) :
            temp [ a [ i ] ] = i + 1
        else :
            temp [ a [ i ] ] = max ( temp [ a [ i ] ] , i - mp [ a [ i ] ] )
        mp [ a [ i ] ] = i
    for i in range ( 1 , n + 1 ) :
        if ( temp [ i ] != - 1 ) :
            temp [ i ] = max ( temp [ i ] , n - mp [ i ] )
def min_comm_ele ( a , ans , temp , n ) :
    max_distance ( a , temp , n )
    for i in range ( 1 , n + 1 ) :
        ans [ i ] = - 1
    for i in range ( 1 , n + 1 ) :
        if ( ans [ temp [ i ] ] == - 1 ) :
            ans [ temp [ i ] ] = i
    for i in range ( 1 , n + 1 ) :
        if ( i > 1 and ans [ i - 1 ] != - 1 ) :
            if ( ans [ i ] == - 1 ) :
                ans [ i ] = ans [ i - 1 ]
            else :
                ans [ i ] = min ( ans [ i ] , ans [ i - 1 ] )
        print ( ans [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    N = 6
    a = [ 1 , 3 , 4 , 5 , 6 , 7 ]
    temp = [ 0 ] * 100
    ans = [ 0 ] * 100
    min_comm_ele ( a , ans , temp , N )

Index/key variables: i
Iterator variables: i
Python program:
def FindTrip ( arr , N ) :
    for i in range ( 1 , N - 1 ) :
        p = arr [ i - 1 ]
        q = arr [ i ]
        r = arr [ i + 1 ]
        if ( p < q and q > r ) :
            print ( i - 1 , i , i + 1 )
            return
    print ( - 1 )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 1 , 4 , 3 ]
    N = len ( arr )
    FindTrip ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
from collections import defaultdict
def cntSubarrays ( arr , N ) :
    cntSub = 0
    cntUnique = 0
    cntFreq = defaultdict ( lambda : 0 )
    for i in range ( N ) :
        for j in range ( i , N ) :
            cntFreq [ arr [ j ] ] += 1
            if ( cntFreq [ arr [ j ] ] == 1 ) :
                cntUnique += 1
            elif ( cntFreq [ arr [ j ] ] == 2 ) :
                cntUnique -= 1
            if ( cntUnique == 0 ) :
                cntSub += 1
        cntFreq . clear ( )
        cntUnique = 0
    return cntSub
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 1 , 2 , 2 , 2 ]
    N = len ( arr )
    print ( cntSubarrays ( arr , N ) )

Index/key variables: j
Accumulator variables: cntSub, cntUnique
Iterator variables: i, j
Python program:
def checkPalinK ( str , K ) :
    N = len ( str )
    cntFreq = [ 0 ] * 256
    for i in range ( N ) :
        cntFreq [ ord ( str [ i ] ) ] += 1
    cntOddFreq = 0
    for i in range ( 256 ) :
        if ( cntFreq [ i ] % 2 == 1 ) :
            cntOddFreq += 1
    if ( cntOddFreq <= ( K + 1 ) ) :
        return True
    return False
if __name__ == ' _ _ main _ _ ' :
    str = " geeksforgeeks "
    K = 2
    if ( checkPalinK ( str , K ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Accumulator variables: cntOddFreq
Iterator variables: i
Python program:
def countRemovableElem ( arr , N ) :
    hash = [ 0 ] * ( N + 1 )
    mex = N + 1
    for i in range ( 0 , N ) :
        if ( arr [ i ] <= N ) :
            hash [ arr [ i ] ] = 1
    for i in range ( 1 , N + 1 ) :
        if ( hash [ i ] == 0 ) :
            mex = i
            break
    print ( N - ( mex - 1 ) )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 3 , 5 , 1 , 6 ]
    N = len ( arr )
    countRemovableElem ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
def printIndexes ( strr ) :
    N = len ( strr )
    cntFreq = [ 0 ] * 256
    for i in range ( N ) :
        cntFreq [ ord ( strr [ i ] ) ] += 1
    cntLeftFreq = [ 0 ] * 256
    for i in range ( N ) :
        cntLeft = 0
        cntRight = 0
        for j in range ( ord ( strr [ i ] ) - 1 , - 1 , - 1 ) :
            cntLeft += cntLeftFreq [ j ]
            cntRight += ( cntFreq [ j ] - cntLeftFreq [ j ] )
        cntLeftFreq [ ord ( strr [ i ] ) ] += 1
        if ( cntLeft == cntRight and cntLeft != 0 ) :
            print ( i , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    strr = " aabacdabbb "
    printIndexes ( strr )

Index/key variables: i, j
Accumulator variables: cntLeft, cntRight
Iterator variables: i, j
Python program:
def Count_Number ( x ) :
    ans = 0 ;
    if ( x % 99 != 0 ) :
        ans = - 1 ;
    else :
        diff = x / 99 ;
        for i in range ( 1 , 10 ) :
            for j in range ( 1 , 10 ) :
                if ( ( i - j ) == diff ) :
                    ans += 10 ;
    return ans ;
if __name__ == ' _ _ main _ _ ' :
    x = 792 ;
    print ( Count_Number ( x ) ) ;

Accumulator variables: ans
Iterator variables: i, j
Python program:
import sys
INF = sys . maxsize ;
def findMaxPoint ( arr , i , n ) :
    if ( i == n ) :
        return [ INF , INF ]
    flag = True ;
    for j in range ( n ) :
        if ( j == i ) :
            continue ;
        if ( arr [ j ] [ 0 ] >= arr [ i ] [ 0 ] or arr [ j ] [ 1 ] >= arr [ i ] [ 1 ] ) :
            flag = False ;
            break ;
    if ( flag ) :
        return arr [ i ] ;
    return findMaxPoint ( arr , i + 1 , n ) ;
def findMaxPoints ( arr , n ) :
    ans = findMaxPoint ( arr , 0 , n ) ;
    if ( ans [ 0 ] == INF ) :
        print ( - 1 ) ;
    else :
        print ( " ( " , ans [ 0 ] , " ▁ " , ans [ 1 ] , " ) " ) ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 1 , 2 ] , [ 2 , 1 ] , [ 3 , 4 ] , [ 4 , 3 ] , [ 5 , 5 ] ] ;
    N = len ( arr ) ;
    findMaxPoints ( arr , N ) ;

Index/key variables: i, j
Iterator variables: j
Boolean variables: flag
Python program:
import sys ;
def findMaxPoint ( arr ) :
    maxX = - sys . maxsize ;
    maxY = - sys . maxsize ;
    n = len ( arr ) ;
    for i in range ( n ) :
        maxX = max ( maxX , arr [ i ] [ 0 ] ) ;
        maxY = max ( maxY , arr [ i ] [ 1 ] ) ;
    for i in range ( n ) :
        if ( maxX == arr [ i ] [ 0 ] and maxY == arr [ i ] [ 1 ] ) :
            print ( " ( " , maxX , " , ▁ " , maxY , " ) " ) ;
            return ;
    print ( - 1 ) ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 1 , 2 ] , [ 2 , 1 ] , [ 3 , 4 ] , [ 4 , 3 ] , [ 5 , 5 ] ] ;
    findMaxPoint ( arr ) ;

Index/key variables: i
Iterator variables: i
Python program:
def find_index ( arr , n , K ) :
    for i in range ( n ) :
        if arr [ i ] == K :
            return i
        elif arr [ i ] > K :
            return i
    return n
arr = [ 1 , 3 , 5 , 6 ]
n = len ( arr )
K = 2
print ( find_index ( arr , n , K ) )

Index/key variables: i
Iterator variables: i
Python program:
def minSubarray ( arr , N ) :
    m = { }
    for i in range ( N ) :
        mini = 10 ** 9
        for j in range ( i , N ) :
            mini = min ( mini , arr [ j ] )
            m [ mini ] = m . get ( mini , 0 ) + 1
    for i in arr :
        print ( m [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 2 , 1 , 4 ]
    N = len ( arr )
    minSubarray ( arr , N )

Index/key variables: i, j, mini
Iterator variables: i, j