dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def countNum ( arr , n ) :
    count = 0
    arr . sort ( )
    for i in range ( 0 , n - 1 ) :
        if ( arr [ i ] != arr [ i + 1 ] and arr [ i ] != arr [ i + 1 ] - 1 ) :
            count += arr [ i + 1 ] - arr [ i ] - 1 ;
    return count
arr = [ 3 , 5 , 8 , 6 ]
n = len ( arr )
print ( countNum ( arr , n ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
import math as mt
def findElementsAfterDel ( arr , m , dell , n , k ) :
    mp = dict ( )
    for i in range ( n ) :
        if dell [ i ] in mp . keys ( ) :
            mp [ dell [ i ] ] += 1
        else :
            mp [ dell [ i ] ] = 1
    heap = list ( )
    for i in range ( m ) :
        if ( arr [ i ] in mp . keys ( ) ) :
            mp [ arr [ i ] ] -= 1
            if ( mp [ arr [ i ] ] == 0 ) :
                mp . pop ( arr [ i ] )
        else :
            heap . append ( arr [ i ] )
    heap . sort ( )
    return heap [ : k ]
array = [ 5 , 12 , 33 , 4 , 56 , 12 , 20 ]
m = len ( array )
dell = [ 12 , 56 , 5 ]
n = len ( dell )
k = 3
print ( * findElementsAfterDel ( array , m , dell , n , k ) )

Index/key variables: i
Accumulator variables: heap
Iterator variables: i
Python program:
def countNum ( arr , n ) :
    s = dict ( )
    count , maxm , minm = 0 , - 10 ** 9 , 10 ** 9
    for i in range ( n ) :
        s [ arr [ i ] ] = 1
        if ( arr [ i ] < minm ) :
            minm = arr [ i ]
        if ( arr [ i ] > maxm ) :
            maxm = arr [ i ]
    for i in range ( minm , maxm + 1 ) :
        if i not in s . keys ( ) :
            count += 1
    return count
arr = [ 3 , 5 , 8 , 6 ]
n = len ( arr )
print ( countNum ( arr , n ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def isPossible ( A , n , H , K ) :
    time = 0
    for i in range ( n ) :
        time += ( A [ i ] - 1 ) // K + 1
    return time <= H
def minJobSpeed ( A , n , H ) :
    if H < n :
        return - 1
    Max = max ( A )
    lo , hi = 1 , Max
    while lo < hi :
        mi = lo + ( hi - lo ) // 2
        if not isPossible ( A , n , H , mi ) :
            lo = mi + 1
        else :
            hi = mi
    return lo
if __name__ == " _ _ main _ _ " :
    A = [ 3 , 6 , 7 , 11 ]
    H = 8
    n = len ( A )
    print ( minJobSpeed ( A , n , H ) )

Index/key variables: i
Accumulator variables: time
Iterator variables: i
Python program:
def countAnomalies ( a , n , k ) :
    a = sorted ( a ) ;
    res = 0 ;
    for i in range ( n ) :
        u = upper_bound ( a , 0 , n , a [ i ] ) ;
        if ( u < n and a [ u ] - a [ i ] <= k ) :
            continue ;
        s = lower_bound ( a , 0 , n , a [ i ] ) ;
        if ( u - s > 1 ) :
            continue ;
        if ( s > 0 and a [ s - 1 ] - a [ i ] <= k ) :
            continue ;
        res += 1 ;
    return res ;
def lower_bound ( a , low , high , element ) :
    while ( low < high ) :
        middle = int ( low + int ( high - low ) / 2 ) ;
        if ( element > a [ middle ] ) :
            low = middle + 1 ;
        else :
            high = middle ;
    return low ;
def upper_bound ( a , low , high , element ) :
    while ( low < high ) :
        middle = int ( low + ( high - low ) / 2 ) ;
        if ( a [ middle ] > element ) :
            high = middle ;
        else :
            low = middle + 1 ;
    return low ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 7 , 1 , 8 ]
    k = 5 ;
    n = len ( arr ) ;
    print ( countAnomalies ( arr , n , k ) ) ;

Index/key variables: i, middle, u
Accumulator variables: res
Iterator variables: i
Python program:
def sumoflength ( arr , n ) :
    s = [ ]
    j = 0
    ans = 0
    for i in range ( n ) :
        while ( j < n and ( arr [ j ] not in s ) ) :
            s . append ( arr [ j ] )
            j += 1
        ans += ( ( j - i ) * ( j - i + 1 ) ) // 2
        s . remove ( arr [ i ] )
    return ans
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 4 ]
    n = len ( arr )
    print ( sumoflength ( arr , n ) )

Index/key variables: i, j
Accumulator variables: ans, s
Iterator variables: i
Python program:
def countDistictSubarray ( arr , n ) :
    vis = dict ( )
    for i in range ( n ) :
        vis [ arr [ i ] ] = 1
    k = len ( vis )
    vid = dict ( )
    ans = 0
    right = 0
    window = 0
    for left in range ( n ) :
        while ( right < n and window < k ) :
            if arr [ right ] in vid . keys ( ) :
                vid [ arr [ right ] ] += 1
            else :
                vid [ arr [ right ] ] = 1
            if ( vid [ arr [ right ] ] == 1 ) :
                window += 1
            right += 1
        if ( window == k ) :
            ans += ( n - right + 1 )
        vid [ arr [ left ] ] -= 1
        if ( vid [ arr [ left ] ] == 0 ) :
            window -= 1
    return ans
arr = [ 2 , 1 , 3 , 2 , 3 ]
n = len ( arr )
print ( countDistictSubarray ( arr , n ) )

Index/key variables: i, left, right
Accumulator variables: ans, window
Iterator variables: i, left
Python program:
def countSubarrays ( arr , n ) :
    difference = 0
    ans = 0
    hash_positive = [ 0 ] * ( n + 1 )
    hash_negative = [ 0 ] * ( n + 1 )
    hash_positive [ 0 ] = 1
    for i in range ( n ) :
        if ( arr [ i ] & 1 == 1 ) :
            difference = difference + 1
        else :
            difference = difference - 1
        if ( difference < 0 ) :
            ans += hash_negative [ - difference ]
            hash_negative [ - difference ] = hash_negative [ - difference ] + 1
        else :
            ans += hash_positive [ difference ]
            hash_positive [ difference ] = hash_positive [ difference ] + 1
    return ans
arr = [ 3 , 4 , 6 , 8 , 1 , 10 , 5 , 7 ]
n = len ( arr )
print ( " Total ▁ Number ▁ of ▁ Even - Odd ▁ subarrays ▁ are ▁ " + str ( countSubarrays ( arr , n ) ) )

Index/key variables: difference, i
Accumulator variables: ans
Iterator variables: i
Python program:
def printGreaterCount ( str ) :
    len__ = len ( str )
    right = [ 0 for i in range ( len__ ) ]
    for i in range ( len__ ) :
        for j in range ( i + 1 , len__ , 1 ) :
            if ( str [ i ] < str [ j ] ) :
                right [ i ] += 1
    for i in range ( len__ ) :
        print ( right [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    str = " abcd "
    printGreaterCount ( str )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def findLongestConseqSubseq ( arr , n ) :
    S = set ( ) ;
    for i in range ( n ) :
        S . add ( arr [ i ] ) ;
    ans = 0 ;
    for i in range ( n ) :
        if S . __contains__ ( arr [ i ] ) :
            j = arr [ i ] ;
            while ( S . __contains__ ( j ) ) :
                j += 1 ;
            ans = max ( ans , j - arr [ i ] ) ;
    return ans ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 94 , 93 , 1000 , 5 , 92 , 78 ] ;
    n = len ( arr ) ;
    print ( findLongestConseqSubseq ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: S, j
Iterator variables: i
Python program:
import sys
def appearsNBy3 ( arr , n ) :
    count1 = 0
    count2 = 0
    first = sys . maxsize
    second = sys . maxsize
    for i in range ( 0 , n ) :
        if ( first == arr [ i ] ) :
            count1 += 1
        elif ( second == arr [ i ] ) :
            count2 += 1
        elif ( count1 == 0 ) :
            count1 += 1
            first = arr [ i ]
        elif ( count2 == 0 ) :
            count2 += 1
            second = arr [ i ]
        else :
            count1 -= 1
            count2 -= 1
    count1 = 0
    count2 = 0
    for i in range ( 0 , n ) :
        if ( arr [ i ] == first ) :
            count1 += 1
        elif ( arr [ i ] == second ) :
            count2 += 1
    if ( count1 > n / 3 ) :
        return first
    if ( count2 > n / 3 ) :
        return second
    return - 1
arr = [ 1 , 2 , 3 , 1 , 1 ]
n = len ( arr )
print ( appearsNBy3 ( arr , n ) )

Index/key variables: i
Accumulator variables: count1, count2
Iterator variables: i
Python program:
def findSubarraySum ( arr , n ) :
    cArray = [ 0 for i in range ( n + 1 ) ]
    for i in range ( 0 , n , 1 ) :
        cArray [ i + 1 ] = cArray [ i ] + arr [ i ]
    subArrSum = [ ]
    for i in range ( 1 , n + 1 , 1 ) :
        for j in range ( i , n + 1 , 1 ) :
            subArrSum . append ( cArray [ j ] - cArray [ i - 1 ] )
    subArrSum . sort ( reverse = False )
    totalSum = 0
    for i in range ( 0 , len ( subArrSum ) - 1 , 1 ) :
        if ( subArrSum [ i ] == subArrSum [ i + 1 ] ) :
            j = i + 1
            while ( subArrSum [ j ] == subArrSum [ i ] and j < len ( subArrSum ) ) :
                subArrSum [ j ] = 0
                j += 1
            subArrSum [ i ] = 0
    for i in range ( 0 , len ( subArrSum ) , 1 ) :
        totalSum += subArrSum [ i ]
    return totalSum
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 2 , 3 , 1 , 4 ]
    n = len ( arr )
    print ( findSubarraySum ( arr , n ) )

Index/key variables: i, j
Accumulator variables: subArrSum, totalSum
Iterator variables: i, j
Python program:
def findSubarraySum ( arr , n ) :
    res = 0
    m = dict ( )
    for i in range ( n ) :
        Sum = 0
        for j in range ( i , n ) :
            Sum += arr [ j ]
            m [ Sum ] = m . get ( Sum , 0 ) + 1
    for x in m :
        if m [ x ] == 1 :
            res += x
    return res
arr = [ 3 , 2 , 3 , 1 , 4 ]
n = len ( arr )
print ( findSubarraySum ( arr , n ) )

Index/key variables: Sum, j, x
Accumulator variables: res
Iterator variables: i, j, x
Python program:
def recaman ( n ) :
    arr = [ 0 ] * n
    arr [ 0 ] = 0
    print ( arr [ 0 ] , end = " , ▁ " )
    for i in range ( 1 , n ) :
        curr = arr [ i - 1 ] - i
        for j in range ( 0 , i ) :
            if ( ( arr [ j ] == curr ) or curr < 0 ) :
                curr = arr [ i - 1 ] + i
                break
        arr [ i ] = curr
        print ( arr [ i ] , end = " , ▁ " )
n = 17
recaman ( n )

Index/key variables: i, j
Iterator variables: i, j
Python program:
class Node :
    def __init__ ( self , x ) :
        self . data = x
        self . left = None
        self . right = None
def height ( root ) :
    global ans , k , lh , rh , f
    if ( root == None ) :
        return 0
    left_height = height ( root . left )
    right_height = height ( root . right )
    if ( ans < 1 + left_height + right_height ) :
        ans = 1 + left_height + right_height
        k = root
        lh = left_height
        rh = right_height
    return 1 + max ( left_height , right_height )
def printArray ( ints , lenn , f ) :
    if ( f == 0 ) :
        for i in range ( lenn - 1 , - 1 , - 1 ) :
            print ( ints [ i ] , end = " ▁ " )
    elif ( f == 1 ) :
        for i in range ( lenn ) :
            print ( ints [ i ] , end = " ▁ " )
def printPathsRecur ( node , path , maxm , pathlen ) :
    global f
    if ( node == None ) :
        return
    path [ pathlen ] = node . data
    pathlen += 1
    if ( node . left == None and node . right == None ) :
        if ( pathlen == maxm and ( f == 0 or f == 1 ) ) :
            printArray ( path , pathlen , f )
            f = 2
    else :
        printPathsRecur ( node . left , path , maxm , pathlen )
        printPathsRecur ( node . right , path , maxm , pathlen )
def diameter ( root ) :
    if ( root == None ) :
        return
    global ans , lh , rh
    global f , k , pathLen
    height_of_tree = height ( root )
    lPath = [ 0 for i in range ( 100 ) ]
    printPathsRecur ( k . left , lPath , lh , 0 ) ;
    print ( k . data , end = " ▁ " )
    rPath = [ 0 for i in range ( 100 ) ]
    f = 1
    printPathsRecur ( k . right , rPath , rh , 0 )
if __name__ == ' _ _ main _ _ ' :
    k , lh , rh , f , ans , pathLen = None , 0 , 0 , 0 , 0 - 10 ** 19 , 0
    root = Node ( 1 )
    root . left = Node ( 2 )
    root . right = Node ( 3 )
    root . left . left = Node ( 4 )
    root . left . right = Node ( 5 )
    root . left . right . left = Node ( 6 )
    root . left . right . right = Node ( 7 )
    root . left . left . right = Node ( 8 )
    root . left . left . right . left = Node ( 9 )
    diameter ( root )

Index/key variables: i, pathlen
Iterator variables: i
Class/struct names: Node
Python program:
def recaman ( n ) :
    if ( n <= 0 ) :
        return
    print ( 0 , " , " , end = ' ' )
    s = set ( [ ] )
    s . add ( 0 )
    prev = 0
    for i in range ( 1 , n ) :
        curr = prev - i
        if ( curr < 0 or curr in s ) :
            curr = prev + i
        s . add ( curr )
        print ( curr , " , " , end = ' ' )
        prev = curr
if __name__ == ' _ _ main _ _ ' :
    n = 17
    recaman ( n )

Accumulator variables: s
Iterator variables: i
Python program:
def findFibSubset ( arr , n ) :
    m = max ( arr )
    a = 0
    b = 1
    hash = [ ]
    hash . append ( a )
    hash . append ( b )
    while ( b < m ) :
        c = a + b
        a = b
        b = c
        hash . append ( b )
    for i in range ( n ) :
        if arr [ i ] in hash :
            print ( arr [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ 4 , 2 , 8 , 5 , 20 , 1 , 40 , 13 , 23 ]
    n = len ( arr )
    findFibSubset ( arr , n )

Index/key variables: i
Accumulator variables: hash
Iterator variables: i
Python program:
import math
def sumOfDiv ( x ) :
    sum = 1 ;
    for i in range ( 2 , int ( math . sqrt ( x ) ) ) :
        if x % i == 0 :
            sum += i
            if i != x / i :
                sum += x / i
    return int ( sum ) ;
def isAmbicle ( a , b ) :
    return ( sumOfDiv ( a ) == b and sumOfDiv ( b ) == a )
def countPairs ( arr , n ) :
    s = set ( )
    count = 0
    for i in range ( n ) :
        s . add ( arr [ i ] )
    for i in range ( n ) :
        if sumOfDiv ( arr [ i ] ) in s :
            sum = sumOfDiv ( arr [ i ] )
            if isAmbicle ( arr [ i ] , sum ) :
                count += 1
    return int ( count / 2 ) ;
arr1 = [ 220 , 284 , 1184 , 1210 , 2 , 5 ]
n1 = len ( arr1 )
print ( countPairs ( arr1 , n1 ) )
arr2 = [ 2620 , 2924 , 5020 , 5564 , 6232 , 6368 ]
n2 = len ( arr2 )
print ( countPairs ( arr2 , n2 ) )

Index/key variables: i
Accumulator variables: count, s, sum
Iterator variables: i
Python program:
import sys
def minimumDeletion ( s , n ) :
    countMap = { }
    for i in s :
        countMap [ i ] = countMap . get ( i , 0 ) + 1
    countMultiset = [ ]
    for it in countMap :
        countMultiset . append ( countMap [ it ] )
    ans = sys . maxsize + 1
    i = 0
    m = len ( countMultiset )
    for j in sorted ( countMultiset ) :
        ans = min ( ans , n - ( m - i ) * j )
        i += 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    S = " geeksforgeeks "
    N = len ( S )
    print ( minimumDeletion ( S , N ) )

Index/key variables: i, it
Accumulator variables: countMultiset
Iterator variables: i, it, j
Python program:
def calculateDistance ( arr , N ) :
    v = [ ]
    for i in range ( N ) :
        v . append ( [ arr [ i ] , i ] )
    v . sort ( )
    ans = 0
    last = 0
    for j in v :
        ans += abs ( j [ 1 ] - last )
        last = j [ 1 ]
    return ans
if __name__ == " _ _ main _ _ " :
    arr = [ 4 , 3 , 2 , 5 , 1 ]
    N = len ( arr )
    print ( calculateDistance ( arr , N ) )

Index/key variables: i
Accumulator variables: ans, v
Iterator variables: i, j
Python program:
import math
def sortArr ( arr , N ) :
    for i in range ( N ) :
        s = str ( arr [ i ] )
        list1 = list ( s )
        list1 . sort ( reverse = True )
        s = ' ' . join ( list1 )
        arr [ i ] = int ( s )
        sr = int ( math . sqrt ( arr [ i ] ) )
        a = sr * sr
        b = ( sr + 1 ) * ( sr + 1 )
        if ( ( arr [ i ] - a ) < ( b - arr [ i ] ) ) :
            arr [ i ] = a
        else :
            arr [ i ] = b
    arr . sort ( )
    for i in range ( N ) :
        print ( arr [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ 29 , 43 , 28 , 12 ]
    N = len ( arr )
    sortArr ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
import sys
def mincost ( arr , N , X ) :
    arr . sort ( )
    sum = 0
    cost = 0
    min_cost = sys . maxsize
    for i in range ( 0 , N ) :
        if ( arr [ i ] < 0 ) :
            cost = abs ( arr [ i ] ) * x + ( sum - abs ( arr [ i ] ) * i )
            sum += abs ( arr [ i ] )
            min_cost = min ( min_cost , cost )
    return min_cost
arr = [ - 1 , - 3 , - 2 , 4 , - 1 ]
N = len ( arr )
x = 2
print ( mincost ( arr , N , x ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
ans = 0
def countArraysUtil ( arr , X , K , xorVal ) :
    global ans
    if ( X == 0 ) :
        cnt = 0
        for i in range ( len ( arr ) ) :
            if ( arr [ i ] > xorVal ) :
                cnt += 1
        if ( cnt >= K ) :
            ans += 1
        return
    temp = arr [ 0 ]
    arr . pop ( 0 )
    countArraysUtil ( arr , X - 1 , K , xorVal )
    arr . insert ( 0 , temp )
    temp = arr [ - 1 ]
    arr . pop ( )
    countArraysUtil ( arr , X - 1 , K , xorVal )
    arr . append ( temp )
    arr [ 0 ] += 1
    countArraysUtil ( arr , X - 1 , K , xorVal )
    arr [ 0 ] -= 1
    arr [ len ( arr ) - 1 ] += 1
    countArraysUtil ( arr , X - 1 , K , xorVal )
    arr [ len ( arr ) - 1 ] -= 1
def countArrays ( arr , X , K ) :
    xorVal = 0
    for i in range ( len ( arr ) ) :
        xorVal = xorVal ^ arr [ i ]
    countArraysUtil ( arr , X , K , xorVal )
    print ( ans )
arr = [ 10 , 2 , 10 , 5 ]
X = 3
K = 3
countArrays ( arr , X , K )

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
import math
from collections import defaultdict
def hashFunction ( N ) :
    prime = [ 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 ]
    value = 1
    while ( N != 0 ) :
        r = N % 10
        value = value * prime [ r ]
        N = N // 10
    return value
def findDiff ( arr , n ) :
    m = defaultdict ( lambda : [ ] )
    for i in range ( n ) :
        h = hashFunction ( arr [ i ] )
        m [ h ] . append ( arr [ i ] )
    i = 0
    while ( i != len ( m ) ) :
        if ( len ( m [ i ] ) > 1 ) :
            minn = min ( m [ i ] )
            maxx = max ( m [ i ] )
            print ( maxx - minn )
            break
        elif ( i == ( len ( m ) - 1 ) ) :
            print ( - 1 )
        i += 1
arr = [ 121 , 312 , 234 , 211 , 112 , 102 ]
N = len ( arr )
findDiff ( arr , N )

Index/key variables: h, i, r
Iterator variables: i
Python program:
def findArea ( arr , n ) :
    arr . sort ( reverse = True )
    dimension = [ 0 , 0 ]
    i = 0
    j = 0
    while ( i < n - 1 and j < 2 ) :
        if ( arr [ i ] == arr [ i + 1 ] ) :
            dimension [ j ] = arr [ i ]
            j += 1
            i += 1
        i += 1
    return ( dimension [ 0 ] * dimension [ 1 ] )
arr = [ 4 , 2 , 1 , 4 , 6 , 6 , 2 , 5 ]
n = len ( arr )
print ( findArea ( arr , n ) )

Index/key variables: i, j
Python program:
def findArea ( arr , n ) :
    s = [ ]
    first = 0
    second = 0
    for i in range ( n ) :
        if arr [ i ] not in s :
            s . append ( arr [ i ] )
            continue
        if ( arr [ i ] > first ) :
            second = first
            first = arr [ i ]
        elif ( arr [ i ] > second ) :
            second = arr [ i ]
    return ( first * second )
if __name__ == " _ _ main _ _ " :
    arr = [ 4 , 2 , 1 , 4 , 6 , 6 , 2 , 5 ]
    n = len ( arr )
    print ( findArea ( arr , n ) )

Index/key variables: i
Accumulator variables: s
Iterator variables: i
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
def printTopToBottomPath ( curr , parent ) :
    stk = [ ]
    while ( curr ) :
        stk . append ( curr )
        curr = parent [ curr ]
    while len ( stk ) != 0 :
        curr = stk [ - 1 ]
        stk . pop ( - 1 )
        print ( curr . data , end = " ▁ " )
    print ( )
def printRootToLeaf ( root ) :
    if ( root == None ) :
        return
    nodeStack = [ ]
    nodeStack . append ( root )
    parent = { }
    parent [ root ] = None
    while len ( nodeStack ) != 0 :
        current = nodeStack [ - 1 ]
        nodeStack . pop ( - 1 )
        if ( not ( current . left ) and not ( current . right ) ) :
            printTopToBottomPath ( current , parent )
        if ( current . right ) :
            parent [ current . right ] = current
            nodeStack . append ( current . right )
        if ( current . left ) :
            parent [ current . left ] = current
            nodeStack . append ( current . left )
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 10 )
    root . left = newNode ( 8 )
    root . right = newNode ( 2 )
    root . left . left = newNode ( 3 )
    root . left . right = newNode ( 5 )
    root . right . left = newNode ( 2 )
    printRootToLeaf ( root )

Index/key variables: curr, root
Accumulator variables: nodeStack, stk
Class/struct names: newNode
Python program:
def playGame ( arr , n ) :
    s = set ( )
    for i in range ( n ) :
        s . add ( arr [ i ] )
    return 1 if len ( s ) % 2 == 0 else 2
arr = [ 1 , 1 , 2 , 2 , 2 , 2 ]
n = len ( arr )
print ( " Player " , playGame ( arr , n ) , " Wins " )

Index/key variables: i
Accumulator variables: s
Iterator variables: i
Python program:
def longLenStrictBitonicSub ( arr , n ) :
    inc , dcr = dict ( ) , dict ( )
    len_inc , len_dcr = [ 0 ] * n , [ 0 ] * n
    longLen = 0
    for i in range ( n ) :
        len = 0
        if inc . get ( arr [ i ] - 1 ) in inc . values ( ) :
            len = inc . get ( arr [ i ] - 1 )
        inc [ arr [ i ] ] = len_inc [ i ] = len + 1
    for i in range ( n - 1 , - 1 , - 1 ) :
        len = 0
        if dcr . get ( arr [ i ] - 1 ) in dcr . values ( ) :
            len = dcr . get ( arr [ i ] - 1 )
        dcr [ arr [ i ] ] = len_dcr [ i ] = len + 1
    for i in range ( n ) :
        if longLen < ( len_inc [ i ] + len_dcr [ i ] - 1 ) :
            longLen = len_inc [ i ] + len_dcr [ i ] - 1
    return longLen
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 5 , 2 , 3 , 4 , 5 , 3 , 2 ]
    n = len ( arr )
    print ( " Longest ▁ length ▁ strict ▁ bitonic ▁ subsequence ▁ = " , longLenStrictBitonicSub ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
import sys ;
def lastSeenElement ( a , n ) :
    hash = { }
    for i in range ( n ) :
        hash [ a [ i ] ] = i
    res_ind = sys . maxsize
    res = 0
    for x , y in hash . items ( ) :
        if y < res_ind :
            res_ind = y
            res = x
    return res
if __name__ == " _ _ main _ _ " :
    a = [ 2 , 1 , 2 , 2 , 4 , 1 ]
    n = len ( a )
    print ( lastSeenElement ( a , n ) )

Index/key variables: i
Iterator variables: i, x, y
Python program:
def Bubble_Sort ( arr , n ) :
    for i in range ( 1 , n ) :
        for j in range ( 0 , n - i ) :
            if ( arr [ j ] > arr [ j + 1 ] ) :
                arr [ j ] , arr [ j + 1 ] = arr [ j + 1 ] , arr [ j ]
    return arr
n = 5
arr = [ 2 , 0 , 1 , 4 , 3 ]
arr = Bubble_Sort ( arr , n )
print ( " The ▁ Sorted ▁ Array ▁ by ▁ using ▁ Bubble ▁ Sort ▁ is ▁ : ▁ " , end = ' ' )
for i in range ( n ) :
    print ( arr [ i ] , end = " ▁ " )

Index/key variables: i, j
Iterator variables: i, j
Python program:
parent = [ 0 ] * 100
size = [ 0 ] * 100
def find_set ( v ) :
    if ( v == parent [ v ] ) :
        return v
    parent [ v ] = find_set ( parent [ v ] )
    return parent [ v ]
def union_sets ( a , b ) :
    a = find_set ( a )
    b = find_set ( b )
    if ( a != b ) :
        if ( size [ a ] < size [ b ] ) :
            a , b = b , a
        parent [ b ] = a
        size [ a ] += size [ b ]
        return 1
    return 0
def MST ( houses , n ) :
    v = [ ]
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            p = abs ( houses [ i ] [ 0 ] - houses [ j ] [ 0 ] )
            p += abs ( houses [ i ] [ 1 ] - houses [ j ] [ 1 ] )
            v . append ( [ p , i , j ] )
    v = sorted ( v )
    for i in range ( n ) :
        parent [ i ] = i
        size [ i ] = 1
    ans = 0
    for x in v :
        if ( union_sets ( x [ 1 ] , x [ 2 ] ) ) :
            ans += x [ 0 ]
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    houses = [ [ 0 , 0 ] , [ 2 , 2 ] , [ 3 , 10 ] , [ 5 , 2 ] , [ 7 , 0 ] ]
    N = len ( houses )
    MST ( houses , N )

Index/key variables: a, b, i, j, v
Accumulator variables: ans, p
Iterator variables: i, j, x