dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
from collections import deque
MAX = 500
N = 3
M = 4
g = [ [ ] for i in range ( MAX ) ]
n , m = 0 , 0
def createGraph ( ) :
    global g , n , m
    k = 1
    for i in range ( 1 , n + 1 ) :
        for j in range ( 1 , m + 1 ) :
            if ( i == n ) :
                if ( j != m ) :
                    g [ k ] . append ( k + 1 )
                    g [ k + 1 ] . append ( k )
            elif ( j == m ) :
                g [ k ] . append ( k + m )
                g [ k + m ] . append ( k )
            else :
                g [ k ] . append ( k + 1 )
                g [ k + 1 ] . append ( k )
                g [ k ] . append ( k + m )
                g [ k + m ] . append ( k )
            k += 1
def bfs ( visit , dist , q ) :
    global g
    while ( len ( q ) > 0 ) :
        temp = q . popleft ( )
        for i in g [ temp ] :
            if ( visit [ i ] != 1 ) :
                dist [ i ] = min ( dist [ i ] , dist [ temp ] + 1 )
                q . append ( i )
                visit [ i ] = 1
    return dist
def prt ( dist ) :
    c = 1
    for i in range ( 1 , n * m + 1 ) :
        print ( dist [ i ] , end = " ▁ " )
        if ( c % m == 0 ) :
            print ( )
        c += 1
def findMinDistance ( mat ) :
    global g , n , m
    n , m = N , M
    createGraph ( )
    dist = [ 0 ] * MAX
    visit = [ 0 ] * MAX
    for i in range ( 1 , M * N + 1 ) :
        dist [ i ] = 10 ** 9
        visit [ i ] = 0
    k = 1
    q = deque ( )
    for i in range ( N ) :
        for j in range ( M ) :
            if ( mat [ i ] [ j ] == 1 ) :
                dist [ k ] = 0
                visit [ k ] = 1
                q . append ( k )
            k += 1
    dist = bfs ( visit , dist , q )
    prt ( dist )
if __name__ == ' _ _ main _ _ ' :
    mat = [ [ 0 , 0 , 0 , 1 ] , [ 0 , 0 , 1 , 1 ] , [ 0 , 1 , 1 , 0 ] ]
    findMinDistance ( mat )

Index/key variables: i, j, k, temp
Accumulator variables: c, q
Iterator variables: i, j
Python program:
def printFirstNegativeInteger ( arr , n , k ) :
    for i in range ( 0 , ( n - k + 1 ) ) :
        flag = False
        for j in range ( 0 , k ) :
            if ( arr [ i + j ] < 0 ) :
                print ( arr [ i + j ] , end = " ▁ " )
                flag = True
                break
        if ( not ( flag ) ) :
            print ( "0" , end = " ▁ " )
arr = [ 12 , - 1 , - 7 , 8 , - 15 , 30 , 16 , 28 ]
n = len ( arr )
k = 3
printFirstNegativeInteger ( arr , n , k )

Iterator variables: i, j
Boolean variables: flag
Python program:
from collections import deque
def printFirstNegativeInteger ( arr , n , k ) :
    Di = deque ( )
    for i in range ( k ) :
        if ( arr [ i ] < 0 ) :
            Di . append ( i ) ;
    for i in range ( k , n ) :
        if ( not Di ) :
            print ( 0 , end = ' ▁ ' )
        else :
            print ( arr [ Di [ 0 ] ] , end = ' ▁ ' ) ;
        while Di and Di [ 0 ] <= ( i - k ) :
            Di . popleft ( )
        if ( arr [ i ] < 0 ) :
            Di . append ( i ) ;
    if not Di :
        print ( 0 )
    else :
        print ( arr [ Di [ 0 ] ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ 12 , - 1 , - 7 , 8 , - 15 , 30 , 16 , 28 ]
    n = len ( arr )
    k = 3
    printFirstNegativeInteger ( arr , n , k ) ;

Index/key variables: i
Accumulator variables: Di
Iterator variables: i
Python program:
def printFirstNegativeInteger ( arr , k ) :
    firstNegativeIndex = 0
    for i in range ( k - 1 , len ( arr ) ) :
        while firstNegativeIndex < i and ( firstNegativeIndex <= i - k or arr [ firstNegativeIndex ] > 0 ) :
            firstNegativeIndex += 1
        firstNegativeElement = arr [ firstNegativeIndex ] if arr [ firstNegativeIndex ] < 0 else 0
        print ( firstNegativeElement , end = ' ▁ ' )
if __name__ == " _ _ main _ _ " :
    arr = [ 12 , - 1 , - 7 , 8 , - 15 , 30 , 16 , 28 ]
    k = 3
    printFirstNegativeInteger ( arr , k )

Index/key variables: firstNegativeIndex
Iterator variables: i
Python program:
def areAnagrams ( root1 , root2 ) :
    if ( root1 == None and root2 == None ) :
        return True
    if ( root1 == None or root2 == None ) :
        return False
    q1 = [ ]
    q2 = [ ]
    q1 . append ( root1 )
    q2 . append ( root2 )
    while ( 1 ) :
        n1 = len ( q1 )
        n2 = len ( q2 )
        if ( n1 != n2 ) :
            return False
        if ( n1 == 0 ) :
            break
        curr_level1 = [ ]
        curr_level2 = [ ]
        while ( n1 > 0 ) :
            node1 = q1 [ 0 ]
            q1 . pop ( 0 )
            if ( node1 . left != None ) :
                q1 . append ( node1 . left )
            if ( node1 . right != None ) :
                q1 . append ( node1 . right )
            n1 -= 1
            node2 = q2 [ 0 ]
            q2 . pop ( 0 )
            if ( node2 . left != None ) :
                q2 . append ( node2 . left )
            if ( node2 . right != None ) :
                q2 . append ( node2 . right )
            curr_level1 . append ( node1 . data )
            curr_level2 . append ( node2 . data )
        curr_level1 . sort ( )
        curr_level2 . sort ( )
        if ( curr_level1 != curr_level2 ) :
            return False
    return True
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
if __name__ == ' _ _ main _ _ ' :
    root1 = newNode ( 1 )
    root1 . left = newNode ( 3 )
    root1 . right = newNode ( 2 )
    root1 . right . left = newNode ( 5 )
    root1 . right . right = newNode ( 4 )
    root2 = newNode ( 1 )
    root2 . left = newNode ( 2 )
    root2 . right = newNode ( 3 )
    root2 . left . left = newNode ( 4 )
    root2 . left . right = newNode ( 5 )
    if areAnagrams ( root1 , root2 ) :
        print ( " Yes " )
    else :
        print ( " No " )

Accumulator variables: curr_level1, curr_level2, n1, q1, q2
Class/struct names: newNode
Python program:
preIndex = 0
class node :
    def __init__ ( self , x ) :
        self . data = x
        self . left = None
        self . right = None
def search ( arr , strt , end , value ) :
    for i in range ( strt , end + 1 ) :
        if ( arr [ i ] == value ) :
            return i
def buildTree ( inn , pre , inStrt , inEnd ) :
    global preIndex
    if ( inStrt > inEnd ) :
        return None
    tNode = node ( pre [ preIndex ] )
    preIndex += 1
    if ( inStrt == inEnd ) :
        return tNode
    inIndex = search ( inn , inStrt , inEnd , tNode . data )
    tNode . left = buildTree ( inn , pre , inStrt , inIndex - 1 )
    tNode . right = buildTree ( inn , pre , inIndex + 1 , inEnd )
    return tNode
def checkPostorder ( node , postOrder , index ) :
    if ( node == None ) :
        return index
    index = checkPostorder ( node . left , postOrder , index )
    index = checkPostorder ( node . right , postOrder , index )
    if ( node . data == postOrder [ index ] ) :
        index += 1
    else :
        return - 1
    return index
if __name__ == ' _ _ main _ _ ' :
    inOrder = [ 4 , 2 , 5 , 1 , 3 ]
    preOrder = [ 1 , 2 , 4 , 5 , 3 ]
    postOrder = [ 4 , 5 , 2 , 3 , 1 ]
    lenn = len ( inOrder )
    root = buildTree ( inOrder , preOrder , 0 , lenn - 1 )
    index = checkPostorder ( root , postOrder , 0 )
    if ( index == lenn ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i, index, preIndex
Iterator variables: i
Class/struct names: node
Python program:
def isChangeable ( notes , n ) :
    fiveCount = 0
    tenCount = 0
    for i in range ( n ) :
        if ( notes [ i ] == 5 ) :
            fiveCount += 1
        elif ( notes [ i ] == 10 ) :
            if ( fiveCount > 0 ) :
                fiveCount -= 1
                tenCount += 1
            else :
                return 0
        else :
            if ( fiveCount > 0 and tenCount > 0 ) :
                fiveCount -= 1
                tenCount -= 1
            elif ( fiveCount >= 3 ) :
                fiveCount -= 3
            else :
                return 0
    return 1
a = [ 5 , 5 , 5 , 10 , 20 ]
n = len ( a )
if ( isChangeable ( a , n ) ) :
    print ( " YES " )
else :
    print ( " NO " )

Index/key variables: i
Accumulator variables: fiveCount, tenCount
Iterator variables: i
Python program:
MAX = 1000
has = [ [ 0 for i in range ( 2 ) ] for j in range ( MAX + 1 ) ]
def search ( X ) :
    if X >= 0 :
        return has [ X ] [ 0 ] == 1
    X = abs ( X )
    return has [ X ] [ 1 ] == 1
def insert ( a , n ) :
    for i in range ( 0 , n ) :
        if a [ i ] >= 0 :
            has [ a [ i ] ] [ 0 ] = 1
        else :
            has [ abs ( a [ i ] ) ] [ 1 ] = 1
if __name__ == " _ _ main _ _ " :
    a = [ - 1 , 9 , - 5 , - 8 , - 5 , - 2 ]
    n = len ( a )
    insert ( a , n )
    X = - 5
    if search ( X ) == True :
        print ( " Present " )
    else :
        print ( " Not ▁ Present " )

Index/key variables: X, i
Iterator variables: i
Python program:
def isMinHeap ( level , n ) :
    for i in range ( int ( n / 2 ) - 1 , - 1 , - 1 ) :
        if level [ i ] > level [ 2 * i + 1 ] :
            return False
        if 2 * i + 2 < n :
            if level [ i ] > level [ 2 * i + 2 ] :
                return False
    return True
if __name__ == ' _ _ main _ _ ' :
    level = [ 10 , 15 , 14 , 25 , 30 ]
    n = len ( level )
    if isMinHeap ( level , n ) :
        print ( " True " )
    else :
        print ( " False " )

Index/key variables: i
Iterator variables: i
Python program:
def minDelete ( arr , n ) :
    freq = { }
    for i in range ( n ) :
        if arr [ i ] in freq :
            freq [ arr [ i ] ] += 1
        else :
            freq [ arr [ i ] ] = 1 ;
    max_freq = 0 ;
    for i , j in freq . items ( ) :
        max_freq = max ( max_freq , j ) ;
    return n - max_freq ;
arr = [ 4 , 3 , 4 , 4 , 2 , 4 ] ;
n = len ( arr )
print ( minDelete ( arr , n ) ) ;

Index/key variables: i
Iterator variables: i, j
Python program:
from collections import defaultdict
def minOperation ( arr , n ) :
    Hash = defaultdict ( lambda : 0 )
    for i in range ( 0 , n ) :
        Hash [ arr [ i ] ] += 1
    max_count = 0
    for i in Hash :
        if max_count < Hash [ i ] :
            max_count = Hash [ i ]
    return n - max_count
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 5 , 2 , 1 , 3 , 2 , 1 ]
    n = len ( arr )
    print ( minOperation ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def checkDuplicatesWithinK ( arr , n , k ) :
    myset = [ ]
    for i in range ( n ) :
        if arr [ i ] in myset :
            return True
        myset . append ( arr [ i ] )
        if ( i >= k ) :
            myset . remove ( arr [ i - k ] )
    return False
if __name__ == " _ _ main _ _ " :
    arr = [ 10 , 5 , 3 , 4 , 3 , 5 , 6 ]
    n = len ( arr )
    if ( checkDuplicatesWithinK ( arr , n , 3 ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Accumulator variables: myset
Iterator variables: i
Python program:
def findDuplicates ( arr , Len ) :
    ifPresent = False
    a1 = [ ]
    for i in range ( Len - 1 ) :
        for j in range ( i + 1 , Len ) :
            if ( arr [ i ] == arr [ j ] ) :
                if arr [ i ] in a1 :
                    break
                else :
                    a1 . append ( arr [ i ] )
                    ifPresent = True
    if ( ifPresent ) :
        print ( a1 , end = " ▁ " )
    else :
        print ( " No ▁ duplicates ▁ present ▁ in ▁ arrays " )
arr = [ 12 , 11 , 40 , 12 , 5 , 6 , 5 , 12 , 11 ]
n = len ( arr )
findDuplicates ( arr , n )

Index/key variables: i, j
Accumulator variables: a1
Iterator variables: i, j
Boolean variables: ifPresent
Python program:
class Node :
    def __init__ ( self , x ) :
        self . data = x
        self . left = self . right = None
    def isLeaf ( self ) :
        return ( self . left == None and self . right == None )
def isSame ( root1 , root2 ) :
    s1 = [ ]
    s2 = [ ]
    s1 . append ( root1 )
    s2 . append ( root2 )
    while ( len ( s1 ) != 0 or len ( s2 ) != 0 ) :
        if ( len ( s1 ) == 0 or len ( s2 ) == 0 ) :
            return False
        temp1 = s1 . pop ( - 1 )
        while ( temp1 != None and not temp1 . isLeaf ( ) ) :
            if ( temp1 . right != None ) :
                s1 . append ( temp1 . right )
            if ( temp1 . left != None ) :
                s1 . append ( temp1 . left )
                temp1 = s1 . pop ( - 1 )
        temp2 = s2 . pop ( - 1 )
        while ( temp2 != None and not temp2 . isLeaf ( ) ) :
            if ( temp2 . right != None ) :
                s2 . append ( temp2 . right )
            if ( temp2 . left != None ) :
                s2 . append ( temp2 . left )
            temp2 = s2 . pop ( - 1 )
        if ( temp1 == None and temp2 != None ) :
            return False
        if ( temp1 != None and temp2 == None ) :
            return False
        if ( temp1 != None and temp2 != None ) :
            if ( temp1 . data != temp2 . data ) :
                return False
    return True
if __name__ == ' _ _ main _ _ ' :
    root1 = Node ( 1 )
    root1 . left = Node ( 2 )
    root1 . right = Node ( 3 )
    root1 . left . left = Node ( 4 )
    root1 . right . left = Node ( 6 )
    root1 . right . right = Node ( 7 )
    root2 = Node ( 0 )
    root2 . left = Node ( 1 )
    root2 . right = Node ( 5 )
    root2 . left . right = Node ( 4 )
    root2 . right . left = Node ( 6 )
    root2 . right . right = Node ( 7 )
    if ( isSame ( root1 , root2 ) ) :
        print ( " Same " )
    else :
        print ( " Not ▁ Same " )

Accumulator variables: s1, s2
Class/struct names: Node
Python program:
def mostFrequent ( arr , n ) :
    arr . sort ( )
    max_count = 1 ; res = arr [ 0 ] ; curr_count = 1
    for i in range ( 1 , n ) :
        if ( arr [ i ] == arr [ i - 1 ] ) :
            curr_count += 1
        else :
            if ( curr_count > max_count ) :
                max_count = curr_count
                res = arr [ i - 1 ]
            curr_count = 1
    if ( curr_count > max_count ) :
        max_count = curr_count
        res = arr [ n - 1 ]
    return res
arr = [ 1 , 5 , 2 , 1 , 3 , 2 , 1 ]
n = len ( arr )
print ( mostFrequent ( arr , n ) )

Index/key variables: i
Accumulator variables: curr_count
Iterator variables: i
Python program:
import math as mt
def mostFrequent ( arr , n ) :
    Hash = dict ( )
    for i in range ( n ) :
        if arr [ i ] in Hash . keys ( ) :
            Hash [ arr [ i ] ] += 1
        else :
            Hash [ arr [ i ] ] = 1
    max_count = 0
    res = - 1
    for i in Hash :
        if ( max_count < Hash [ i ] ) :
            res = i
            max_count = Hash [ i ]
    return res
arr = [ 1 , 5 , 2 , 1 , 3 , 2 , 1 ]
n = len ( arr )
print ( mostFrequent ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def smallestSubsegment ( a , n ) :
    left = dict ( )
    count = dict ( )
    mx = 0
    mn , strindex = 0 , 0
    for i in range ( n ) :
        x = a [ i ]
        if ( x not in count . keys ( ) ) :
            left [ x ] = i
            count [ x ] = 1
        else :
            count [ x ] += 1
        if ( count [ x ] > mx ) :
            mx = count [ x ]
            mn = i - left [ x ] + 1
            strindex = left [ x ]
        elif ( count [ x ] == mx and i - left [ x ] + 1 < mn ) :
            mn = i - left [ x ] + 1
            strindex = left [ x ]
    for i in range ( strindex , strindex + mn ) :
        print ( a [ i ] , end = " ▁ " )
A = [ 1 , 2 , 2 , 2 , 1 ]
n = len ( A )
smallestSubsegment ( A , n )

Index/key variables: i, x
Iterator variables: i
Python program:
def findSymPairs ( arr , row ) :
    hM = dict ( )
    for i in range ( row ) :
        first = arr [ i ] [ 0 ]
        sec = arr [ i ] [ 1 ]
        if ( sec in hM . keys ( ) and hM [ sec ] == first ) :
            print ( " ( " , sec , " , " , first , " ) " )
        else :
            hM [ first ] = sec
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 0 for i in range ( 2 ) ] for i in range ( 5 ) ]
    arr [ 0 ] [ 0 ] , arr [ 0 ] [ 1 ] = 11 , 20
    arr [ 1 ] [ 0 ] , arr [ 1 ] [ 1 ] = 30 , 40
    arr [ 2 ] [ 0 ] , arr [ 2 ] [ 1 ] = 5 , 10
    arr [ 3 ] [ 0 ] , arr [ 3 ] [ 1 ] = 40 , 30
    arr [ 4 ] [ 0 ] , arr [ 4 ] [ 1 ] = 10 , 5
    findSymPairs ( arr , 5 )

Index/key variables: first, i, sec
Iterator variables: i
Python program:
from math import sqrt
def findRepeatingNumber ( arr , n ) :
    sq = sqrt ( n )
    range__ = int ( ( n / sq ) + 1 )
    count = [ 0 for i in range ( range__ ) ]
    for i in range ( 0 , n + 1 , 1 ) :
        count [ int ( ( arr [ i ] - 1 ) / sq ) ] += 1
    selected_block = range__ - 1
    for i in range ( 0 , range__ - 1 , 1 ) :
        if ( count [ i ] > sq ) :
            selected_block = i
            break
    m = { i : 0 for i in range ( n ) }
    for i in range ( 0 , n + 1 , 1 ) :
        if ( ( ( selected_block * sq ) < arr [ i ] ) and ( arr [ i ] <= ( ( selected_block + 1 ) * sq ) ) ) :
            m [ arr [ i ] ] += 1
            if ( m [ arr [ i ] ] > 1 ) :
                return arr [ i ]
    return - 1
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 1 , 2 , 3 , 5 , 4 ]
    n = 5
    print ( " One ▁ of ▁ the ▁ numbers ▁ repeated ▁ in ▁ the ▁ array ▁ is : " , findRepeatingNumber ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def groupElements ( arr , n ) :
    visited = [ False ] * n
    for i in range ( 0 , n ) :
        visited [ i ] = False
    for i in range ( 0 , n ) :
        if ( visited [ i ] == False ) :
            print ( arr [ i ] , end = " ▁ " )
            for j in range ( i + 1 , n ) :
                if ( arr [ i ] == arr [ j ] ) :
                    print ( arr [ i ] , end = " ▁ " )
                    visited [ j ] = True
arr = [ 4 , 6 , 9 , 2 , 3 , 4 , 9 , 6 , 10 , 4 ]
n = len ( arr )
groupElements ( arr , n )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def orderedGroup ( arr ) :
    hM = { }
    for i in range ( 0 , len ( arr ) ) :
        hM [ arr [ i ] ] = hM . get ( arr [ i ] , 0 ) + 1
    for i in range ( 0 , len ( arr ) ) :
        count = hM . get ( arr [ i ] , None )
        if count != None :
            for j in range ( 0 , count ) :
                print ( arr [ i ] , end = " ▁ " )
            del hM [ arr [ i ] ]
if __name__ == " _ _ main _ _ " :
    arr = [ 10 , 5 , 3 , 10 , 10 , 4 , 1 , 3 ]
    orderedGroup ( arr )

Index/key variables: i
Iterator variables: i, j
Python program:
def areDisjoint ( set1 , set2 , m , n ) :
    for i in range ( 0 , m ) :
        for j in range ( 0 , n ) :
            if ( set1 [ i ] == set2 [ j ] ) :
                return False
    return True
set1 = [ 12 , 34 , 11 , 9 , 3 ]
set2 = [ 7 , 2 , 1 , 5 ]
m = len ( set1 )
n = len ( set2 )
print ( " yes " ) if areDisjoint ( set1 , set2 , m , n ) else ( " ▁ No " )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def areDisjoint ( set1 , set2 , m , n ) :
    set1 . sort ( )
    set2 . sort ( )
    i = 0 ; j = 0
    while ( i < m and j < n ) :
        if ( set1 [ i ] < set2 [ j ] ) :
            i += 1
        elif ( set2 [ j ] < set1 [ i ] ) :
            j += 1
        else :
            return False
    return True
set1 = [ 12 , 34 , 11 , 9 , 3 ]
set2 = [ 7 , 2 , 1 , 5 ]
m = len ( set1 )
n = len ( set2 )
print ( " Yes " ) if areDisjoint ( set1 , set2 , m , n ) else print ( " No " )

Index/key variables: i, j
Python program:
from collections import defaultdict
def findSum ( A , B , n ) :
    Hash = defaultdict ( lambda : 0 )
    for i in range ( 0 , n ) :
        Hash [ A [ i ] ] += 1
        Hash [ B [ i ] ] += 1
    Sum = 0
    for x in Hash :
        if Hash [ x ] == 1 :
            Sum += x
    return Sum
if __name__ == " _ _ main _ _ " :
    A = [ 5 , 4 , 9 , 2 , 3 ]
    B = [ 2 , 8 , 7 , 6 , 3 ]
    n = len ( A )
    print ( findSum ( A , B , n ) )

Index/key variables: i, x
Accumulator variables: Sum
Iterator variables: i, x
Python program:
def findMissing ( a , b , n , m ) :
    for i in range ( n ) :
        for j in range ( m ) :
            if ( a [ i ] == b [ j ] ) :
                break
        if ( j == m - 1 ) :
            print ( a [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    a = [ 1 , 2 , 6 , 3 , 4 , 5 ]
    b = [ 2 , 4 , 3 , 1 , 0 ]
    n = len ( a )
    m = len ( b )
    findMissing ( a , b , n , m )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def findMissing ( a , b , n , m ) :
    s = dict ( )
    for i in range ( m ) :
        s [ b [ i ] ] = 1
    for i in range ( n ) :
        if a [ i ] not in s . keys ( ) :
            print ( a [ i ] , end = " ▁ " )
a = [ 1 , 2 , 6 , 3 , 4 , 5 ]
b = [ 2 , 4 , 3 , 1 , 0 ]
n = len ( a )
m = len ( b )
findMissing ( a , b , n , m )

Index/key variables: i
Iterator variables: i
Python program:
def areEqual ( arr1 , arr2 , n , m ) :
    if ( n != m ) :
        return False
    arr1 . sort ( )
    arr2 . sort ( )
    for i in range ( 0 , n - 1 ) :
        if ( arr1 [ i ] != arr2 [ i ] ) :
            return False
    return True
arr1 = [ 3 , 5 , 2 , 5 , 2 ]
arr2 = [ 2 , 3 , 5 , 5 , 2 ]
n = len ( arr1 )
m = len ( arr2 )
if ( areEqual ( arr1 , arr2 , n , m ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i
Iterator variables: i
Python program:
def find_maximum ( a , n , k ) :
    b = dict ( )
    for i in range ( n ) :
        x = a [ i ]
        d = min ( 1 + i , n - i )
        if x not in b . keys ( ) :
            b [ x ] = d
        else :
            b [ x ] = min ( d , b [ x ] )
    ans = 10 ** 9
    for i in range ( n ) :
        x = a [ i ]
        if ( x != ( k - x ) and ( k - x ) in b . keys ( ) ) :
            ans = min ( max ( b [ x ] , b [ k - x ] ) , ans )
    return ans
a = [ 3 , 5 , 8 , 6 , 7 ]
K = 11
n = len ( a )
print ( find_maximum ( a , n , K ) )

Index/key variables: i, x
Iterator variables: i
Python program:
def isProduct ( arr , n , x ) :
    for i in arr :
        for j in arr :
            if i * j == x :
                return True
    return False
arr = [ 10 , 20 , 9 , 40 ]
x = 400
n = len ( arr )
if ( isProduct ( arr , n , x ) == True ) :
    print ( " Yes " )
else :
    print ( " No " )
x = 900
if ( isProduct ( arr , n , x ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Iterator variables: i, j
Python program:
def isProduct ( arr , n , x ) :
    if n < 2 :
        return False
    s = set ( )
    for i in range ( 0 , n ) :
        if arr [ i ] == 0 :
            if x == 0 :
                return True
            else :
                continue
        if x % arr [ i ] == 0 :
            if x // arr [ i ] in s :
                return True
            s . add ( arr [ i ] )
    return False
if __name__ == " _ _ main _ _ " :
    arr = [ 10 , 20 , 9 , 40 ]
    x = 400
    n = len ( arr )
    if isProduct ( arr , n , x ) :
        print ( " Yes " )
    else :
        print ( " No " )
    x = 190
    if isProduct ( arr , n , x ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Accumulator variables: s
Iterator variables: i
Python program:
def findGreatest ( arr , n ) :
    result = - 1
    for i in range ( n ) :
        for j in range ( n - 1 ) :
            for k in range ( j + 1 , n ) :
                if ( arr [ j ] * arr [ k ] == arr [ i ] ) :
                    result = max ( result , arr [ i ] )
    return result
if __name__ == " _ _ main _ _ " :
    arr = [ 30 , 10 , 9 , 3 , 35 ]
    n = len ( arr )
    print ( findGreatest ( arr , n ) )

Index/key variables: i, j, k
Iterator variables: i, j, k
Python program:
from math import sqrt
def findGreatest ( arr , n ) :
    m = dict ( )
    for i in arr :
        m [ i ] = m . get ( i , 0 ) + 1
    arr = sorted ( arr )
    for i in range ( n - 1 , 0 , - 1 ) :
        j = 0
        while ( j < i and arr [ j ] <= sqrt ( arr [ i ] ) ) :
            if ( arr [ i ] % arr [ j ] == 0 ) :
                result = arr [ i ] // arr [ j ]
                if ( result != arr [ j ] and ( result in m . keys ( ) ) and m [ result ] > 0 ) :
                    return arr [ i ]
                elif ( result == arr [ j ] and ( result in m . keys ( ) ) and m [ result ] > 1 ) :
                    return arr [ i ]
            j += 1
    return - 1
arr = [ 17 , 2 , 1 , 15 , 30 ]
n = len ( arr )
print ( findGreatest ( arr , n ) )

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