dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
ans = 0
adj = [ [ ] for i in range ( 10 ** 5 + 1 ) ]
def dfsUtil ( u , par , depth ) :
    global adj , ans
    for it in adj [ u ] :
        if ( it != par ) :
            dfsUtil ( it , u , depth + 1 )
    ans += depth
def dfs ( u , par , depth ) :
    global ans
    dfsUtil ( u , par , depth )
    print ( ans )
def countPairs ( edges ) :
    global adj
    for i in range ( len ( edges ) ) :
        u = edges [ i ] [ 0 ]
        v = edges [ i ] [ 1 ]
        adj [ u ] . append ( v )
        adj [ v ] . append ( u )
    dfs ( 1 , 1 , 1 )
if __name__ == ' _ _ main _ _ ' :
    edges = [ [ 1 , 2 ] , [ 1 , 3 ] , [ 2 , 4 ] ]
    countPairs ( edges )

Index/key variables: i, u, v
Iterator variables: i, it
Python program:
v = [ - 1 ] * ( 1000000 )
def power_value ( val ) :
    if ( val == 1 ) :
        return 0
    if ( val % 2 == 0 ) :
        v [ val ] = power_value ( val // 2 ) + 1
        return v [ val ]
    else :
        temp = val * 3
        temp += 1
        v [ val ] = power_value ( temp ) + 1
        return v [ val ]
def getKthNumber ( l , r , k ) :
    ans = [ ]
    for i in range ( l , r + 1 ) :
        if ( v [ i ] == - 1 ) :
            power_value ( i )
    j = 0
    for i in range ( l , r + 1 ) :
        ans . append ( [ v [ i ] , i ] )
        j += 1
    ans = sorted ( ans )
    print ( ans [ k - 1 ] [ 1 ] )
if __name__ == ' _ _ main _ _ ' :
    L , R , K = 7 , 10 , 4
    getKthNumber ( L , R , K )

Index/key variables: i, val
Accumulator variables: ans, j
Iterator variables: i
Python program:
class TreeNode :
    def __init__ ( self , val = 0 , left = None , right = None ) :
        self . val = val
        self . left = left
        self . right = right
def convertBinaryToDecimal ( arr ) :
    ans = 0
    for i in arr :
        ans = ( ans << 1 ) | i
    return ans
def decimalEquilvalentAtEachLevel ( root ) :
    ans = 0
    que = [ root ]
    while True :
        length = len ( que )
        if not length :
            break
        eachLvl = [ ]
        while length :
            temp = que . pop ( 0 )
            eachLvl . append ( temp . val )
            if temp . left :
                que . append ( temp . left )
            if temp . right :
                que . append ( temp . right )
            length -= 1
        ans += convertBinaryToDecimal ( eachLvl )
    print ( ans )
root = TreeNode ( 0 )
root . left = TreeNode ( 1 )
root . right = TreeNode ( 0 )
root . left . left = TreeNode ( 0 )
root . left . right = TreeNode ( 1 )
root . right . left = TreeNode ( 1 )
root . right . right = TreeNode ( 1 )
decimalEquilvalentAtEachLevel ( root )

Accumulator variables: ans, eachLvl, length, que
Iterator variables: i
Class/struct names: TreeNode
Python program:
def minimumOperations ( arr , N ) :
    oddCnt = 0
    evenCnt = 0
    for i in range ( N ) :
        if ( arr [ i ] % 2 == 0 ) :
            evenCnt += 1
        else :
            oddCnt += 1
    print ( min ( oddCnt , evenCnt ) )
arr = [ 4 , 1 , 2 ]
N = len ( arr )
minimumOperations ( arr , N )

Index/key variables: i
Accumulator variables: evenCnt, oddCnt
Iterator variables: i
Python program:
def minIncr ( arr ) :
    forEven = 0
    for i in range ( len ( arr ) ) :
        if i % 2 :
            if not arr [ i ] % 2 :
                forEven += 1
        else :
            if arr [ i ] % 2 :
                forEven += 1
    return min ( forEven , len ( arr ) - forEven )
arr = [ 1 , 4 , 6 , 8 , 9 , 5 ]
print ( minIncr ( arr ) )

Index/key variables: i
Accumulator variables: forEven
Iterator variables: i
Python program:
def minOperations ( arr , N , Q , M ) :
    m1 = { }
    m2 = { }
    front = 0
    rear = 0
    for i in range ( N ) :
        front += arr [ i ]
        m1 [ arr [ i ] ] = front
    for i in range ( N - 1 , - 1 , - 1 ) :
        rear += arr [ i ]
        m2 [ arr [ i ] ] = rear
    for i in range ( M ) :
        print ( min ( m1 [ Q [ i ] ] , m2 [ Q [ i ] ] ) , end = " ▁ " )
arr = [ 2 , 3 , 6 , 7 , 4 , 5 , 1 ]
N = len ( arr )
Q = [ 7 , 6 ]
M = len ( Q )
minOperations ( arr , N , Q , M )

Index/key variables: i
Accumulator variables: front, rear
Iterator variables: i
Python program:
def checkAnagram ( s1 , s2 ) :
    s2hash = [ 0 for i in range ( 26 ) ]
    s1hash = [ 0 for i in range ( 26 ) ]
    s1len = len ( s1 )
    s2len = len ( s2 )
    if ( s1len > s2len ) :
        return False
    left = 0
    right = 0
    while ( right < s1len ) :
        s1hash [ ord ( s1 [ right ] ) - 97 ] += 1
        s2hash [ ord ( s2 [ right ] ) - 97 ] += 1
        right += 1
    right -= 1
    while ( right < s2len ) :
        if ( s1hash == s2hash ) :
            return True
        right += 1
        if ( right != s2len ) :
            s2hash [ ord ( s2 [ right ] ) - 97 ] += 1
        s2hash [ ord ( s2 [ left ] ) - 97 ] -= 1
        left += 1
    return False
if __name__ == ' _ _ main _ _ ' :
    s1 = " ab "
    s2 = " bbpobac "
    if ( checkAnagram ( s1 , s2 ) ) :
        print ( " YES " )
    else :
        print ( " No " )

Index/key variables: left, right
Python program:
def findMaxIntervals ( v , n ) :
    maxi = 0
    for i in range ( n ) :
        c = n
        for j in range ( n ) :
            if ( v [ i ] [ 1 ] < v [ j ] [ 0 ] or v [ i ] [ 0 ] > v [ j ] [ 1 ] ) :
                c -= 1
        maxi = max ( c , maxi )
    print ( maxi )
arr = [ ]
arr . append ( ( 1 , 2 ) )
arr . append ( ( 3 , 4 ) )
arr . append ( ( 2 , 5 ) )
N = len ( arr )
findMaxIntervals ( arr , N )

Index/key variables: i, j
Accumulator variables: c
Iterator variables: i, j
Python program:
def check ( a , n ) :
    flag = 0
    for i in range ( 1 , n - 1 ) :
        if ( a [ i + 1 ] > a [ i ] and a [ i ] < a [ i - 1 ] ) :
            flag = 1
    if ( flag != 0 ) :
        return False
    else :
        return True
arr = [ 1 , 3 , 5 , 2 ]
N = len ( arr )
if ( check ( arr , N ) != 0 ) :
    print ( " YES " )
else :
    print ( " NO " )

Index/key variables: i
Iterator variables: i
Python program:
def smallestNumber ( arr , lenn ) :
    maxi = 0
    for i in range ( lenn ) :
        maxi = max ( maxi , arr [ i ] )
    ans = - 1
    for i in range ( 2 , maxi + 2 ) :
        flag = True
        for j in range ( lenn ) :
            if ( arr [ j ] % i == 0 ) :
                flag = False
                break
        if ( flag ) :
            ans = i
            break
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 2 , 6 , 9 , 2 ]
    N = len ( arr )
    smallestNumber ( arr , N )

Index/key variables: i, j
Iterator variables: i, j
Boolean variables: flag
Python program:
def findDuplicate ( str1 , N ) :
    first = 0
    second = 0
    for i in range ( N ) :
        if ( first & ( 1 << ( ord ( str1 [ i ] ) - 97 ) ) ) :
            second = second | ( 1 << ( ord ( str1 [ i ] ) - 97 ) )
        else :
            first = first | ( 1 << ( ord ( str1 [ i ] ) - 97 ) )
    for i in range ( 26 ) :
        if ( ( first & ( 1 << i ) ) and ( second & ( 1 << i ) ) ) :
            print ( chr ( i + 97 ) , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    str1 = " geeksforgeeks "
    N = len ( str1 )
    findDuplicate ( str1 , N )

Index/key variables: i
Iterator variables: i
Python program:
def minOperations ( S ) :
    count = 0 ;
    for i in range ( 1 , len ( S ) ) :
        if ( S [ i ] != S [ i - 1 ] ) :
            count += 1 ;
    print ( count ) ;
if __name__ == ' _ _ main _ _ ' :
    S = "0101010101" ;
    minOperations ( S ) ;

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def numberOfPairs ( arr , N ) :
    set_bits = [ 0 ] * 31
    count = 0
    for i in range ( N ) :
        x = arr [ i ]
        bitpos = - 1
        while ( x > 0 ) :
            bitpos += 1
            x //= 2
        for j in range ( bitpos + 1 ) :
            count += set_bits [ j ]
        set_bits [ bitpos ] += 1
    print ( count )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 16 , 8 , 64 ]
    N = len ( arr )
    numberOfPairs ( arr , N )

Index/key variables: bitpos, i, j
Accumulator variables: count, x
Iterator variables: i, j
Python program:
def calculateQuery ( arr , N , query , M ) :
    for i in range ( M ) :
        X = query [ i ]
        sum_start = 0
        sum_end = 0
        for j in range ( N ) :
            sum_start += arr [ j ]
            if ( arr [ j ] == X ) :
                break
        for j in range ( N - 1 , - 1 , - 1 ) :
            sum_end += arr [ j ]
            if ( arr [ j ] == X ) :
                break
        print ( min ( sum_end , sum_start ) , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 3 , 6 , 7 , 4 , 5 , 30 ]
    queries = [ 6 , 5 ]
    N = len ( arr )
    M = len ( queries )
    calculateQuery ( arr , N , queries , M )

Index/key variables: i, j
Accumulator variables: sum_end, sum_start
Iterator variables: i, j
Python program:
def calculateQuery ( arr , N , query , M ) :
    prefix = 0
    suffix = 0
    mp = { }
    for i in range ( N ) :
        prefix += arr [ i ]
        mp [ arr [ i ] ] = [ prefix , 0 ]
    for i in range ( N - 1 , - 1 , - 1 ) :
        suffix += arr [ i ]
        mp [ arr [ i ] ] = [ mp [ arr [ i ] ] [ 0 ] , suffix ]
    for i in range ( M ) :
        X = query [ i ]
        print ( min ( mp [ X ] [ 0 ] , mp [ X ] [ 1 ] ) , end = " ▁ " )
arr = [ 2 , 3 , 6 , 7 , 4 , 5 , 30 ]
queries = [ 6 , 5 ]
N = len ( arr )
M = len ( queries )
calculateQuery ( arr , N , queries , M )

Index/key variables: X, i
Accumulator variables: prefix, suffix
Iterator variables: i
Python program:
def findMaximum ( arr , N , Q , queries ) :
    prefix_max = [ 0 ] * ( N + 1 )
    suffix_max = [ 0 ] * ( N + 1 )
    prefix_max [ 0 ] = arr [ 0 ]
    for i in range ( 1 , N ) :
        prefix_max [ i ] = max ( prefix_max [ i - 1 ] , arr [ i ] )
    suffix_max [ N - 1 ] = arr [ N - 1 ]
    for i in range ( N - 2 , - 1 , - 1 ) :
        suffix_max [ i ] = max ( suffix_max [ i + 1 ] , arr [ i ] )
    for i in range ( Q ) :
        l = queries [ i ] [ 0 ]
        r = queries [ i ] [ 1 ]
        if ( l == 0 and r == ( N - 1 ) ) :
            print ( "0" )
        elif ( l == 0 ) :
            print ( suffix_max [ r + 1 ] )
        elif ( r == ( N - 1 ) ) :
            print ( prefix_max [ l - 1 ] )
        else :
            print ( max ( prefix_max [ l - 1 ] , suffix_max [ r + 1 ] ) )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 5 , 6 , 8 , 10 , 15 ]
    N = len ( arr )
    queries = [ [ 0 , 1 ] , [ 0 , 2 ] , [ 1 , 4 ] ]
    Q = len ( queries )
    findMaximum ( arr , N , Q , queries )

Index/key variables: i
Iterator variables: i
Python program:
from bisect import bisect_left
def firstOccurence ( s , Q ) :
    N = len ( s )
    M = len ( Q )
    v = [ [ ] for i in range ( 26 ) ]
    for i in range ( N ) :
        v [ ord ( s [ i ] ) - ord ( ' a ' ) ] . append ( i )
    for i in range ( M ) :
        left = Q [ i ] [ 0 ]
        right = Q [ i ] [ 1 ]
        c = Q [ i ] [ 2 ]
        if ( len ( v [ ord ( c ) - ord ( ' a ' ) ] ) == 0 ) :
            print ( " - 1" )
            continue
        idx = bisect_left ( v [ ord ( c ) - ord ( ' a ' ) ] , left )
        if ( idx == len ( v [ ord ( c ) - ord ( ' a ' ) ] ) ) :
            print ( " - 1 ▁ " )
            continue
        idx = v [ ord ( c ) - ord ( ' a ' ) ] [ idx ]
        if ( idx > right ) :
            print ( " - 1 ▁ " )
        else :
            print ( idx , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    S = " abcabcabc " ;
    Q = [ [ 0 , 3 , ' a ' ] , [ 0 , 2 , ' b ' ] , [ 2 , 4 , ' z ' ] ]
    firstOccurence ( S , Q )

Index/key variables: i, idx
Iterator variables: i
Python program:
def oddOneOut ( arr , N ) :
    odd = 0
    even = 0
    lastOdd = 0
    lastEven = 0
    for i in range ( N ) :
        if ( arr [ i ] % 2 == 0 ) :
            even += 1
            lastEven = i
        else :
            odd += 1
            lastOdd = i
    if ( odd == 1 ) :
        print ( lastOdd )
    else :
        print ( lastEven )
arr = [ 2 , 4 , 7 , 8 , 10 ]
N = len ( arr )
oddOneOut ( arr , N )

Index/key variables: i
Accumulator variables: even, odd
Iterator variables: i
Python program:
def minEmail ( email ) :
    ans = ' '
    ans += email [ 0 ]
    i = 1
    notAt = True
    while i < len ( email ) :
        if ( i < len ( email ) - 3 and notAt and email [ i : i + 2 ] == ' at ' ) :
            ans += ' @ '
            i += 1
            notAt = False
        elif i < len ( email ) - 4 and email [ i : i + 3 ] == ' dot ' :
            ans += ' . '
            i += 2
        else :
            ans += email [ i ]
        i += 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    email = ' geeksforgeeksatgmaildotcom '
    print ( minEmail ( email ) )

Index/key variables: i
Accumulator variables: ans
Boolean variables: notAt
Python program:
def isGreaterEqual ( N , X ) :
    return ( N * ( N + 1 ) // 2 ) >= X
def minimumPossible ( X ) :
    for i in range ( 1 , X + 1 ) :
        if ( isGreaterEqual ( i , X ) ) :
            return i
if __name__ == ' _ _ main _ _ ' :
    X = 14
    print ( minimumPossible ( X ) )

Iterator variables: i
Python program:
def CheckDivByAllDigits ( number ) :
    n = number
    while ( n > 0 ) :
        if ( n % 10 ) :
            if ( number % ( n % 10 ) ) :
                return False
        n //= 10
    return True
def cntNumInRang ( arr , N ) :
    global Max
    prefCntDiv = [ 0 ] * Max
    for i in range ( 1 , Max ) :
        prefCntDiv [ i ] = prefCntDiv [ i - 1 ] + ( CheckDivByAllDigits ( i ) )
    for i in range ( N ) :
        print ( prefCntDiv [ arr [ i ] [ 1 ] ] - prefCntDiv [ arr [ i ] [ 0 ] - 1 ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 1 , 5 ] , [ 12 , 14 ] ]
    Max = 1000005
    N = len ( arr )
    cntNumInRang ( arr , N )

Index/key variables: i
Accumulator variables: n
Iterator variables: i
Python program:
def arrayNesting ( arr ) :
    res = 0
    for i in range ( len ( arr ) ) :
        if arr [ i ] == i :
            res = max ( res , 1 )
        else :
            count = 0
            curr_index = i
            while arr [ curr_index ] != curr_index :
                next_index = arr [ curr_index ]
                arr [ curr_index ] = curr_index
                curr_index = next_index
                count += 1
        res = max ( res , count )
    return res
if __name__ == " _ _ main _ _ " :
    arr = [ 5 , 4 , 0 , 3 , 1 , 6 , 2 ]
    res = arrayNesting ( arr )
    print ( res )

Index/key variables: curr_index, i
Accumulator variables: count
Iterator variables: i
Python program:
N = 2 * 100000
prime = [ 0 ] * N
def Sieve ( ) :
    p = [ True ] * ( N + 1 )
    p [ 0 ] = p [ 1 ] = False
    i = 2
    while ( i * i <= N ) :
        if ( p [ i ] == True ) :
            for j in range ( i * i , N , i ) :
                p [ j ] = False
        i += 1
    for i in range ( N ) :
        if ( p [ i ] != False ) :
            prime . append ( pow ( i , 4 ) )
def countNumbers ( L , R ) :
    Count = 0
    for p in prime :
        if ( p >= L and p <= R ) :
            Count += 1
    print ( Count )
L = 16
R = 85000
Sieve ( )
countNumbers ( L , R )

Index/key variables: i, j
Accumulator variables: Count, prime
Iterator variables: i, j, p
Python program:
def countRemainingElements ( L1 , L2 , n ) :
    one = 0 ;
    zero = 0 ;
    for i in range ( n ) :
        if ( L1 [ i ] == 1 ) :
            one += 1 ;
        else :
            zero += 1 ;
    ans = n ;
    for i in range ( n ) :
        if ( L2 [ i ] == 1 ) :
            one -= 1 ;
            if ( one < 0 ) :
                ans = i ;
                break ;
        else :
            zero -= 1 ;
            if ( zero < 0 ) :
                ans = i ;
                break ;
    print ( n - ans ) ;
if __name__ == ' _ _ main _ _ ' :
    L1 = [ 1 , 1 , 0 , 0 ] ;
    L2 = [ 0 , 0 , 0 , 1 ] ;
    N = len ( L1 ) ;
    countRemainingElements ( L1 , L2 , N ) ;

Index/key variables: i
Accumulator variables: one, zero
Iterator variables: i
Python program:
def getCount ( rows , columns , A ) :
    res = 0
    for i in range ( rows ) :
        for j in range ( i + 1 , rows , 1 ) :
            if ( A [ i ] [ 0 ] * A [ j ] [ 1 ] == A [ i ] [ 1 ] * A [ j ] [ 0 ] ) :
                res += 1
    return res
if __name__ == ' _ _ main _ _ ' :
    A = [ [ 4 , 8 ] , [ 10 , 20 ] , [ 15 , 30 ] , [ 3 , 6 ] ]
    columns = 2
    rows = len ( A )
    print ( getCount ( rows , columns , A ) )

Index/key variables: i, j
Accumulator variables: res
Iterator variables: i, j
Python program:
def Min_Score_Index ( N , A ) :
    Score = [ 0 ] * N
    for i in range ( N - 1 , - 1 , - 1 ) :
        if A [ i ] + i < N :
            Score [ i ] = A [ i ] * Score [ A [ i ] + i ]
        else :
            Score [ i ] = A [ i ]
    min_value = min ( Score )
    ind = Score . index ( min_value )
    print ( ind )
if __name__ == " _ _ main _ _ " :
    N = 5
    A = [ 1 , 2 , 3 , 4 , 5 ]
    Min_Score_Index ( N , A )

Index/key variables: i
Iterator variables: i
Python program:
def minLength ( S , T , N , M ) :
    temp = " " ;
    subtract = 0 ;
    for i in range ( N ) :
        temp += S [ i ] ;
        if ( len ( temp ) >= M ) :
            if ( T == ( temp [ len ( temp ) - M : len ( temp ) ] ) ) :
                subtract += M ;
                cnt = 0 ;
                while ( cnt != M ) :
                    temp = temp [ 0 : len ( temp ) - 1 ] ;
                    cnt += 1 ;
    print ( ( N - subtract ) ) ;
if __name__ == ' _ _ main _ _ ' :
    S = " aabcbcbd " ;
    T = " abc " ;
    N = len ( S ) ;
    M = len ( T ) ;
    minLength ( S , T , N , M ) ;

Index/key variables: i
Accumulator variables: cnt, subtract, temp
Iterator variables: i
Python program:
def maximumCount ( arr1 , arr2 , s1 , s2 ) :
    sum1 = 0
    sum2 = 0
    for i in range ( s1 ) :
        sum1 += arr1 [ i ]
    for j in range ( s2 ) :
        sum2 += arr2 [ j ]
    len = 0
    if ( s1 >= s2 ) :
        lenn = s2
    else :
        lenn = s1
    arr1 . sort ( ) ;
    arr2 . sort ( ) ;
    j = 0
    k = s2 - 1
    count = 0
    for i in range ( lenn ) :
        if ( sum1 <= sum2 ) :
            if ( arr2 [ k ] >= arr1 [ i ] ) :
                dif1 = arr1 [ j ]
                dif2 = arr2 [ k ]
                sum1 -= dif1
                sum1 += dif2
                sum2 -= dif2
                sum2 += dif1
                j += 1
                k -= 1
                count += 1
            else :
                break
        else :
            break
    return count
arr1 = [ 1 , 3 , 2 , 4 ]
arr2 = [ 6 , 7 , 8 ]
N = len ( arr1 )
M = len ( arr2 )
print ( maximumCount ( arr1 , arr2 , N , M ) )

Index/key variables: i, j, k
Accumulator variables: count, sum1, sum2
Iterator variables: i, j
Python program:
def isValidDigit ( digit , K ) :
    while ( K != 0 ) :
        if ( K % 10 == digit ) :
            return True
        K = K // 10
    return False
def noOfValidNumbers ( K , arr , n ) :
    count = 0
    for i in range ( n ) :
        no = arr [ i ]
        flag = True
        while ( no != 0 ) :
            digit = no % 10
            if ( not isValidDigit ( digit , K ) ) :
                flag = False
                break
            no = no // 10
        if ( flag == True ) :
            count += 1
    return count
if __name__ == " _ _ main _ _ " :
    K = 12
    arr = [ 1 , 12 , 1222 , 13 , 2 ]
    n = len ( arr )
    print ( noOfValidNumbers ( K , arr , n ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Boolean variables: flag
Python program:
from bisect import bisect_left
def minimumIndex ( arr , Q ) :
    N = len ( arr )
    M = len ( Q )
    storeArrIdx = [ ]
    minIdx = [ 0 ] * ( N )
    for i in range ( N ) :
        storeArrIdx . append ( [ arr [ i ] , i ] )
    arr = sorted ( arr )
    storeArrIdx = sorted ( storeArrIdx )
    minIdx [ N - 1 ] = storeArrIdx [ N - 1 ] [ 1 ]
    for i in range ( N - 2 , - 1 , - 1 ) :
        minIdx [ i ] = min ( minIdx [ i + 1 ] , storeArrIdx [ i ] [ 1 ] )
    for i in range ( M ) :
        pos = bisect_left ( arr , Q [ i ] )
        if ( pos == N ) :
            print ( - 1 , end = " ▁ " )
            continue
        print ( minIdx [ pos ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 9 ]
    Q = [ 7 , 10 , 0 ]
    minimumIndex ( arr , Q )

Index/key variables: i, pos
Accumulator variables: storeArrIdx
Iterator variables: i
Python program:
def isSubarrayExistUtil ( arr , K , N ) :
    totalXOR = 0
    SubarrayXOR = 0
    for i in range ( N ) :
        totalXOR ^= arr [ i ]
    for i in range ( K ) :
        SubarrayXOR ^= arr [ i ]
    if ( SubarrayXOR == ( totalXOR ^ SubarrayXOR ) ) :
        return True
    for i in range ( K , N ) :
        SubarrayXOR ^= arr [ i ]
        SubarrayXOR ^= arr [ i - 1 ]
        if ( SubarrayXOR == ( totalXOR ^ SubarrayXOR ) ) :
            return True
    return False
def isSubarrayExist ( arr , K , N ) :
    if ( isSubarrayExistUtil ( arr , K , N ) ) :
        print ( " YES " )
    else :
        print ( " NO " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 3 , 3 , 5 , 7 , 7 , 3 , 4 ]
    N = len ( arr )
    K = 5
    isSubarrayExist ( arr , K , N )

Index/key variables: i
Accumulator variables: SubarrayXOR, totalXOR
Iterator variables: i
Python program:
import sys
def getDefiniteFinds ( arr ) :
    n = len ( arr )
    smallestRight = [ 0 ] * ( n + 1 )
    smallestRight [ n ] = sys . maxsize
    for i in range ( n - 1 , - 1 , - 1 ) :
        smallestRight [ i ] = min ( smallestRight [ i + 1 ] , arr [ i ] )
    mn = - sys . maxsize - 1
    ans = 0
    for i in range ( n ) :
        if ( mn < arr [ i ] and arr [ i ] < smallestRight [ i + 1 ] ) :
            ans += 1
        mn = max ( arr [ i ] , mn )
    return ans
arr = [ 5 , 4 , 9 ]
print ( getDefiniteFinds ( arr ) )

Index/key variables: i, n
Accumulator variables: ans
Iterator variables: i
Python program:
def checkReverse ( leftSum , rightSum ) :
    rev = 0
    temp = rightSum
    while ( temp != 0 ) :
        rev = ( rev * 10 ) + ( temp % 10 )
        temp //= 10
    if ( rev == leftSum ) :
        return True
    return False
def findIndex ( arr , N ) :
    rightSum = 0
    leftSum = 0
    for i in range ( N ) :
        rightSum += arr [ i ]
    for i in range ( N ) :
        rightSum -= arr [ i ]
        if ( checkReverse ( leftSum , rightSum ) ) :
            return i
        leftSum += arr [ i ]
    return - 1
if __name__ == ' _ _ main _ _ ' :
    arr = [ 5 , 7 , 3 , 6 , 4 , 9 , 2 ]
    N = len ( arr )
    print ( findIndex ( arr , N ) )

Index/key variables: i
Accumulator variables: leftSum, rightSum, temp
Iterator variables: i
Python program:
Max = 100005
def printUniqDif ( n , a ) :
    bset = [ 0 for i in range ( 33 ) ]
    diff = 0
    for i in range ( n ) :
        bset [ a [ i ] ] = 1
    d = 0
    for i in range ( 1 , 33 ) :
        d = d | ( bset [ i ] << i )
    for i in range ( 33 ) :
        if ( bset [ i ] ) :
            diff = diff | d >> i
    X , Y = bset . count ( 1 ) , str ( bin ( diff ) [ 2 : ] )
    if ( X != n ) :
        print ( 0 , end = " ▁ " )
    for i in range ( 1 , len ( Y ) ) :
        if ( Y [ i ] == '1' ) :
            print ( i , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    a = [ 1 , 4 , 6 ]
    n = len ( a )
    printUniqDif ( n , a )

Index/key variables: i
Iterator variables: i
Python program:
from bisect import bisect_left
def LCS ( firstArr , secondArr ) :
    mp = { }
    for i in range ( len ( firstArr ) ) :
        mp [ firstArr [ i ] ] = i + 1
    tempArr = [ ]
    for i in range ( len ( secondArr ) ) :
        if ( secondArr [ i ] in mp ) :
            tempArr . append ( mp [ secondArr [ i ] ] )
    tail = [ ]
    tail . append ( tempArr [ 0 ] )
    for i in range ( 1 , len ( tempArr ) ) :
        if ( tempArr [ i ] > tail [ - 1 ] ) :
            tail . append ( tempArr [ i ] )
        elif ( tempArr [ i ] < tail [ 0 ] ) :
            tail [ 0 ] = tempArr [ i ]
        else :
            it = bisect_left ( tail , tempArr [ i ] )
            it = tempArr [ i ]
    return len ( tail )
if __name__ == ' _ _ main _ _ ' :
    firstArr = [ 3 , 5 , 1 , 8 ]
    secondArr = [ 3 , 3 , 5 , 3 , 8 ]
    print ( LCS ( firstArr , secondArr ) )

Index/key variables: i
Accumulator variables: tail, tempArr
Iterator variables: i