dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def countPairs ( a , n , k ) :
    res = 0
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            if ( abs ( a [ j ] - a [ i ] ) < k ) :
                res += 1
    return res
a = [ 1 , 10 , 4 , 2 ]
k = 3
n = len ( a )
print ( countPairs ( a , n , k ) , end = " " )

Index/key variables: i, j
Accumulator variables: res
Iterator variables: i, j
Python program:
def countPairs ( a , n , k ) :
    a . sort ( )
    res = 0
    for i in range ( n ) :
        j = i + 1
        while ( j < n and a [ j ] - a [ i ] < k ) :
            res += 1
            j += 1
    return res
a = [ 1 , 10 , 4 , 2 ]
k = 3
n = len ( a )
print ( countPairs ( a , n , k ) , end = " " )

Index/key variables: i, j
Accumulator variables: res
Iterator variables: i
Python program:
def findMaxPairs ( a , b , n , k ) :
    a . sort ( )
    b . sort ( )
    flag = [ False ] * n
    result = 0
    for i in range ( n ) :
        for j in range ( n ) :
            if ( abs ( a [ i ] - b [ j ] ) <= k and flag [ j ] == False ) :
                result += 1
                flag [ j ] = True
                break
    return result
if __name__ == " _ _ main _ _ " :
    a = [ 10 , 15 , 20 ]
    b = [ 17 , 12 , 24 ]
    n = len ( a )
    k = 3
    print ( findMaxPairs ( a , b , n , k ) )

Index/key variables: i, j
Accumulator variables: result
Iterator variables: i, j
Python program:
def findMaxPairs ( a , b , n , k ) :
    a . sort ( )
    b . sort ( )
    result = 0
    j = 0
    for i in range ( n ) :
        if j < n :
            if abs ( a [ i ] - b [ j ] ) <= k :
                result += 1
                j += 1
            elif a [ i ] > b [ j ] :
                j += 1
    return result
if __name__ == ' _ _ main _ _ ' :
    a = [ 10 , 15 , 20 ]
    b = [ 17 , 12 , 24 ]
    n = len ( a )
    k = 3
    print ( findMaxPairs ( a , b , n , k ) )

Index/key variables: i, j
Accumulator variables: result
Iterator variables: i
Python program:
def sumOfMinAbsDifferences ( arr , n ) :
    arr . sort ( )
    sum = 0
    sum += abs ( arr [ 0 ] - arr [ 1 ] ) ;
    sum += abs ( arr [ n - 1 ] - arr [ n - 2 ] ) ;
    for i in range ( 1 , n - 1 ) :
        sum += min ( abs ( arr [ i ] - arr [ i - 1 ] ) , abs ( arr [ i ] - arr [ i + 1 ] ) )
    return sum ;
arr = [ 5 , 10 , 1 , 4 , 8 , 7 ]
n = len ( arr )
print ( " Sum ▁ = ▁ " , sumOfMinAbsDifferences ( arr , n ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
import sys
def findSmallestDifference ( A , B , m , n ) :
    A . sort ( )
    B . sort ( )
    a = 0
    b = 0
    result = sys . maxsize
    while ( a < m and b < n ) :
        if ( abs ( A [ a ] - B [ b ] ) < result ) :
            result = abs ( A [ a ] - B [ b ] )
        if ( A [ a ] < B [ b ] ) :
            a += 1
        else :
            b += 1
    return result
A = [ 1 , 2 , 11 , 5 ]
B = [ 4 , 12 , 19 , 23 , 127 , 235 ]
m = len ( A )
n = len ( B )
print ( findSmallestDifference ( A , B , m , n ) )

Index/key variables: a, b
Python program:
def findLarger ( arr , n ) :
    x = sorted ( arr )
    for i in range ( n / 2 , n ) :
        print ( x [ i ] ) ,
arr = [ 1 , 3 , 6 , 1 , 0 , 9 ]
n = len ( arr ) ;
findLarger ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
def singleelement ( arr , n ) :
    low = 0
    high = n - 2
    mid = 0
    while ( low <= high ) :
        mid = ( low + high ) // 2
        if ( arr [ mid ] == arr [ mid ^ 1 ] ) :
            low = mid + 1
        else :
            high = mid - 1
    return arr [ low ]
arr = [ 2 , 3 , 5 , 4 , 5 , 3 , 4 ]
size = len ( arr )
arr . sort ( )
print ( singleelement ( arr , size ) )

Index/key variables: low, mid
Python program:
def countTriplets ( arr , n , sum ) :
    ans = 0
    for i in range ( 0 , n - 2 ) :
        for j in range ( i + 1 , n - 1 ) :
            for k in range ( j + 1 , n ) :
                if ( arr [ i ] + arr [ j ] + arr [ k ] < sum ) :
                    ans += 1
    return ans
arr = [ 5 , 1 , 3 , 4 , 7 ]
n = len ( arr )
sum = 12
print ( countTriplets ( arr , n , sum ) )

Index/key variables: i, j, k
Accumulator variables: ans
Iterator variables: i, j, k
Python program:
def countTriplets ( arr , n , sum ) :
    arr . sort ( )
    ans = 0
    for i in range ( 0 , n - 2 ) :
        j = i + 1
        k = n - 1
        while ( j < k ) :
            if ( arr [ i ] + arr [ j ] + arr [ k ] >= sum ) :
                k = k - 1
            else :
                ans += ( k - j )
                j = j + 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 5 , 1 , 3 , 4 , 7 ]
    n = len ( arr )
    sum = 12
    print ( countTriplets ( arr , n , sum ) )

Index/key variables: i, j, k
Accumulator variables: ans
Iterator variables: i
Python program:
def countTriplets ( a , n ) :
    s = set ( )
    for i in range ( n ) :
        s . add ( a [ i ] )
    count = 0
    for i in range ( n ) :
        for j in range ( i + 1 , n , 1 ) :
            xr = a [ i ] ^ a [ j ]
            if ( xr in s and xr != a [ i ] and xr != a [ j ] ) :
                count += 1 ;
    return int ( count / 3 )
if __name__ == ' _ _ main _ _ ' :
    a = [ 1 , 3 , 5 , 10 , 14 , 15 ]
    n = len ( a )
    print ( countTriplets ( a , n ) )

Index/key variables: i, j
Accumulator variables: count, s
Iterator variables: i, j
Python program:
def getMissingNo ( a , n ) :
    i , total = 0 , 1
    for i in range ( 2 , n + 2 ) :
        total += i
        total -= a [ i - 2 ]
    return total
arr = [ 1 , 2 , 3 , 5 ]
print ( getMissingNo ( arr , len ( arr ) ) )

Accumulator variables: total
Iterator variables: i
Python program:
def countOccurrences ( arr , n , x ) :
    res = 0
    for i in range ( n ) :
        if x == arr [ i ] :
            res += 1
    return res
arr = [ 1 , 2 , 2 , 2 , 2 , 3 , 4 , 7 , 8 , 8 ]
n = len ( arr )
x = 2
print ( countOccurrences ( arr , n , x ) )

Index/key variables: i
Accumulator variables: res
Iterator variables: i
Python program:
def binarySearch ( arr , l , r , x ) :
    if ( r < l ) :
        return - 1
    mid = int ( l + ( r - l ) / 2 )
    if arr [ mid ] == x :
        return mid
    if arr [ mid ] > x :
        return binarySearch ( arr , l , mid - 1 , x )
    return binarySearch ( arr , mid + 1 , r , x )
def countOccurrences ( arr , n , x ) :
    ind = binarySearch ( arr , 0 , n - 1 , x )
    if ind == - 1 :
        return 0
    count = 1
    left = ind - 1
    while ( left >= 0 and arr [ left ] == x ) :
        count += 1
        left -= 1
    right = ind + 1 ;
    while ( right < n and arr [ right ] == x ) :
        count += 1
        right += 1
    return count
arr = [ 1 , 2 , 2 , 2 , 2 , 3 , 4 , 7 , 8 , 8 ]
n = len ( arr )
x = 2
print ( countOccurrences ( arr , n , x ) )

Index/key variables: left, mid, right
Accumulator variables: count
Python program:
def findMissingUtil ( arr1 , arr2 , N ) :
    if N == 1 :
        return arr1 [ 0 ] ;
    if arr1 [ 0 ] != arr2 [ 0 ] :
        return arr1 [ 0 ]
    lo = 0
    hi = N - 1
    while ( lo < hi ) :
        mid = ( lo + hi ) / 2
        if arr1 [ mid ] == arr2 [ mid ] :
            lo = mid
        else :
            hi = mid
        if lo == hi - 1 :
            break
    return arr1 [ hi ]
def findMissing ( arr1 , arr2 , M , N ) :
    if N == M - 1 :
        print ( " Missing ▁ Element ▁ is " , findMissingUtil ( arr1 , arr2 , M ) )
    elif M == N - 1 :
        print ( " Missing ▁ Element ▁ is " , findMissingUtil ( arr2 , arr1 , N ) )
    else :
        print ( " Invalid ▁ Input " )
arr1 = [ 1 , 4 , 5 , 7 , 9 ]
arr2 = [ 4 , 5 , 7 , 9 ]
M = len ( arr1 )
N = len ( arr2 )
findMissing ( arr1 , arr2 , M , N )

Index/key variables: hi, mid
Python program:
def findMissing ( arr1 , arr2 , M , N ) :
    if ( M != N - 1 and N != M - 1 ) :
        print ( " Invalid ▁ Input " )
        return
    res = 0
    for i in range ( 0 , M ) :
        res = res ^ arr1 [ i ] ;
    for i in range ( 0 , N ) :
        res = res ^ arr2 [ i ]
    print ( " Missing ▁ element ▁ is " , res )
arr1 = [ 4 , 1 , 5 , 9 , 7 ]
arr2 = [ 7 , 5 , 9 , 4 ]
M = len ( arr1 )
N = len ( arr2 )
findMissing ( arr1 , arr2 , M , N )

Index/key variables: i
Iterator variables: i
Python program:
def printTwoElements ( arr , size ) :
    for i in range ( size ) :
        if arr [ abs ( arr [ i ] ) - 1 ] > 0 :
            arr [ abs ( arr [ i ] ) - 1 ] = - arr [ abs ( arr [ i ] ) - 1 ]
        else :
            print ( " The ▁ repeating ▁ element ▁ is " , abs ( arr [ i ] ) )
    for i in range ( size ) :
        if arr [ i ] > 0 :
            print ( " and ▁ the ▁ missing ▁ element ▁ is " , i + 1 )
arr = [ 7 , 3 , 4 , 5 , 5 , 6 , 2 ]
n = len ( arr )
printTwoElements ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
def getTwoElements ( arr , n ) :
    global x , y
    x = 0
    y = 0
    xor1 = arr [ 0 ]
    for i in range ( 1 , n ) :
        xor1 = xor1 ^ arr [ i ]
    for i in range ( 1 , n + 1 ) :
        xor1 = xor1 ^ i
    set_bit_no = xor1 & ~ ( xor1 - 1 )
    for i in range ( n ) :
        if ( arr [ i ] & set_bit_no ) != 0 :
            x = x ^ arr [ i ]
        else :
            y = y ^ arr [ i ]
    for i in range ( 1 , n + 1 ) :
        if ( i & set_bit_no ) != 0 :
            x = x ^ i
        else :
            y = y ^ i
arr = [ 1 , 3 , 4 , 5 , 5 , 6 , 2 ]
n = len ( arr )
getTwoElements ( arr , n )
print ( " The ▁ missing ▁ element ▁ is " , x , " and ▁ the ▁ repeating ▁ number ▁ is " , y )

Index/key variables: i
Iterator variables: i
Python program:
def main ( ) :
    arr = [ 4 , 3 , 6 , 2 , 1 , 1 ]
    numberMap = { }
    max = len ( arr )
    for i in arr :
        if not i in numberMap :
            numberMap [ i ] = True
        else :
            print ( " Repeating ▁ = " , i )
    for i in range ( 1 , max + 1 ) :
        if not i in numberMap :
            print ( " Missing ▁ = " , i )
main ( )

Index/key variables: i
Iterator variables: i
Python program:
def findFourElements ( A , n , X ) :
    for i in range ( 0 , 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 ] == X :
                        print ( " % d , ▁ % d , ▁ % d , ▁ % d " % ( A [ i ] , A [ j ] , A [ k ] , A [ l ] ) )
A = [ 10 , 2 , 3 , 4 , 5 , 9 , 7 , 8 ]
n = len ( A )
X = 23
findFourElements ( A , n , X )

Index/key variables: i, j, k, l
Iterator variables: i, j, k, l
Python program:
def findFourElements ( arr , n , X ) :
    mp = { }
    for i in range ( n - 1 ) :
        for j in range ( i + 1 , n ) :
            mp [ arr [ i ] + arr [ j ] ] = [ i , j ]
    for i in range ( n - 1 ) :
        for j in range ( i + 1 , n ) :
            summ = arr [ i ] + arr [ j ]
            if ( X - summ ) in mp :
                p = mp [ X - summ ]
                if ( p [ 0 ] != i and p [ 0 ] != j and p [ 1 ] != i and p [ 1 ] != j ) :
                    print ( arr [ i ] , " , ▁ " , arr [ j ] , " , ▁ " , arr [ p [ 0 ] ] , " , ▁ " , arr [ p [ 1 ] ] , sep = " " )
                    return
arr = [ 10 , 20 , 30 , 40 , 1 , 2 ]
n = len ( arr )
X = 91
findFourElements ( arr , n , X )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def fourSum ( X , arr , Map , N ) :
    temp = [ 0 for i in range ( N ) ]
    for i in range ( N - 1 ) :
        for j in range ( i + 1 , N ) :
            curr_sum = arr [ i ] + arr [ j ]
            if ( X - curr_sum ) in Map :
                p = Map [ X - curr_sum ]
                if ( p [ 0 ] != i and p [ 1 ] != i and p [ 0 ] != j and p [ 1 ] != j and temp [ p [ 0 ] ] == 0 and temp [ p [ 1 ] ] == 0 and temp [ i ] == 0 and temp [ j ] == 0 ) :
                    print ( arr [ i ] , " , " , arr [ j ] , " , " , arr [ p [ 0 ] ] , " , " , arr [ p [ 1 ] ] , sep = " " )
                    temp [ p [ 1 ] ] = 1
                    temp [ i ] = 1
                    temp [ j ] = 1
                    break
def twoSum ( nums , N ) :
    Map = { }
    for i in range ( N - 1 ) :
        for j in range ( i + 1 , N ) :
            Map [ nums [ i ] + nums [ j ] ] = [ ]
            Map [ nums [ i ] + nums [ j ] ] . append ( i )
            Map [ nums [ i ] + nums [ j ] ] . append ( j )
    return Map
arr = [ 10 , 20 , 30 , 40 , 1 , 2 ]
n = len ( arr )
X = 91
Map = twoSum ( arr , n )
fourSum ( X , arr , Map , n )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def search ( arr , n , x ) :
    i = 0
    while ( i < n ) :
        if ( arr [ i ] == x ) :
            return i
        i = i + abs ( arr [ i ] - x )
    print ( " number ▁ is ▁ not ▁ present ! " )
    return - 1
arr = [ 8 , 7 , 6 , 7 , 6 , 5 , 4 , 3 , 2 , 3 , 4 , 3 ]
n = len ( arr )
x = 3
print ( " Element " , x , " ▁ is ▁ present ▁ at ▁ index ▁ " , search ( arr , n , 3 ) )

Index/key variables: i
Python program:
import sys
def thirdLargest ( arr , arr_size ) :
    if ( arr_size < 3 ) :
        print ( " ▁ Invalid ▁ Input ▁ " )
        return
    first = arr [ 0 ]
    for i in range ( 1 , arr_size ) :
        if ( arr [ i ] > first ) :
            first = arr [ i ]
    second = - sys . maxsize
    for i in range ( 0 , arr_size ) :
        if ( arr [ i ] > second and arr [ i ] < first ) :
            second = arr [ i ]
    third = - sys . maxsize
    for i in range ( 0 , arr_size ) :
        if ( arr [ i ] > third and arr [ i ] < second ) :
            third = arr [ i ]
    print ( " The ▁ Third ▁ Largest " , " element ▁ is " , third )
arr = [ 12 , 13 , 1 , 10 , 34 , 16 ]
n = len ( arr )
thirdLargest ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
import sys
def thirdLargest ( arr , arr_size ) :
    if ( arr_size < 3 ) :
        print ( " ▁ Invalid ▁ Input ▁ " )
        return
    first = arr [ 0 ]
    second = - sys . maxsize
    third = - sys . maxsize
    for i in range ( 1 , arr_size ) :
        if ( arr [ i ] > first ) :
            third = second
            second = first
            first = arr [ i ]
        elif ( arr [ i ] > second ) :
            third = second
            second = arr [ i ]
        elif ( arr [ i ] > third ) :
            third = arr [ i ]
    print ( " The ▁ third ▁ Largest " , " element ▁ is " , third )
arr = [ 12 , 13 , 1 , 10 , 34 , 16 ]
n = len ( arr )
thirdLargest ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
def checkPair ( arr , n ) :
    s = set ( )
    sum = 0
    for i in range ( n ) :
        sum += arr [ i ]
    if sum % 2 != 0 :
        return False
    sum = sum / 2
    for i in range ( n ) :
        val = sum - arr [ i ]
        if arr [ i ] not in s :
            s . add ( arr [ i ] )
        if val in s :
            print ( " Pair ▁ elements ▁ are " , arr [ i ] , " and " , int ( val ) )
arr = [ 2 , 11 , 5 , 1 , 4 , 7 ]
n = len ( arr )
if checkPair ( arr , n ) == False :
    print ( " No ▁ pair ▁ found " )

Index/key variables: i
Accumulator variables: s, sum
Iterator variables: i
Python program:
def search ( arr , n , x ) :
    if ( arr [ n - 1 ] == x ) :
        return " Found "
    backup = arr [ n - 1 ]
    arr [ n - 1 ] = x
    i = 0
    while ( i < n ) :
        if ( arr [ i ] == x ) :
            arr [ n - 1 ] = backup
            if ( i < n - 1 ) :
                return " Found "
            return " Not ▁ Found "
        i = i + 1
arr = [ 4 , 6 , 1 , 5 , 8 ]
n = len ( arr )
x = 1
print ( search ( arr , n , x ) )

Index/key variables: i
Python program:
def sequence ( a ) :
    if ( len ( a ) == 0 ) :
        return [ 0 , 0 ]
    s = 0
    e = len ( a ) - 1
    while ( s < e ) :
        m = ( s + e ) // 2
        if ( a [ m ] >= m + a [ 0 ] ) :
            s = m + 1
        else :
            e = m
    return [ a [ s ] , len ( a ) - ( a [ len ( a ) - 1 ] - a [ 0 ] ) ]
p = sequence ( [ 1 , 2 , 3 , 4 , 4 , 4 , 5 , 6 ] )
print ( " Repeated ▁ element ▁ is " , p [ 0 ] , " , ▁ it ▁ appears " , p [ 1 ] , " times " )

Index/key variables: m, s
Python program:
def minAdjDifference ( arr , n ) :
    if ( n < 2 ) : return
    res = abs ( arr [ 1 ] - arr [ 0 ] )
    for i in range ( 2 , n ) :
        res = min ( res , abs ( arr [ i ] - arr [ i - 1 ] ) )
    res = min ( res , abs ( arr [ n - 1 ] - arr [ 0 ] ) )
    print ( " Min ▁ Difference ▁ = ▁ " , res )
a = [ 10 , 12 , 13 , 15 , 10 ]
n = len ( a )
minAdjDifference ( a , n )

Index/key variables: i
Iterator variables: i
Python program:
MAX = 100000
def Print3Smallest ( arr , n ) :
    firstmin = MAX
    secmin = MAX
    thirdmin = MAX
    for i in range ( 0 , n ) :
        if arr [ i ] < firstmin :
            thirdmin = secmin
            secmin = firstmin
            firstmin = arr [ i ]
        elif arr [ i ] < secmin :
            thirdmin = secmin
            secmin = arr [ i ]
        elif arr [ i ] < thirdmin :
            thirdmin = arr [ i ]
    print ( " First ▁ min ▁ = ▁ " , firstmin )
    print ( " Second ▁ min ▁ = ▁ " , secmin )
    print ( " Third ▁ min ▁ = ▁ " , thirdmin )
arr = [ 4 , 9 , 1 , 32 , 12 ]
n = len ( arr )
Print3Smallest ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
import bisect
def closestResult ( a , b , n ) :
    a . sort ( )
    c = [ ]
    for i in range ( n ) :
        up = bisect . bisect_right ( a , b [ i ] )
        if up == n :
            c . append ( - 1 )
        else :
            c . append ( a [ up ] )
    print ( " Result ▁ = ▁ " , end = " " )
    for i in c :
        print ( i , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    a = [ 2 , 5 , 6 , 1 , 8 , 9 ]
    b = [ 2 , 1 , 0 , 5 , 4 , 9 ]
    n = len ( a )
    closestResult ( a , b , n )

Index/key variables: i, up
Accumulator variables: c
Iterator variables: i
Python program:
def findCounts ( arr , n ) :
    hash = [ 0 for i in range ( n ) ]
    i = 0
    while ( i < n ) :
        hash [ arr [ i ] - 1 ] += 1
        i += 1
    print ( " Below ▁ are ▁ counts ▁ of ▁ all ▁ elements " )
    for i in range ( n ) :
        print ( i + 1 , " - > " , hash [ i ] , end = " ▁ " )
        print ( )
arr = [ 2 , 3 , 3 , 2 , 5 ]
findCounts ( arr , len ( arr ) )
arr1 = [ 1 ]
findCounts ( arr1 , len ( arr1 ) )
arr3 = [ 4 , 4 , 4 , 4 ]
findCounts ( arr3 , len ( arr3 ) )
arr2 = [ 1 , 3 , 5 , 7 , 9 , 1 , 3 , 5 , 7 , 9 , 1 ]
findCounts ( arr2 , len ( arr2 ) )
arr4 = [ 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 ]
findCounts ( arr4 , len ( arr4 ) )
arr5 = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ]
findCounts ( arr5 , len ( arr5 ) )
arr6 = [ 11 , 10 , 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 ]
findCounts ( arr6 , len ( arr6 ) )

Index/key variables: i
Iterator variables: i
Python program:
def findCounts ( arr , n ) :
    i = 0
    while i < n :
        if arr [ i ] <= 0 :
            i += 1
            continue
        elementIndex = arr [ i ] - 1
        if arr [ elementIndex ] > 0 :
            arr [ i ] = arr [ elementIndex ]
            arr [ elementIndex ] = - 1
        else :
            arr [ elementIndex ] -= 1
            arr [ i ] = 0
            i += 1
    print ( " Below ▁ are ▁ counts ▁ of ▁ all ▁ elements " )
    for i in range ( 0 , n ) :
        print ( " % d ▁ - > ▁ % d " % ( i + 1 , abs ( arr [ i ] ) ) )
    print ( " " )
arr = [ 2 , 3 , 3 , 2 , 5 ]
findCounts ( arr , len ( arr ) )
arr1 = [ 1 ]
findCounts ( arr1 , len ( arr1 ) )
arr3 = [ 4 , 4 , 4 , 4 ]
findCounts ( arr3 , len ( arr3 ) )
arr2 = [ 1 , 3 , 5 , 7 , 9 , 1 , 3 , 5 , 7 , 9 , 1 ]
findCounts ( arr2 , len ( arr2 ) )
arr4 = [ 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 , 3 ]
findCounts ( arr4 , len ( arr4 ) )
arr5 = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 , 11 ]
findCounts ( arr5 , len ( arr5 ) )
arr6 = [ 11 , 10 , 9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 ]
findCounts ( arr6 , len ( arr6 ) )

Index/key variables: elementIndex, i
Iterator variables: i
Python program:
def printfrequency ( arr , n ) :
    for j in range ( n ) :
        arr [ j ] = arr [ j ] - 1
    for i in range ( n ) :
        arr [ arr [ i ] % n ] = arr [ arr [ i ] % n ] + n
    for i in range ( n ) :
        print ( i + 1 , " - > " , arr [ i ] // n )
arr = [ 2 , 3 , 3 , 2 , 5 ]
n = len ( arr )
printfrequency ( arr , n )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def deleteElement ( arr , n , x ) :
    for i in range ( n ) :
        if ( arr [ i ] == x ) :
            break
    if ( i < n ) :
        n = n - 1 ;
        for j in range ( i , n , 1 ) :
            arr [ j ] = arr [ j + 1 ]
    return n
if __name__ == ' _ _ main _ _ ' :
    arr = [ 11 , 15 , 6 , 8 , 9 , 10 ]
    n = len ( arr )
    x = 6
    n = deleteElement ( arr , n , x )
    print ( " Modified ▁ array ▁ is " )
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def deleteElement ( arr , n , x ) :
    if arr [ n - 1 ] == x :
        return n - 1
    prev = arr [ n - 1 ]
    for i in range ( n - 2 , 1 , - 1 ) :
        if arr [ i ] != x :
            curr = arr [ i ]
            arr [ i ] = prev
            prev = curr
    if i < 0 :
        return 0
    arr [ i ] = prev
    return n - 1
arr = [ 11 , 15 , 6 , 8 , 9 , 10 ]
n = len ( arr )
x = 6
n = deleteElement ( arr , n , x )
print ( " Modified ▁ array ▁ is " )
for i in range ( n ) :
    print ( arr [ i ] , end = " ▁ " )

Index/key variables: i
Iterator variables: i
Python program:
def getInvCount ( arr , n ) :
    invcount = 0
    for i in range ( 1 , n - 1 ) :
        small = 0
        for j in range ( i + 1 , n ) :
            if ( arr [ i ] > arr [ j ] ) :
                small += 1
        great = 0 ;
        for j in range ( i - 1 , - 1 , - 1 ) :
            if ( arr [ i ] < arr [ j ] ) :
                great += 1
        invcount += great * small
    return invcount
arr = [ 8 , 4 , 2 , 1 ]
n = len ( arr )
print ( " Inversion ▁ Count ▁ : " , getInvCount ( arr , n ) )

Index/key variables: i, j
Accumulator variables: great, invcount, small
Iterator variables: i, j
Python program:
def maxWater ( arr , n ) :
    res = 0 ;
    for i in range ( 1 , n - 1 ) :
        left = arr [ i ] ;
        for j in range ( i ) :
            left = max ( left , arr [ j ] ) ;
        right = arr [ i ] ;
        for j in range ( i + 1 , n ) :
            right = max ( right , arr [ j ] ) ;
        res = res + ( min ( left , right ) - arr [ i ] ) ;
    return res ;
if __name__ == " _ _ main _ _ " :
    arr = [ 0 , 1 , 0 , 2 , 1 , 0 , 1 , 3 , 2 , 1 , 2 , 1 ] ;
    n = len ( arr ) ;
    print ( maxWater ( arr , n ) ) ;

Index/key variables: i, j
Iterator variables: i, j
Python program:
def findWater ( arr , n ) :
    left = [ 0 ] * n
    right = [ 0 ] * n
    water = 0
    left [ 0 ] = arr [ 0 ]
    for i in range ( 1 , n ) :
        left [ i ] = max ( left [ i - 1 ] , arr [ i ] )
    right [ n - 1 ] = arr [ n - 1 ]
    for i in range ( n - 2 , - 1 , - 1 ) :
        right [ i ] = max ( right [ i + 1 ] , arr [ i ] ) ;
    for i in range ( 0 , n ) :
        water += min ( left [ i ] , right [ i ] ) - arr [ i ]
    return water
arr = [ 0 , 1 , 0 , 2 , 1 , 0 , 1 , 3 , 2 , 1 , 2 , 1 ]
n = len ( arr )
print ( " Maximum ▁ water ▁ that ▁ can ▁ be ▁ accumulated ▁ is " , findWater ( arr , n ) )

Index/key variables: i
Accumulator variables: water
Iterator variables: i
Python program:
def findWater ( arr , n ) :
    result = 0
    left_max = 0
    right_max = 0
    lo = 0
    hi = n - 1
    while ( lo <= hi ) :
        if ( arr [ lo ] < arr [ hi ] ) :
            if ( arr [ lo ] > left_max ) :
                left_max = arr [ lo ]
            else :
                result += left_max - arr [ lo ]
            lo += 1
        else :
            if ( arr [ hi ] > right_max ) :
                right_max = arr [ hi ]
            else :
                result += right_max - arr [ hi ]
            hi -= 1
    return result
arr = [ 0 , 1 , 0 , 2 , 1 , 0 , 1 , 3 , 2 , 1 , 2 , 1 ]
n = len ( arr )
print ( " Maximum ▁ water ▁ that ▁ can ▁ be ▁ accumulated ▁ is ▁ " , findWater ( arr , n ) )

Index/key variables: hi, lo
Accumulator variables: result