dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def minRemove ( a , b , n , m ) :
    countA = dict ( )
    countB = dict ( )
    for i in range ( n ) :
        countA [ a [ i ] ] = countA . get ( a [ i ] , 0 ) + 1
    for i in range ( n ) :
        countB [ b [ i ] ] = countB . get ( b [ i ] , 0 ) + 1
    res = 0
    for x in countA :
        if x in countB . keys ( ) :
            res += min ( countA [ x ] , countB [ x ] )
    return res
a = [ 1 , 2 , 3 , 4 ]
b = [ 2 , 3 , 4 , 5 , 8 ]
n = len ( a )
m = len ( b )
print ( minRemove ( a , b , n , m ) )

Index/key variables: i, x
Accumulator variables: res
Iterator variables: i, x
Python program:
def countItems ( list1 , list2 ) :
    count = 0
    for i in list1 :
        for j in list2 :
            if i [ 0 ] == j [ 0 ] and i [ 1 ] != j [ 1 ] :
                count += 1
    return count
list1 = [ ( " apple " , 60 ) , ( " bread " , 20 ) , ( " wheat " , 50 ) , ( " oil " , 30 ) ]
list2 = [ ( " milk " , 20 ) , ( " bread " , 15 ) , ( " wheat " , 40 ) , ( " apple " , 60 ) ]
print ( " Count ▁ = ▁ " , countItems ( list1 , list2 ) )

Accumulator variables: count
Iterator variables: i, j
Python program:
def find ( list1 , list2 ) :
    res = [ ]
    max_possible_sum = len ( list1 ) + len ( list2 ) - 2
    for sum in range ( max_possible_sum + 1 ) :
        for i in range ( sum + 1 ) :
            if ( i < len ( list1 ) and ( sum - i ) < len ( list2 ) and list1 [ i ] == list2 [ sum - i ] ) :
                res . append ( list1 [ i ] )
        if ( len ( res ) > 0 ) :
            break
    for i in range ( len ( res ) ) :
        print ( res [ i ] , end = " ▁ " )
list1 = [ ]
list1 . append ( " GeeksforGeeks " )
list1 . append ( " Udemy " )
list1 . append ( " Coursera " )
list1 . append ( " edX " )
list2 = [ ]
list2 . append ( " Codecademy " )
list2 . append ( " Khan ▁ Academy " )
list2 . append ( " GeeksforGeeks " )
find ( list1 , list2 )

Index/key variables: i
Accumulator variables: res
Iterator variables: i, sum
Python program:
import sys
def find ( list1 , list2 ) :
    Map = { }
    for i in range ( len ( list1 ) ) :
        Map [ list1 [ i ] ] = i
    res = [ ]
    minsum = sys . maxsize
    for j in range ( len ( list2 ) ) :
        if list2 [ j ] in Map :
            Sum = j + Map [ list2 [ j ] ]
            if ( Sum < minsum ) :
                minsum = Sum
                res . clear ( )
                res . append ( list2 [ j ] )
            elif ( Sum == minsum ) :
                res . append ( list2 [ j ] )
    print ( * res , sep = " ▁ " )
list1 = [ ]
list1 . append ( " GeeksforGeeks " )
list1 . append ( " Udemy " )
list1 . append ( " Coursera " )
list1 . append ( " edX " )
list2 = [ ]
list2 . append ( " Codecademy " )
list2 . append ( " Khan ▁ Academy " )
list2 . append ( " GeeksforGeeks " )
find ( list1 , list2 )

Index/key variables: i, j
Accumulator variables: res
Iterator variables: i, j
Python program:
def makePermutation ( a , n ) :
    count = dict ( )
    for i in range ( n ) :
        if count . get ( a [ i ] ) :
            count [ a [ i ] ] += 1
        else :
            count [ a [ i ] ] = 1 ;
    next_missing = 1
    for i in range ( n ) :
        if count [ a [ i ] ] != 1 or a [ i ] > n or a [ i ] < 1 :
            count [ a [ i ] ] -= 1
            while count . get ( next_missing ) :
                next_missing += 1
            a [ i ] = next_missing
            count [ next_missing ] = 1
A = [ 2 , 2 , 3 , 3 ]
n = len ( A )
makePermutation ( A , n )
for i in range ( n ) :
    print ( A [ i ] , end = " ▁ " )

Index/key variables: i, next_missing
Iterator variables: i
Python program:
def getPairsCount ( arr , n , sum ) :
    count = 0
    for i in range ( 0 , n ) :
        for j in range ( i + 1 , n ) :
            if arr [ i ] + arr [ j ] == sum :
                count += 1
    return count
arr = [ 1 , 5 , 7 , - 1 , 5 ]
n = len ( arr )
sum = 6
print ( " Count ▁ of ▁ pairs ▁ is " , getPairsCount ( arr , n , sum ) )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
class getNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def isFullBinaryTree ( root ) :
    if ( not root ) :
        return True
    q = [ ]
    q . append ( root )
    while ( not len ( q ) ) :
        node = q [ 0 ]
        q . pop ( 0 )
        if ( node . left == None and node . right == None ) :
            continue
        if ( node . left == None or node . right == None ) :
            return False
        q . append ( node . left )
        q . append ( node . right )
    return True
if __name__ == ' _ _ main _ _ ' :
    root = getNode ( 1 )
    root . left = getNode ( 2 )
    root . right = getNode ( 3 )
    root . left . left = getNode ( 4 )
    root . left . right = getNode ( 5 )
    if ( isFullBinaryTree ( root ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Accumulator variables: q
Class/struct names: getNode
Python program:
def linearSearch ( a , n , key ) :
    for i in range ( 0 , n ) :
        if ( a [ i ] == key ) :
            return True
    return False
arr = 2 , 3 , 4 , 10 , 40
x = 10
n = len ( arr )
if ( linearSearch ( arr , n , x ) ) :
    print ( " Element ▁ is ▁ present ▁ in ▁ array " )
else :
    print ( " Element ▁ is ▁ not ▁ present ▁ in ▁ array " )

Index/key variables: i
Iterator variables: i
Python program:
import sys
def getPairsCount ( arr , n , sum ) :
    m = [ 0 ] * 1000
    for i in range ( 0 , n ) :
        m [ arr [ i ] ] += 1
    twice_count = 0
    for i in range ( 0 , n ) :
        twice_count += m [ sum - arr [ i ] ]
        if ( sum - arr [ i ] == arr [ i ] ) :
            twice_count -= 1
    return int ( twice_count / 2 )
arr = [ 1 , 5 , 7 , - 1 , 5 ]
n = len ( arr )
sum = 6
print ( " Count ▁ of ▁ pairs ▁ is " , getPairsCount ( arr , n , sum ) )

Index/key variables: i
Accumulator variables: twice_count
Iterator variables: i
Python program:
def countPairs ( arr1 , arr2 , m , n , x ) :
    count = 0
    for i in range ( m ) :
        for j in range ( n ) :
            if arr1 [ i ] + arr2 [ j ] == x :
                count = count + 1
    return count
arr1 = [ 1 , 3 , 5 , 7 ]
arr2 = [ 2 , 3 , 5 , 8 ]
m = len ( arr1 )
n = len ( arr2 )
x = 10
print ( " Count ▁ = ▁ " , countPairs ( arr1 , arr2 , m , n , x ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def isPresent ( arr , low , high , value ) :
    while ( low <= high ) :
        mid = ( low + high ) // 2
        if ( arr [ mid ] == value ) :
            return True
        elif ( arr [ mid ] > value ) :
            high = mid - 1
        else :
            low = mid + 1
    return False
def countPairs ( arr1 , arr2 , m , n , x ) :
    count = 0
    for i in range ( m ) :
        value = x - arr1 [ i ]
        if ( isPresent ( arr2 , 0 , n - 1 , value ) ) :
            count += 1
    return count
if __name__ == " _ _ main _ _ " :
    arr1 = [ 1 , 3 , 5 , 7 ]
    arr2 = [ 2 , 3 , 5 , 8 ]
    m = len ( arr1 )
    n = len ( arr2 )
    x = 10
    print ( " Count ▁ = ▁ " , countPairs ( arr1 , arr2 , m , n , x ) )

Index/key variables: i, mid
Accumulator variables: count
Iterator variables: i
Python program:
def countPairs ( arr1 , arr2 , m , n , x ) :
    count = 0
    us = set ( )
    for i in range ( m ) :
        us . add ( arr1 [ i ] )
    for j in range ( n ) :
        if x - arr2 [ j ] in us :
            count += 1
    return count
arr1 = [ 1 , 3 , 5 , 7 ]
arr2 = [ 2 , 3 , 5 , 8 ]
m = len ( arr1 )
n = len ( arr2 )
x = 10
print ( " Count ▁ = " , countPairs ( arr1 , arr2 , m , n , x ) )

Index/key variables: i, j
Accumulator variables: count, us
Iterator variables: i, j
Python program:
def countPairs ( arr1 , arr2 , m , n , x ) :
    count , l , r = 0 , 0 , n - 1
    while ( l < m and r >= 0 ) :
        if ( ( arr1 [ l ] + arr2 [ r ] ) == x ) :
            l += 1
            r -= 1
            count += 1
        elif ( ( arr1 [ l ] + arr2 [ r ] ) < x ) :
            l += 1
        else :
            r -= 1
    return count
if __name__ == ' _ _ main _ _ ' :
    arr1 = [ 1 , 3 , 5 , 7 ]
    arr2 = [ 2 , 3 , 5 , 8 ]
    m = len ( arr1 )
    n = len ( arr2 )
    x = 10
    print ( " Count ▁ = " , countPairs ( arr1 , arr2 , m , n , x ) )

Index/key variables: l, r
Accumulator variables: count
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . next = None
def push ( head_ref , new_data ) :
    new_node = Node ( new_data )
    new_node . next = head_ref
    head_ref = new_node
    return head_ref
def countPairs ( head1 , head2 , x ) :
    count = 0
    p1 = head1
    while ( p1 != None ) :
        p2 = head2
        while ( p2 != None ) :
            if ( ( p1 . data + p2 . data ) == x ) :
                count += 1
            p2 = p2 . next
        p1 = p1 . next
    return count
if __name__ == ' _ _ main _ _ ' :
    head1 = None
    head2 = None
    head1 = push ( head1 , 7 )
    head1 = push ( head1 , 5 )
    head1 = push ( head1 , 1 )
    head1 = push ( head1 , 3 )
    head2 = push ( head2 , 3 )
    head2 = push ( head2 , 5 )
    head2 = push ( head2 , 2 )
    head2 = push ( head2 , 8 )
    x = 10
    print ( " Count ▁ = ▁ " , countPairs ( head1 , head2 , x ) )

Accumulator variables: count
Class/struct names: Node
Python program:
def countPairs ( arr1 , arr2 , n , value ) :
    count = 0
    l = 0
    r = n - 1
    while ( l < n and r >= 0 ) :
        sum = arr1 [ l ] + arr2 [ r ]
        if ( sum == value ) :
            l += 1
            r -= 1
            count += 1
        elif ( sum > value ) :
            r -= 1
        else :
            l += 1
    return count
def countQuadruples ( arr1 , arr2 , arr3 , arr4 , n , x ) :
    count = 0
    for i in range ( 0 , n ) :
        for j in range ( 0 , n ) :
            p_sum = arr1 [ i ] + arr2 [ j ]
            count += int ( countPairs ( arr3 , arr4 , n , x - p_sum ) )
    return count
arr1 = [ 1 , 4 , 5 , 6 ]
arr2 = [ 2 , 3 , 7 , 8 ]
arr3 = [ 1 , 4 , 6 , 10 ]
arr4 = [ 2 , 4 , 7 , 8 ]
n = len ( arr1 )
x = 30
print ( " Count ▁ = ▁ " , countQuadruples ( arr1 , arr2 , arr3 , arr4 , n , x ) )

Index/key variables: i, j, l, r
Accumulator variables: count
Iterator variables: i, j
Python program:
def countQuadruples ( arr1 , arr2 , arr3 , arr4 , n , x ) :
    count = 0
    m = { }
    for i in range ( n ) :
        for j in range ( n ) :
            if ( arr1 [ i ] + arr2 [ j ] ) in m :
                m [ arr1 [ i ] + arr2 [ j ] ] += 1
            else :
                m [ arr1 [ i ] + arr2 [ j ] ] = 1
    for k in range ( n ) :
        for l in range ( n ) :
            p_sum = arr3 [ k ] + arr4 [ l ]
            if ( x - p_sum ) in m :
                count += m [ x - p_sum ]
    return count
arr1 = [ 1 , 4 , 5 , 6 ]
arr2 = [ 2 , 3 , 7 , 8 ]
arr3 = [ 1 , 4 , 6 , 10 ]
arr4 = [ 2 , 4 , 7 , 8 ]
n = len ( arr1 )
x = 30
print ( " Count ▁ = " , countQuadruples ( arr1 , arr2 , arr3 , arr4 , n , x ) )

Index/key variables: i, j, k, l
Accumulator variables: count
Iterator variables: i, j, k, l
Python program:
if __name__ == ' _ _ main _ _ ' :
    N = 4 ;
    print ( " Value ▁ of ▁ N : ▁ " , N ) ;
    for i in range ( 1 , N + 1 ) :
        for j in range ( 1 , N + 1 ) :
            min = i if i < j else j ;
            print ( N - min + 1 , end = " " ) ;
        print ( ) ;

Iterator variables: i, j
Python program:
arr = [ 10 , 2 , - 2 , - 20 , 10 ]
n = len ( arr )
k = - 10
res = 0
for i in range ( n ) :
    summ = 0
    for j in range ( i , n ) :
        summ += arr [ j ]
        if summ == k :
            res += 1
print ( res )

Index/key variables: j
Accumulator variables: res, summ
Iterator variables: i, j
Python program:
from collections import defaultdict
def findSubarraySum ( arr , n , Sum ) :
    prevSum = defaultdict ( lambda : 0 )
    res = 0
    currsum = 0
    for i in range ( 0 , n ) :
        currsum += arr [ i ]
        if currsum == Sum :
            res += 1
        if ( currsum - Sum ) in prevSum :
            res += prevSum [ currsum - Sum ]
        prevSum [ currsum ] += 1
    return res
if __name__ == " _ _ main _ _ " :
    arr = [ 10 , 2 , - 2 , - 20 , 10 ]
    Sum = - 10
    n = len ( arr )
    print ( findSubarraySum ( arr , n , Sum ) )

Index/key variables: currsum, i
Accumulator variables: res
Iterator variables: i
Python program:
def countPairs ( arr , n ) :
    result = 0 ;
    for i in range ( 0 , n ) :
        for j in range ( i + 1 , n ) :
            product = arr [ i ] * arr [ j ] ;
            for k in range ( 0 , n ) :
                if ( arr [ k ] == product ) :
                    result = result + 1 ;
                    break ;
    return result ;
arr = [ 6 , 2 , 4 , 12 , 5 , 3 ] ;
n = len ( arr ) ;
print ( countPairs ( arr , n ) ) ;

Index/key variables: i, j, k
Iterator variables: i, j, k
Python program:
def countPairs ( arr , n ) :
    result = 0
    Hash = set ( )
    for i in range ( n ) :
        Hash . add ( arr [ i ] )
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            product = arr [ i ] * arr [ j ]
            if product in ( Hash ) :
                result += 1
    return result
if __name__ == ' _ _ main _ _ ' :
    arr = [ 6 , 2 , 4 , 12 , 5 , 3 ]
    n = len ( arr )
    print ( countPairs ( arr , n ) )

Index/key variables: i, j
Accumulator variables: Hash, result
Iterator variables: i, j
Python program:
def findPairs ( arr1 , arr2 , n , m , x ) :
    for i in range ( 0 , n ) :
        for j in range ( 0 , m ) :
            if ( arr1 [ i ] + arr2 [ j ] == x ) :
                print ( arr1 [ i ] , arr2 [ j ] )
arr1 = [ 1 , 2 , 3 , 7 , 5 , 4 ]
arr2 = [ 0 , 7 , 4 , 3 , 2 , 1 ]
n = len ( arr1 )
m = len ( arr2 )
x = 8
findPairs ( arr1 , arr2 , n , m , x )

Index/key variables: i, j
Iterator variables: i, j
Python program:
import math
def isvalid ( arr , K , N , M ) :
    sum = 0
    for i in range ( 0 , N ) :
        sum += math . ceil ( arr [ i ] * 1.0 / K )
    return sum <= M
def smallestValueForK ( arr , N , M ) :
    low = 1
    high = arr [ 0 ]
    for i in range ( 1 , len ( arr ) ) :
        high = max ( high , arr [ i ] )
    mid = 0
    while ( high - low > 1 ) :
        mid = ( high + low ) // 2
        if ( not isvalid ( arr , mid , N , M ) ) :
            low = mid + 1
        else :
            high = mid
    if ( isvalid ( arr , low , N , M ) ) :
        return low
    else :
        return high
if __name__ == " _ _ main _ _ " :
    arr = [ 4 , 3 , 2 , 7 ]
    N = len ( arr )
    M = 5
    print ( smallestValueForK ( arr , N , M ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def findPairs ( arr1 , arr2 , n , m , x ) :
    s = set ( )
    for i in range ( 0 , n ) :
        s . add ( arr1 [ i ] )
    for j in range ( 0 , m ) :
        if ( ( x - arr2 [ j ] ) in s ) :
            print ( ( x - arr2 [ j ] ) , ' ' , arr2 [ j ] )
arr1 = [ 1 , 0 , - 4 , 7 , 6 , 4 ]
arr2 = [ 0 , 2 , 4 , - 3 , 2 , 1 ]
x = 8
n = len ( arr1 )
m = len ( arr2 )
findPairs ( arr1 , arr2 , n , m , x )

Index/key variables: i, j
Accumulator variables: s
Iterator variables: i, j
Python program:
class newNode :
    def __init__ ( self , key ) :
        self . data = key
        self . left = None
        self . right = None
def isBalancedUtil ( root , maxh , minh ) :
    if ( root == None ) :
        maxh = minh = 0
        return True
    lmxh = 0
    lmnh = 0
    rmxh , rmnh = 0 , 0
    if ( isBalancedUtil ( root . left , lmxh , lmnh ) == False ) :
        return False
    if ( isBalancedUtil ( root . right , rmxh , rmnh ) == False ) :
        return False
    maxh = max ( lmxh , rmxh ) + 1
    minh = min ( lmnh , rmnh ) + 1
    if ( maxh <= 2 * minh ) :
        return True
    return False
def isBalanced ( root ) :
    maxh , minh = 0 , 0
    return isBalancedUtil ( root , maxh , minh )
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 10 )
    root . left = newNode ( 5 )
    root . right = newNode ( 100 )
    root . right . left = newNode ( 50 )
    root . right . right = newNode ( 150 )
    root . right . left . left = newNode ( 40 )
    if ( isBalanced ( root ) ) :
        print ( " Balanced " )
    else :
        print ( " Not ▁ Balanced " )

Class/struct names: newNode
Python program:
def findLargestIndex ( arr , n ) :
    for i in range ( n ) :
        if ( arr [ i ] == i ) :
            print ( i )
            return
    print ( - 1 )
arr = [ - 10 , - 5 , 0 , 3 , 7 ]
n = len ( arr )
findLargestIndex ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
def countFreq ( a , n ) :
    hm = dict ( )
    for i in range ( n ) :
        hm [ a [ i ] ] = hm . get ( a [ i ] , 0 ) + 1
    cumul = 0
    for i in range ( n ) :
        cumul += hm [ a [ i ] ]
        if ( hm [ a [ i ] ] > 0 ) :
            print ( a [ i ] , " - > " , cumul )
        hm [ a [ i ] ] = 0
a = [ 1 , 3 , 2 , 4 , 2 , 1 ]
n = len ( a )
countFreq ( a , n )

Index/key variables: i
Accumulator variables: cumul
Iterator variables: i
Python program:
def findPair ( arr , n ) :
    found = False
    for i in range ( 0 , n ) :
        for j in range ( i + 1 , n ) :
            for k in range ( 0 , n ) :
                if ( arr [ i ] + arr [ j ] == arr [ k ] ) :
                    print ( arr [ i ] , arr [ j ] )
                    found = True
    if ( found == False ) :
        print ( " Not ▁ exist " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 10 , 4 , 8 , 13 , 5 ]
    n = len ( arr )
    findPair ( arr , n )

Index/key variables: i, j, k
Iterator variables: i, j, k
Boolean variables: found
Python program:
def findkthElement ( arr , n , K ) :
    l = 0
    h = n - 1
    while l + 1 < h :
        mid = ( l + h ) // 2
        if arr [ l ] >= arr [ mid ] :
            l = mid
        else :
            h = mid
    if arr [ l ] < arr [ h ] :
        r = l
    else :
        r = h
    if K <= r + 1 :
        return arr [ r + 1 - K ]
    else :
        return arr [ n - ( K - ( r + 1 ) ) ]
if __name__ == " _ _ main _ _ " :
    arr = [ 10 , 8 , 6 , 5 , 2 , 1 , 13 , 12 ]
    n = len ( arr )
    K = 3
    print ( findkthElement ( arr , n , K ) )

Index/key variables: h, l, mid
Python program:
def printPairs ( arr , n , k ) :
    isPairFound = True
    for i in range ( 0 , n ) :
        for j in range ( 0 , n ) :
            if ( i != j and arr [ i ] % arr [ j ] == k ) :
                print ( " ( " , arr [ i ] , " , ▁ " , arr [ j ] , " ) " , sep = " " , end = " ▁ " )
                isPairFound = True
    return isPairFound
arr = [ 2 , 3 , 5 , 4 , 7 ]
n = len ( arr )
k = 3
if ( printPairs ( arr , n , k ) == False ) :
    print ( " No ▁ such ▁ pair ▁ exists " )

Index/key variables: i, j
Iterator variables: i, j
Boolean variables: isPairFound
Python program:
import math as mt
def findDivisors ( n ) :
    v = [ ]
    for i in range ( 1 , mt . floor ( n ** ( .5 ) ) + 1 ) :
        if ( n % i == 0 ) :
            if ( n / i == i ) :
                v . append ( i )
            else :
                v . append ( i )
                v . append ( n // i )
    return v
def printPairs ( arr , n , k ) :
    occ = dict ( )
    for i in range ( n ) :
        occ [ arr [ i ] ] = True
    isPairFound = False
    for i in range ( n ) :
        if ( occ [ k ] and k < arr [ i ] ) :
            print ( " ( " , k , " , " , arr [ i ] , " ) " , end = " ▁ " )
            isPairFound = True
        if ( arr [ i ] >= k ) :
            v = findDivisors ( arr [ i ] - k )
            for j in range ( len ( v ) ) :
                if ( arr [ i ] % v [ j ] == k and arr [ i ] != v [ j ] and occ [ v [ j ] ] ) :
                    print ( " ( " , arr [ i ] , " , " , v [ j ] , " ) " , end = " ▁ " )
                    isPairFound = True
    return isPairFound
arr = [ 3 , 1 , 2 , 5 , 4 ]
n = len ( arr )
k = 2
if ( printPairs ( arr , n , k ) == False ) :
    print ( " No ▁ such ▁ pair ▁ exists " )

Index/key variables: i, j, k
Accumulator variables: v
Iterator variables: i, j
Boolean variables: isPairFound
Python program:
def convert ( arr , n ) :
    temp = [ arr [ i ] for i in range ( n ) ]
    temp . sort ( )
    umap = { }
    val = 0
    for i in range ( n ) :
        umap [ temp [ i ] ] = val
        val += 1
    for i in range ( n ) :
        arr [ i ] = umap [ arr [ i ] ]
def printArr ( arr , n ) :
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ 10 , 20 , 15 , 12 , 11 , 50 ]
    n = len ( arr )
    print ( " Given ▁ Array ▁ is ▁ " )
    printArr ( arr , n )
    convert ( arr , n )
    print ( " Converted Array is   " )
    printArr ( arr , n )

Index/key variables: i
Accumulator variables: val
Iterator variables: i
Python program:
class newNode :
    def __init__ ( self , key ) :
        self . data = key
        self . left = None
        self . right = None
def checkDupUtil ( root , s ) :
    if ( root == None ) :
        return False
    if root . data in s :
        return True
    s . add ( root . data )
    return checkDupUtil ( root . left , s ) or checkDupUtil ( root . right , s )
def checkDup ( root ) :
    s = set ( )
    return checkDupUtil ( root , s )
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 1 )
    root . left = newNode ( 2 )
    root . right = newNode ( 2 )
    root . left . left = newNode ( 3 )
    if ( checkDup ( root ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Class/struct names: newNode
Python program:
from collections import deque
from bisect import bisect_left , bisect_right
def totalCount ( A , N , M , queries , Q ) :
    row_sum = [ 0 ] * N
    col_sum = [ 0 ] * M
    for i in range ( N ) :
        for j in range ( M ) :
            row_sum [ i ] += A [ i ] [ j ]
            col_sum [ j ] += A [ i ] [ j ]
    sum_list = [ ]
    for i in range ( N ) :
        sum_list . append ( row_sum [ i ] )
    for i in range ( M ) :
        sum_list . append ( col_sum [ i ] )
    sum_list = sorted ( sum_list )
    for i in range ( Q ) :
        L = queries [ i ] [ 0 ]
        R = queries [ i ] [ 1 ]
        l = left_search ( sum_list , L )
        r = right_search ( sum_list , R )
        print ( r - l + 1 , end = " ▁ " )
def left_search ( A , num ) :
    low , high = 0 , len ( A ) - 1
    ans = 0
    while ( low <= high ) :
        mid = low + ( high - low ) // 2
        if ( A [ mid ] >= num ) :
            ans = mid
            high = mid - 1
        else :
            low = mid + 1
    return ans
def right_search ( A , num ) :
    low , high = 0 , len ( A ) - 1
    ans = high
    while ( low <= high ) :
        mid = low + ( high - low ) // 2
        if ( A [ mid ] <= num ) :
            ans = mid
            low = mid + 1
        else :
            high = mid - 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    N , M = 3 , 2
    A = [ [ 13 , 3 ] , [ 9 , 4 ] , [ 6 , 10 ] ]
    Q = 2
    queries = [ [ 10 , 20 ] , [ 25 , 35 ] ]
    totalCount ( A , N , M , queries , Q )

Index/key variables: i, j, mid
Accumulator variables: sum_list
Iterator variables: i, j
Python program:
from collections import defaultdict
import sys
def smallestKFreq ( arr , n , k ) :
    mp = defaultdict ( lambda : 0 )
    for i in range ( n ) :
        mp [ arr [ i ] ] += 1
    res = sys . maxsize
    res1 = sys . maxsize
    for key , values in mp . items ( ) :
        if values == k :
            res = min ( res , key )
    return res if res != res1 else - 1
arr = [ 2 , 2 , 1 , 3 , 1 ]
k = 2
n = len ( arr )
print ( smallestKFreq ( arr , n , k ) )

Index/key variables: i
Iterator variables: i, key, values
Python program:
import sys
def maximumProfit ( arr , n ) :
    ans = - sys . maxsize - 1
    price = 0
    for i in range ( n ) :
        count = 0
        for j in range ( n ) :
            if ( arr [ i ] <= arr [ j ] ) :
                count += 1
        if ( ans < count * arr [ i ] ) :
            price = arr [ i ]
            ans = count * arr [ i ]
    return price ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 22 , 87 , 9 , 50 , 56 , 43 ]
    print ( maximumProfit ( arr , 6 ) )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j