dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
charBuffer = [ ]
def processWords ( input ) :
    s = input . split ( " ▁ " )
    for values in s :
        charBuffer . append ( values [ 0 ] )
    return charBuffer
if __name__ == ' _ _ main _ _ ' :
    input = " geeks ▁ for ▁ geeks "
    print ( * processWords ( input ) , sep = " " )

Accumulator variables: charBuffer
Iterator variables: values
Python program:
def delCost ( s , cost ) :
    ans = 0
    forMax = { }
    forTot = { }
    for i in range ( len ( s ) ) :
        if s [ i ] not in forMax :
            forMax [ s [ i ] ] = cost [ i ]
        else :
            forMax [ s [ i ] ] = max ( cost [ i ] , forMax [ s [ i ] ] )
        if s [ i ] not in forTot :
            forTot [ s [ i ] ] = cost [ i ]
        else :
            forTot [ s [ i ] ] += cost [ i ]
    for i in forMax :
        ans += forTot [ i ] - forMax [ i ]
    return ans
string = " AAABBB "
cost = [ 1 , 2 , 3 , 4 , 5 , 6 ]
print ( delCost ( string , cost ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
MAX = 10000
divisors = [ [ ] for i in range ( MAX + 1 ) ]
def computeDivisors ( ) :
    global divisors
    global MAX
    for i in range ( 1 , MAX + 1 , 1 ) :
        for j in range ( i , MAX + 1 , i ) :
            divisors [ j ] . append ( i )
def getClosest ( val1 , val2 , target ) :
    if ( target - val1 >= val2 - target ) :
        return val2
    else :
        return val1
def findClosest ( arr , n , target ) :
    if ( target <= arr [ 0 ] ) :
        return arr [ 0 ]
    if ( target >= arr [ n - 1 ] ) :
        return arr [ n - 1 ]
    i = 0
    j = n
    mid = 0
    while ( i < j ) :
        mid = ( i + j ) // 2
        if ( arr [ mid ] == target ) :
            return arr [ mid ]
        if ( target < arr [ mid ] ) :
            if ( mid > 0 and target > arr [ mid - 1 ] ) :
                return getClosest ( arr [ mid - 1 ] , arr [ mid ] , target )
            j = mid
        else :
            if ( mid < n - 1 and target < arr [ mid + 1 ] ) :
                return getClosest ( arr [ mid ] , arr [ mid + 1 ] , target )
            i = mid + 1
    return arr [ mid ]
def printClosest ( N , X ) :
    global divisors
    computeDivisors ( )
    ans = findClosest ( divisors [ N ] , len ( divisors [ N ] ) , X )
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    N = 16
    X = 5
    printClosest ( N , X )

Index/key variables: N, j, mid
Iterator variables: i, j
Python program:
def maxMatch ( A , B ) :
    Aindex = { }
    diff = { }
    for i in range ( len ( A ) ) :
        Aindex [ A [ i ] ] = i
    for i in range ( len ( B ) ) :
        if i - Aindex [ B [ i ] ] < 0 :
            if len ( A ) + i - Aindex [ B [ i ] ] not in diff :
                diff [ len ( A ) + i - Aindex [ B [ i ] ] ] = 1
            else :
                diff [ len ( A ) + i - Aindex [ B [ i ] ] ] += 1
        else :
            if i - Aindex [ B [ i ] ] not in diff :
                diff [ i - Aindex [ B [ i ] ] ] = 1
            else :
                diff [ i - Aindex [ B [ i ] ] ] += 1
    return max ( diff . values ( ) )
A = [ 5 , 3 , 7 , 9 , 8 ]
B = [ 8 , 7 , 3 , 5 , 9 ]
print ( maxMatch ( A , B ) )

Index/key variables: i
Iterator variables: i
Python program:
def palindrome ( a , i , j ) :
    while ( i < j ) :
        if ( a [ i ] != a [ j ] ) :
            return False
        i += 1
        j -= 1
    return True
def findSubArray ( arr , k ) :
    n = len ( arr )
    for i in range ( n - k + 1 ) :
        if ( palindrome ( arr , i , i + k - 1 ) ) :
            return i
    return - 1
arr = [ 2 , 3 , 5 , 1 , 3 ]
k = 4
ans = findSubArray ( arr , k )
if ( ans == - 1 ) :
    print ( - 1 )
else :
    for i in range ( ans , ans + k ) :
        print ( arr [ i ] , end = " ▁ " )

Index/key variables: i, j
Iterator variables: i
Python program:
def isCrossed ( path ) :
    if ( len ( path ) == 0 ) :
        return bool ( False )
    ans = bool ( False )
    Set = set ( )
    x , y = 0 , 0
    Set . add ( ( x , y ) )
    for i in range ( len ( path ) ) :
        if ( path [ i ] == ' N ' ) :
            Set . add ( ( x , y ) )
            y = y + 1
        if ( path [ i ] == ' S ' ) :
            Set . add ( ( x , y ) )
            y = y - 1
        if ( path [ i ] == ' E ' ) :
            Set . add ( ( x , y ) )
            x = x + 1
        if ( path [ i ] == ' W ' ) :
            Set . add ( ( x , y ) )
            x = x - 1
        if ( x , y ) in Set :
            ans = bool ( True )
            break
    if ( ans ) :
        print ( " Crossed " )
    else :
        print ( " Not ▁ Crossed " )
path = " NESW "
isCrossed ( path )

Index/key variables: i
Accumulator variables: Set
Iterator variables: i
Python program:
from collections import deque
def maxWidth ( N , M , cost , s ) :
    adj = [ [ ] for i in range ( N ) ]
    for i in range ( M ) :
        adj [ s [ i ] [ 0 ] ] . append ( s [ i ] [ 1 ] )
    result = 0
    q = deque ( )
    q . append ( 0 )
    while ( len ( q ) > 0 ) :
        count = len ( q )
        result = max ( count , result )
        while ( count > 0 ) :
            temp = q . popleft ( )
            for i in adj [ temp ] :
                q . append ( i )
            count -= 1
    return result
if __name__ == ' _ _ main _ _ ' :
    N = 11
    M = 10
    edges = [ ]
    edges . append ( [ 0 , 1 ] )
    edges . append ( [ 0 , 2 ] )
    edges . append ( [ 0 , 3 ] )
    edges . append ( [ 1 , 4 ] )
    edges . append ( [ 1 , 5 ] )
    edges . append ( [ 3 , 6 ] )
    edges . append ( [ 4 , 7 ] )
    edges . append ( [ 6 , 1 ] )
    edges . append ( [ 6 , 8 ] )
    edges . append ( [ 6 , 9 ] )
    cost = [ 1 , 2 , - 1 , 3 , 4 , 5 , 8 , 2 , 6 , 12 , 7 ]
    print ( maxWidth ( N , M , cost , edges ) )

Index/key variables: i, temp
Accumulator variables: count, q
Iterator variables: i
Python program:
MAX = 10000000
isPrime = [ True ] * ( MAX + 1 )
primes = [ ]
def SieveOfEratosthenes ( ) :
    global isPrime
    p = 2
    while p * p <= MAX :
        if ( isPrime [ p ] == True ) :
            for i in range ( p * p , MAX + 1 , p ) :
                isPrime [ i ] = False
        p += 1
    for p in range ( 2 , MAX + 1 ) :
        if ( isPrime [ p ] ) :
            primes . append ( p )
def prime_search ( primes , diff ) :
    low = 0
    high = len ( primes ) - 1
    while ( low <= high ) :
        mid = ( low + high ) // 2
        if ( primes [ mid ] == diff ) :
            return primes [ mid ]
        elif ( primes [ mid ] < diff ) :
            low = mid + 1
        else :
            res = primes [ mid ]
            high = mid - 1
    return res
def minCost ( arr , n ) :
    SieveOfEratosthenes ( )
    res = 0
    for i in range ( 1 , n ) :
        if ( arr [ i ] < arr [ i - 1 ] ) :
            diff = arr [ i - 1 ] - arr [ i ]
            closest_prime = prime_search ( primes , diff )
            res += closest_prime
            arr [ i ] += closest_prime
    return res
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 1 , 5 , 4 , 3 ]
    n = 5
    print ( minCost ( arr , n ) )

Index/key variables: i, mid, p
Accumulator variables: primes, res
Iterator variables: i, p
Python program:
def count ( s ) :
    cnt = 0
    for c in s :
        if c == '0' :
            cnt += 1
    if ( cnt % 3 != 0 ) :
        return 0
    res = 0
    k = cnt // 3
    sum = 0
    mp = { }
    for i in range ( len ( s ) ) :
        if s [ i ] == '0' :
            sum += 1
        if ( sum == 2 * k and k in mp and i < len ( s ) - 1 and i > 0 ) :
            res += mp [ k ]
        if sum in mp :
            mp [ sum ] += 1
        else :
            mp [ sum ] = 1
    return res
if __name__ == " _ _ main _ _ " :
    st = "01010"
    print ( count ( st ) )

Index/key variables: i, k, sum
Accumulator variables: cnt, res
Iterator variables: c, i
Python program:
def canTransform ( str1 , str2 ) :
    s1 = " "
    s2 = " "
    for c in str1 :
        if ( c != ' C ' ) :
            s1 += c
    for c in str2 :
        if ( c != ' C ' ) :
            s2 += c
    if ( s1 != s2 ) :
        return False
    i = 0
    j = 0
    n = len ( str1 )
    while ( i < n and j < n ) :
        if ( str1 [ i ] == ' C ' ) :
            i += 1
        elif ( str2 [ j ] == ' C ' ) :
            j += 1
        else :
            if ( ( str1 [ i ] == ' A ' and i < j ) or ( str1 [ i ] == ' B ' and i > j ) ) :
                return False
            i += 1
            j += 1
    return True
if __name__ == ' _ _ main _ _ ' :
    str1 = " BCCABCBCA "
    str2 = " CBACCBBAC "
    if ( canTransform ( str1 , str2 ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i, j
Accumulator variables: s1, s2
Iterator variables: c
Python program:
def maxsubstringLength ( S , N ) :
    arr = [ 0 ] * N
    for i in range ( N ) :
        if ( S [ i ] == ' a ' or S [ i ] == ' e ' or S [ i ] == ' i ' or S [ i ] == ' o ' or S [ i ] == ' u ' ) :
            arr [ i ] = 1
        else :
            arr [ i ] = - 1
    maxLen = 0
    curr_sum = 0
    hash = { }
    for i in range ( N ) :
        curr_sum += arr [ i ]
        if ( curr_sum == 0 ) :
            maxLen = max ( maxLen , i + 1 )
        if ( curr_sum in hash . keys ( ) ) :
            maxLen = max ( maxLen , i - hash [ curr_sum ] )
        else :
            hash [ curr_sum ] = i
    return maxLen
S = " geeksforgeeks "
n = len ( S )
print ( maxsubstringLength ( S , n ) )

Index/key variables: curr_sum, i
Iterator variables: i
Python program:
mat = [ [ 0 for x in range ( 1001 ) ] for y in range ( 1001 ) ]
dx = [ 0 , - 1 , - 1 , - 1 , 0 , 1 , 1 , 1 ]
dy = [ 1 , 1 , 0 , - 1 , - 1 , - 1 , 0 , 1 ]
def FindMinimumDistance ( ) :
    global x , y , r , c
    q = [ ]
    q . append ( [ x , y ] )
    mat [ x ] [ y ] = 0
    while ( len ( q ) != 0 ) :
        x = q [ 0 ] [ 0 ]
        y = q [ 0 ] [ 1 ]
        q . pop ( 0 )
        for i in range ( 8 ) :
            a = x + dx [ i ]
            b = y + dy [ i ]
            if ( a < 0 or a >= r or b >= c or b < 0 ) :
                continue
            if ( mat [ a ] [ b ] == 0 ) :
                mat [ a ] [ b ] = mat [ x ] [ y ] + 1
                q . append ( [ a , b ] )
r = 5
c = 5
x = 1
y = 1
t = x
l = y
mat [ x ] [ y ] = 0
FindMinimumDistance ( )
mat [ t ] [ l ] = 0
for i in range ( r ) :
    for j in range ( c ) :
        print ( mat [ i ] [ j ] , end = " ▁ " )
    print ( )

Index/key variables: a, b, i, j, l, t, x, y
Accumulator variables: q
Iterator variables: i, j
Python program:
def minOperations ( S , K ) :
    ans = 0
    for i in range ( K ) :
        zero , one = 0 , 0
        for j in range ( i , len ( S ) , K ) :
            if ( S [ j ] == '0' ) :
                zero += 1
            else :
                one += 1
        ans += min ( zero , one )
    return ans
if __name__ == ' _ _ main _ _ ' :
    s = "110100101"
    K = 3
    print ( minOperations ( s , K ) )

Index/key variables: j
Accumulator variables: ans, one, zero
Iterator variables: i, j
Python program:
def missingElement ( arr , n ) :
    max_ele = arr [ 0 ]
    min_ele = arr [ 0 ]
    x = 0
    d = 0
    for i in range ( n ) :
        if ( arr [ i ] > max_ele ) :
            max_ele = arr [ i ]
        if ( arr [ i ] < min_ele ) :
            min_ele = arr [ i ]
    d = ( max_ele - min_ele ) // n
    for i in range ( n ) :
        x = x ^ arr [ i ]
    for i in range ( n + 1 ) :
        x = x ^ ( min_ele + ( i * d ) )
    return x
if __name__ == ' _ _ main _ _ ' :
    arr = [ 12 , 3 , 6 , 15 , 18 ]
    n = len ( arr )
    element = missingElement ( arr , n )
    print ( element )

Index/key variables: i
Iterator variables: i
Python program:
def Printksubstring ( str1 , n , k ) :
    total = int ( ( n * ( n + 1 ) ) / 2 )
    if ( k > total ) :
        print ( " - 1" )
        return
    substring = [ 0 for i in range ( n + 1 ) ]
    substring [ 0 ] = 0
    temp = n
    for i in range ( 1 , n + 1 , 1 ) :
        substring [ i ] = substring [ i - 1 ] + temp
        temp -= 1
    l = 1
    h = n
    start = 0
    while ( l <= h ) :
        m = int ( ( l + h ) / 2 )
        if ( substring [ m ] > k ) :
            start = m
            h = m - 1
        elif ( substring [ m ] < k ) :
            l = m + 1
        else :
            start = m
            break
    end = n - ( substring [ start ] - k )
    for i in range ( start - 1 , end ) :
        print ( str1 [ i ] , end = " " )
if __name__ == ' _ _ main _ _ ' :
    str1 = " abc "
    k = 4
    n = len ( str1 )
    Printksubstring ( str1 , n , k )

Index/key variables: i, m, start
Accumulator variables: temp
Iterator variables: i
Python program:
def LowerInsertionPoint ( arr , n , X ) :
    if ( X < arr [ 0 ] ) :
        return 0 ;
    elif ( X > arr [ n - 1 ] ) :
        return n
    lowerPnt = 0
    i = 1
    while ( i < n and arr [ i ] < X ) :
        lowerPnt = i
        i = i * 2
    while ( lowerPnt < n and arr [ lowerPnt ] < X ) :
        lowerPnt += 1
    return lowerPnt
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 3 , 4 , 4 , 5 , 6 , 7 , 9 ]
    n = len ( arr )
    X = 4
    print ( LowerInsertionPoint ( arr , n , X ) )

Index/key variables: i, lowerPnt
Python program:
def getCount ( M , N ) :
    count = 0 ;
    if ( M == 1 ) :
        return N ;
    if ( N == 1 ) :
        return M ;
    if ( N > M ) :
        for i in range ( 1 , M + 1 ) :
            numerator = N * i - N + M - i ;
            denominator = M - 1 ;
            if ( numerator % denominator == 0 ) :
                j = numerator / denominator ;
                if ( j >= 1 and j <= N ) :
                    count += 1 ;
    else :
        for j in range ( 1 , N + 1 ) :
            numerator = M * j - M + N - j ;
            denominator = N - 1 ;
            if ( numerator % denominator == 0 ) :
                i = numerator / denominator ;
                if ( i >= 1 and i <= M ) :
                    count += 1 ;
    return count ;
if __name__ == ' _ _ main _ _ ' :
    M , N = 3 , 5 ;
    print ( getCount ( M , N ) ) ;

Accumulator variables: count
Iterator variables: i, j
Python program:
import sys
def swapElement ( arr1 , arr2 , n ) :
    wrongIdx = 0 ;
    for i in range ( 1 , n ) :
        if ( arr1 [ i ] < arr1 [ i - 1 ] ) :
            wrongIdx = i
    maximum = - ( sys . maxsize - 1 )
    maxIdx = - 1
    res = False
    for i in range ( n ) :
        if ( arr2 [ i ] > maximum and arr2 [ i ] >= arr1 [ wrongIdx - 1 ] ) :
            if ( wrongIdx + 1 <= n - 1 and arr2 [ i ] <= arr1 [ wrongIdx + 1 ] ) :
                maximum = arr2 [ i ]
                maxIdx = i
                res = True
    if ( res ) :
        ( arr1 [ wrongIdx ] , arr2 [ maxIdx ] ) = ( arr2 [ maxIdx ] , arr1 [ wrongIdx ] )
    return res
def getSortedArray ( arr1 , arr2 , n ) :
    if ( swapElement ( arr1 , arr2 , n ) ) :
        for i in range ( n ) :
            print ( arr1 [ i ] , end = " ▁ " )
    else :
        print ( " Not ▁ Possible " )
if __name__ == " _ _ main _ _ " :
    arr1 = [ 1 , 3 , 7 , 4 , 10 ]
    arr2 = [ 2 , 1 , 6 , 8 , 9 ]
    n = len ( arr1 )
    getSortedArray ( arr1 , arr2 , n )

Index/key variables: i, maxIdx, wrongIdx
Iterator variables: i
Boolean variables: res
Python program:
def transpose ( mat , row , col ) :
    tr = [ [ 0 for i in range ( row ) ] for i in range ( col ) ]
    for i in range ( row ) :
        for j in range ( col ) :
            tr [ j ] [ i ] = mat [ i ] [ j ]
    return tr
def RowWiseSort ( B ) :
    for i in range ( len ( B ) ) :
        B [ i ] = sorted ( B [ i ] )
    return B
def sortCol ( mat , N , M ) :
    B = transpose ( mat , N , M )
    B = RowWiseSort ( B )
    mat = transpose ( B , M , N )
    for i in range ( N ) :
        for j in range ( M ) :
            print ( mat [ i ] [ j ] , end = " ▁ " )
        print ( )
if __name__ == ' _ _ main _ _ ' :
    mat = [ [ 1 , 6 , 10 ] , [ 8 , 5 , 9 ] , [ 9 , 4 , 15 ] , [ 7 , 3 , 60 ] ]
    N = len ( mat )
    M = len ( mat [ 0 ] )
    sortCol ( mat , N , M )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def largestArea ( N , M , H , V , h , v ) :
    s1 = set ( [ ] ) ;
    s2 = set ( [ ] ) ;
    for i in range ( 1 , N + 2 ) :
        s1 . add ( i ) ;
    for i in range ( 1 , M + 2 ) :
        s2 . add ( i ) ;
    for i in range ( h ) :
        s1 . remove ( H [ i ] ) ;
    for i in range ( v ) :
        s2 . remove ( V [ i ] ) ;
    list1 = [ 0 ] * len ( s1 )
    list2 = [ 0 ] * len ( s2 ) ;
    i = 0 ;
    for it1 in s1 :
        list1 [ i ] = it1 ;
        i += 1
    i = 0 ;
    for it2 in s2 :
        list2 [ i ] = it2
        i += 1
    list1 . sort ( ) ;
    list2 . sort ( ) ;
    maxH = 0
    p1 = 0
    maxV = 0
    p2 = 0 ;
    for j in range ( len ( s1 ) ) :
        maxH = max ( maxH , list1 [ j ] - p1 ) ;
        p1 = list1 [ j ] ;
    for j in range ( len ( s2 ) ) :
        maxV = max ( maxV , list2 [ j ] - p2 ) ;
        p2 = list2 [ j ] ;
    print ( ( maxV * maxH ) )
if __name__ == " _ _ main _ _ " :
    N = 3
    M = 3 ;
    H = [ 2 ]
    V = [ 2 ] ;
    h = len ( H )
    v = len ( V ) ;
    largestArea ( N , M , H , V , h , v ) ;

Index/key variables: i, j
Accumulator variables: s1, s2
Iterator variables: i, it1, it2, j
Python program:
def minSteps ( A , B , M , N ) :
    if ( A [ 0 ] > B [ 0 ] ) :
        return 0
    if ( B [ 0 ] > A [ 0 ] ) :
        return 1
    if ( M <= N and A [ 0 ] == B [ 0 ] and A . count ( A [ 0 ] ) == M and B . count ( B [ 0 ] ) == N ) :
        return - 1
    for i in range ( 1 , N ) :
        if ( B [ i ] > B [ 0 ] ) :
            return 1
    for i in range ( 1 , M ) :
        if ( A [ i ] < A [ 0 ] ) :
            return 1
    for i in range ( 1 , M ) :
        if ( A [ i ] > A [ 0 ] ) :
            A [ 0 ] , B [ i ] = B [ i ] , A [ 0 ]
            A [ 0 ] , B [ 0 ] = B [ 0 ] , A [ 0 ]
            return 2
    for i in range ( 1 , N ) :
        if ( B [ i ] < B [ 0 ] ) :
            A [ 0 ] , B [ i ] = B [ i ] , A [ 0 ]
            A [ 0 ] , B [ 0 ] = B [ 0 ] , A [ 0 ]
            return 2
    return 0
if __name__ == ' _ _ main _ _ ' :
    A = " adsfd "
    B = " dffff "
    M = len ( A )
    N = len ( B )
    print ( minSteps ( A , B , M , N ) )

Index/key variables: i
Iterator variables: i
Python program:
maxN = 201 ;
n1 , n2 , n3 = 0 , 0 , 0 ;
dp = [ [ [ 0 for i in range ( maxN ) ] for j in range ( maxN ) ] for j in range ( maxN ) ] ;
def getMaxSum ( i , j , k , arr1 , arr2 , arr3 ) :
    cnt = 0 ;
    if ( i >= n1 ) :
        cnt += 1 ;
    if ( j >= n2 ) :
        cnt += 1 ;
    if ( k >= n3 ) :
        cnt += 1 ;
    if ( cnt >= 2 ) :
        return 0 ;
    if ( dp [ i ] [ j ] [ k ] != - 1 ) :
        return dp [ i ] [ j ] [ k ] ;
    ans = 0 ;
    if ( i < n1 and j < n2 ) :
        ans = max ( ans , getMaxSum ( i + 1 , j + 1 , k , arr1 , arr2 , arr3 ) + arr1 [ i ] * arr2 [ j ] ) ;
    if ( i < n1 and k < n3 ) :
        ans = max ( ans , getMaxSum ( i + 1 , j , k + 1 , arr1 , arr2 , arr3 ) + arr1 [ i ] * arr3 [ k ] ) ;
    if ( j < n2 and k < n3 ) :
        ans = max ( ans , getMaxSum ( i , j + 1 , k + 1 , arr1 , arr2 , arr3 ) + arr2 [ j ] * arr3 [ k ] ) ;
    dp [ i ] [ j ] [ k ] = ans ;
    return dp [ i ] [ j ] [ k ] ;
def reverse ( tmp ) :
    i , k , t = 0 , 0 , 0 ;
    n = len ( tmp ) ;
    for i in range ( n // 2 ) :
        t = tmp [ i ] ;
        tmp [ i ] = tmp [ n - i - 1 ] ;
        tmp [ n - i - 1 ] = t ;
def maxProductSum ( arr1 , arr2 , arr3 ) :
    for i in range ( len ( dp ) ) :
        for j in range ( len ( dp [ 0 ] ) ) :
            for k in range ( len ( dp [ j ] [ 0 ] ) ) :
                dp [ i ] [ j ] [ k ] = - 1 ;
    arr1 . sort ( ) ;
    reverse ( arr1 ) ;
    arr2 . sort ( ) ;
    reverse ( arr2 ) ;
    arr3 . sort ( ) ;
    reverse ( arr3 ) ;
    return getMaxSum ( 0 , 0 , 0 , arr1 , arr2 , arr3 ) ;
if __name__ == ' _ _ main _ _ ' :
    n1 = 2 ;
    arr1 = [ 3 , 5 ] ;
    n2 = 2 ;
    arr2 = [ 2 , 1 ] ;
    n3 = 3 ;
    arr3 = [ 4 , 3 , 5 ] ;
    print ( maxProductSum ( arr1 , arr2 , arr3 ) ) ;

Index/key variables: i, j, k
Iterator variables: i, j, k
Python program:
def findTriplet ( arr , N ) :
    arr . sort ( )
    i = N - 1
    while i - 2 >= 0 :
        if ( arr [ i - 2 ] + arr [ i - 1 ] > arr [ i ] ) :
            flag = 1
            break
        i -= 1
    if ( flag ) :
        print ( arr [ i - 2 ] , arr [ i - 1 ] , arr [ i ] )
    else :
        print ( - 1 )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 2 , 10 , 3 , 5 ]
    N = len ( arr )
    findTriplet ( arr , N )

Index/key variables: i
Python program:
def numberofpairs ( arr , N ) :
    answer = 0
    arr . sort ( )
    minDiff = 10000000
    for i in range ( 0 , N - 1 ) :
        minDiff = min ( minDiff , arr [ i + 1 ] - arr [ i ] )
    for i in range ( 0 , N - 1 ) :
        if arr [ i + 1 ] - arr [ i ] == minDiff :
            answer += 1
    return answer
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 2 , 1 , 3 ]
    N = len ( arr )
    print ( numberofpairs ( arr , N ) )

Index/key variables: i
Accumulator variables: answer
Iterator variables: i
Python program:
max_length = 0
store = [ ]
ans = [ ]
def find_max_length ( arr , index , sum , k ) :
    global max_length
    sum = sum + arr [ index ]
    store . append ( arr [ index ] )
    if ( sum == k ) :
        if ( max_length < len ( store ) ) :
            max_length = len ( store )
            ans = store
    for i in range ( index + 1 , len ( arr ) ) :
        if ( sum + arr [ i ] <= k ) :
            find_max_length ( arr , i , sum , k )
            store . pop ( )
        else :
            return
    return
def longestSubsequence ( arr , n , k ) :
    arr . sort ( )
    for i in range ( n ) :
        if ( max_length >= n - i ) :
            break
        store . clear ( )
        find_max_length ( arr , i , 0 , k )
    return max_length
if __name__ == " _ _ main _ _ " :
    arr = [ - 3 , 0 , 1 , 1 , 2 ]
    n = len ( arr )
    k = 1
    print ( longestSubsequence ( arr , n , k ) )

Index/key variables: i, index
Iterator variables: i
Python program:
def sortArray ( A , N ) :
    if ( N % 4 == 0 or N % 4 == 1 ) :
        for i in range ( N // 2 ) :
            x = i
            if ( i % 2 == 0 ) :
                y = N - i - 2
                z = N - i - 1
            A [ z ] = A [ y ]
            A [ y ] = A [ x ]
            A [ x ] = x + 1
        print ( " Sorted ▁ Array : ▁ " , end = " " )
        for i in range ( N ) :
            print ( A [ i ] , end = " ▁ " )
    else :
        print ( " - 1" )
A = [ 5 , 4 , 3 , 2 , 1 ]
N = len ( A )
sortArray ( A , N )

Index/key variables: i, x, y, z
Iterator variables: i
Python program:
def findK ( arr , size , N ) :
    arr = sorted ( arr )
    temp_sum = 0
    for i in range ( size ) :
        temp_sum += arr [ i ]
        if ( N - temp_sum == arr [ i ] * ( size - i - 1 ) ) :
            return arr [ i ]
    return - 1
arr = [ 3 , 1 , 10 , 4 , 8 ]
size = len ( arr )
N = 16
print ( findK ( arr , size , N ) )

Index/key variables: i
Accumulator variables: temp_sum
Iterator variables: i
Python program:
def existsTriplet ( a , b , c , x , l1 , l2 , l3 ) :
    if ( l2 <= l1 and l2 <= l3 ) :
        l1 , l2 = l2 , l1
        a , b = b , a
    elif ( l3 <= l1 and l3 <= l2 ) :
        l1 , l3 = l3 , l1
        a , c = c , a
    for i in range ( l1 ) :
        j = 0
        k = l3 - 1
        while ( j < l2 and k >= 0 ) :
            if ( a [ i ] + b [ j ] + c [ k ] == x ) :
                return True
            if ( a [ i ] + b [ j ] + c [ k ] < x ) :
                j += 1
            else :
                k -= 1
    return False
a = [ 2 , 7 , 8 , 10 , 15 ]
b = [ 1 , 6 , 7 , 8 ]
c = [ 4 , 5 , 5 ]
l1 = len ( a )
l2 = len ( b )
l3 = len ( c )
x = 14
if ( existsTriplet ( a , b , c , x , l1 , l2 , l3 ) ) :
    print ( " Yes " )
else :
    print ( " No " )

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