dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
class Node :
    def __init__ ( self , data , next ) :
        self . data = data
        self . next = next
class LinkedList :
    def __init__ ( self ) :
        self . head = None
    def push ( self , new_data ) :
        new_node = Node ( new_data , self . head )
        self . head = new_node
    def check_pair_product ( self , prod ) :
        p = self . head
        s = set ( )
        while p != None :
            curr = p . data
            if ( prod % curr == 0 and ( prod // curr ) in s ) :
                print ( curr , prod // curr )
                return True ;
            s . add ( p . data ) ;
            p = p . next ;
        return False
if __name__ == " _ _ main _ _ " :
    linkedlist = LinkedList ( )
    linkedlist . push ( 1 )
    linkedlist . push ( 2 )
    linkedlist . push ( 1 )
    linkedlist . push ( 12 )
    linkedlist . push ( 1 )
    linkedlist . push ( 18 )
    linkedlist . push ( 47 )
    linkedlist . push ( 16 )
    linkedlist . push ( 12 )
    linkedlist . push ( 14 )
    res = linkedlist . check_pair_product ( 24 )
    if res == False :
        print ( " NO ▁ PAIR ▁ EXIST " )

Accumulator variables: s
Class/struct names: LinkedList, Node
Python program:
def solve ( arr , n , k ) :
    arr . sort ( )
    if ( k == 1 and arr [ n - 2 ] != arr [ n - 1 ] ) :
        print ( arr [ n - 1 ] )
        return
    count = 1
    for i in range ( n - 2 , - 1 , - 1 ) :
        if ( arr [ i ] == arr [ i + 1 ] ) :
            count += 1
        else :
            count = 1
        if ( count == k and ( i == 0 or ( arr [ i - 1 ] != arr [ i ] ) ) ) :
            print ( arr [ i ] )
            return
    print ( " No ▁ such ▁ element " )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 1 , 2 , 3 , 3 , 4 , 5 , 5 , 6 , 6 , 6 ]
    k = 2
    n = len ( arr )
    solve ( arr , n , k )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def getMin ( arr , n ) :
    res = arr [ 0 ]
    for i in range ( 1 , n ) :
        res = min ( res , arr [ i ] )
    return res
def getMax ( arr , n ) :
    res = arr [ 0 ]
    for i in range ( 1 , n ) :
        res = max ( res , arr [ i ] )
    return res
def findSum ( arr , n ) :
    min = getMin ( arr , n )
    max = getMax ( arr , n )
    return min + max
def findProduct ( arr , n ) :
    min = getMin ( arr , n )
    max = getMax ( arr , n )
    return min * max
if __name__ == " _ _ main _ _ " :
    arr = [ 12 , 1234 , 45 , 67 , 1 ]
    n = len ( arr )
    print ( " Sum ▁ = ▁ " , findSum ( arr , n ) )
    print ( " Product ▁ = ▁ " , findProduct ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def countEle ( s , a , N ) :
    mp = { }
    for i in range ( 0 , N ) :
        num = a [ i ]
        if num in mp :
            print ( "0" , end = " ▁ " )
        else :
            cnt = 0
            while s [ - 1 ] != num :
                mp [ s . pop ( ) ] = True
                cnt += 1
            s . pop ( )
            cnt += 1
            print ( cnt , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    N = 5
    s = [ ]
    s . append ( 1 )
    s . append ( 2 )
    s . append ( 3 )
    s . append ( 4 )
    s . append ( 6 )
    a = [ 6 , 3 , 4 , 1 , 2 ]
    countEle ( s , a , N )

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
N = 6
Tree = [ 0 ] * ( 6 * N )
for i in range ( 6 * N ) :
    Tree [ i ] = set ( )
def buildTree ( arr : list , idx : int , s : int , e : int ) -> None :
    global Tree
    if s == e :
        Tree [ idx ] . add ( arr [ s ] )
        return
    mid = ( s + e ) // 2
    buildTree ( arr , 2 * idx , s , mid )
    buildTree ( arr , 2 * idx + 1 , mid + 1 , e )
    for it in Tree [ 2 * idx ] :
        Tree [ idx ] . add ( it )
    for it in Tree [ 2 * idx + 1 ] :
        Tree [ idx ] . add ( it )
def query ( idx : int , s : int , e : int , qs : int , qe : int , x : int ) -> bool :
    global Tree
    if qs <= s and e <= qe :
        if list ( Tree [ idx ] ) . count ( x ) != 0 :
            return True
        else :
            return False
    if qe < s or e < qs :
        return False
    mid = ( s + e ) // 2
    leftAns = query ( 2 * idx , s , mid , qs , qe , x )
    rightAns = query ( 2 * idx + 1 , mid + 1 , e , qs , qe , x )
    return ( leftAns or rightAns )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 3 , 3 , 9 , 8 , 7 ]
    n = len ( arr )
    buildTree ( arr , 1 , 0 , n - 1 )
    l = 0
    r = 3
    x = 2
    if query ( 1 , 0 , n - 1 , l , r , x ) :
        print ( " YES " )
    else :
        print ( " NO " )
    l = 2
    r = 5
    x = 3
    if query ( 1 , 0 , n - 1 , l , r , x ) :
        print ( " YES " )
    else :
        print ( " NO " )

Index/key variables: i, idx, s
Iterator variables: i, it
Python program:
def countChar ( str ) :
    n = len ( str )
    if ( n <= 2 ) :
        return n
    count = 2
    for i in range ( 1 , n - 1 ) :
        if ( str [ i - 1 ] == str [ i + 1 ] ) :
            count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    str = " egeeksk "
    print ( countChar ( str ) )

Accumulator variables: count
Iterator variables: i
Python program:
def next ( arr , target ) :
    start = 0 ;
    end = len ( arr ) - 1 ;
    if ( end == 0 ) :
        return - 1 ;
    if ( target > arr [ end ] ) :
        return end ;
    ans = - 1 ;
    while ( start <= end ) :
        mid = ( start + end ) // 2 ;
        if ( arr [ mid ] >= target ) :
            end = mid - 1 ;
        else :
            ans = mid ;
            start = mid + 1 ;
    return ans ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 5 , 8 , 12 ] ;
    print ( next ( arr , 5 ) ) ;

Index/key variables: end, mid
Python program:
def next ( arr , target ) :
    start = 0 ;
    end = len ( arr ) - 1 ;
    ans = - 1 ;
    while ( start <= end ) :
        mid = ( start + end ) // 2 ;
        if ( arr [ mid ] <= target ) :
            start = mid + 1 ;
        else :
            ans = mid ;
            end = mid - 1 ;
    return ans ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 5 , 8 , 12 ] ;
    print ( next ( arr , 8 ) ) ;

Index/key variables: mid
Python program:
def search ( arr , n , x ) :
    res = - 1
    for i in range ( 0 , n , 1 ) :
        if ( x == arr [ i ] ) :
            res = i
    if ( res == - 1 ) :
        return False
    temp = arr [ res ]
    i = res
    while ( i > 0 ) :
        arr [ i ] = arr [ i - 1 ]
        i -= 1
    arr [ 0 ] = temp
    return True
if __name__ == ' _ _ main _ _ ' :
    arr = [ 12 , 25 , 36 , 85 , 98 , 75 , 89 , 15 , 63 , 66 , 64 , 74 , 27 , 83 , 97 ]
    q = [ 63 , 63 , 86 , 63 , 78 ]
    n = len ( arr )
    m = len ( q )
    for i in range ( 0 , m , 1 ) :
        if ( search ( arr , n , q [ i ] ) ) :
            print ( " Yes " , end = " ▁ " )
        else :
            print ( " No " , end = " ▁ " )

Index/key variables: i, res
Iterator variables: i
Python program:
def compare ( a , b ) :
    if a [ 0 ] == b [ 0 ] :
        return a [ 1 ] < b [ 1 ]
    return a [ 0 ] < b [ 0 ]
def findInd ( preSum , n , val ) :
    l , h = 0 , n - 1
    ans = - 1
    while l <= h :
        mid = ( l + h ) // 2
        if preSum [ mid ] [ 0 ] <= val :
            ans = mid
            l = mid + 1
        else :
            h = mid - 1
    return ans
def largestSub ( arr , n , k ) :
    maxlen = 0
    preSum = [ ]
    Sum = 0
    minInd = [ None ] * ( n )
    for i in range ( 0 , n ) :
        Sum = Sum + arr [ i ]
        preSum . append ( [ Sum , i ] )
    preSum . sort ( )
    minInd [ 0 ] = preSum [ 0 ] [ 1 ]
    for i in range ( 1 , n ) :
        minInd [ i ] = min ( minInd [ i - 1 ] , preSum [ i ] [ 1 ] )
    Sum = 0
    for i in range ( 0 , n ) :
        Sum = Sum + arr [ i ]
        if Sum > k :
            maxlen = i + 1
        else :
            ind = findInd ( preSum , n , Sum - k - 1 )
            if ind != - 1 and minInd [ ind ] < i :
                maxlen = max ( maxlen , i - minInd [ ind ] )
    return maxlen
if __name__ == " _ _ main _ _ " :
    arr = [ - 2 , 1 , 6 , - 3 ]
    n = len ( arr )
    k = 5
    print ( largestSub ( arr , n , k ) )

Index/key variables: i, ind, mid
Accumulator variables: preSum
Iterator variables: i
Python program:
from typing import List
def pairExists ( arr1 : List [ int ] , m : int , arr2 : List [ int ] , n : int ) -> bool :
    s = set ( )
    for i in range ( m ) :
        for j in range ( n ) :
            if ( arr2 [ 2 ] - arr1 [ 2 ] ) not in s :
                return True
        s . add ( arr1 [ i ] )
    return False
if __name__ == " _ _ main _ _ " :
    arr1 = [ 1 , 5 , 10 , 8 ]
    arr2 = [ 2 , 20 , 13 ]
    if ( pairExists ( arr1 , 4 , arr2 , 3 ) ) :
        print ( 1 )
    else :
        print ( 0 )

Index/key variables: i, int
Accumulator variables: s
Iterator variables: i, j
Python program:
value = 0
def canBeOptimalValue ( K : int , arr : list , N : int , B : int ) -> bool :
    global value
    tmp = [ 0 ] * N
    for i in range ( N ) :
        tmp [ i ] = ( arr [ i ] + K * ( i + 1 ) )
    tmp . sort ( )
    value = 0
    for i in range ( K ) :
        value += tmp [ i ]
    return value <= B
def findNoOfElementsandValue ( arr : list , N : int , B : int ) :
    global value
    ans = 0
    value = 0
    while start <= end :
        mid = ( start + end ) // 2
        if canBeOptimalValue ( mid , arr , N , B ) :
            ans = mid
            start = mid + 1
        else :
            end = mid - 1
    canBeOptimalValue ( ans , arr , N , B )
    print ( ans , value )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 5 , 6 , 3 ]
    N = len ( arr )
    B = 90
    findNoOfElementsandValue ( arr , N , B )

Index/key variables: i
Accumulator variables: value
Iterator variables: i
Python program:
def prevGreater ( arr , n ) :
    print ( " - 1" , end = " , ▁ " )
    for i in range ( 1 , n ) :
        flag = 0
        for j in range ( i - 1 , - 1 , - 1 ) :
            if arr [ i ] < arr [ j ] :
                print ( arr [ j ] , end = " , ▁ " )
                flag = 1
                break
        if j == 0 and flag == 0 :
            print ( " - 1" , end = " , ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ 10 , 4 , 2 , 20 , 40 , 12 , 30 ]
    n = len ( arr )
    prevGreater ( arr , n )

Index/key variables: i, j
Iterator variables: i, j
Python program:
import math as mt
def prevGreater ( arr , n ) :
    s = list ( ) ;
    s . append ( arr [ 0 ] )
    print ( " - 1 , ▁ " , end = " " )
    for i in range ( 1 , n ) :
        while ( len ( s ) > 0 and s [ - 1 ] < arr [ i ] ) :
            s . pop ( )
        if len ( s ) == 0 :
            print ( " - 1 , ▁ " , end = " " )
        else :
            print ( s [ - 1 ] , " , ▁ " , end = " " )
        s . append ( arr [ i ] )
arr = [ 10 , 4 , 2 , 20 , 40 , 12 , 30 ]
n = len ( arr )
prevGreater ( arr , n )

Index/key variables: i
Accumulator variables: s
Iterator variables: i
Python program:
def printDuplicates ( arr , n ) :
    fl = 0 ;
    for i in range ( 0 , n ) :
        if ( arr [ arr [ i ] % n ] >= n ) :
            if ( arr [ arr [ i ] % n ] < 2 * n ) :
                print ( arr [ i ] % n , end = " ▁ " )
                fl = 1 ;
        arr [ arr [ i ] % n ] += n ;
    if ( fl == 0 ) :
        print ( " - 1" )
arr = [ 1 , 6 , 3 , 1 , 3 , 6 , 6 ] ;
arr_size = len ( arr ) ;
printDuplicates ( arr , arr_size ) ;

Index/key variables: i
Iterator variables: i
Python program:
def findMissingNo ( arr , n ) :
    for i in range ( n ) :
        if ( arr [ i ] <= 0 or arr [ i ] > n ) :
            continue
        val = arr [ i ]
        while ( arr [ val - 1 ] != val ) :
            nextval = arr [ val - 1 ]
            arr [ val - 1 ] = val
            val = nextval
            if ( val <= 0 or val > n ) :
                break
    for i in range ( n ) :
        if ( arr [ i ] != i + 1 ) :
            return i + 1
    return n + 1
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 3 , 7 , 6 , 8 , - 1 , - 10 , 15 ]
    arr_size = len ( arr )
    missing = findMissingNo ( arr , arr_size )
    print ( " The ▁ smallest ▁ positive " , " missing ▁ number ▁ is ▁ " , missing )

Index/key variables: i
Iterator variables: i
Python program:
def findTriplets ( arr , n , sum ) :
    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 ) :
                    print ( arr [ i ] , " ▁ " , arr [ j ] , " ▁ " , arr [ k ] , sep = " " )
arr = [ 0 , - 1 , 2 , - 3 , 1 ]
n = len ( arr )
findTriplets ( arr , n , - 2 )

Index/key variables: i, j, k
Iterator variables: i, j, k
Python program:
import math as mt
def findTriplets ( arr , n , Sum ) :
    for i in range ( n - 1 ) :
        s = dict ( )
        for j in range ( i + 1 , n ) :
            x = Sum - ( arr [ i ] + arr [ j ] )
            if x in s . keys ( ) :
                print ( x , arr [ i ] , arr [ j ] )
            else :
                s [ arr [ j ] ] = 1
arr = [ 0 , - 1 , 2 , - 3 , 1 ]
Sum = - 2
n = len ( arr )
findTriplets ( arr , n , Sum )

Index/key variables: i, j
Iterator variables: i, j
Python program:
import sys
def maxProduct ( arr , n ) :
    if ( n < 4 ) :
        return - 1 ;
    max_product = - sys . maxsize ;
    for i in range ( 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 ) :
                    max_product = max ( max_product , arr [ i ] * arr [ j ] * arr [ k ] * arr [ l ] ) ;
    return max_product ;
arr = [ 10 , 3 , 5 , 6 , 20 ] ;
n = len ( arr ) ;
max = maxProduct ( arr , n ) ;
if ( max == - 1 ) :
    print ( " No ▁ Quadruple ▁ Exists " ) ;
else :
    print ( " Maximum ▁ product ▁ is " , max ) ;

Index/key variables: i, j, k, l
Iterator variables: i, j, k, l
Python program:
def maxSum ( arr , n ) :
    if ( n < 2 ) :
        return - 1
    ans = arr [ 0 ] + arr [ 1 ]
    for i in range ( 1 , n - 1 , 1 ) :
        ans = min ( ans , ( arr [ i ] + arr [ i + 1 ] ) )
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 12 , 2 , 2 ]
    n = len ( arr )
    print ( maxSum ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
N = 3
def getGreatestSum ( a ) :
    prev_max = 0
    for j in range ( N ) :
        if ( prev_max < a [ N - 1 ] [ j ] ) :
            prev_max = a [ N - 1 ] [ j ]
    sum = prev_max
    for i in range ( N - 2 , - 1 , - 1 ) :
        curr_max = - 2147483648
        for j in range ( N ) :
            if ( prev_max > a [ i ] [ j ] and a [ i ] [ j ] > curr_max ) :
                curr_max = a [ i ] [ j ]
        if ( curr_max == - 2147483648 ) :
            return - 1
        prev_max = curr_max
        sum = sum + prev_max
    return sum
a = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ]
print ( getGreatestSum ( a ) )
b = [ [ 4 , 5 , 6 ] , [ 4 , 5 , 6 ] , [ 4 , 5 , 6 ] ]
print ( getGreatestSum ( b ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
import math
def occurrenceDays ( n , firstday ) :
    days = [ " Monday " , " Tuesday " , " Wednesday " , " Thursday " , " Friday " , " Saturday " , " Sunday " ]
    count = [ 4 for i in range ( 0 , 7 ) ]
    pos = - 1
    for i in range ( 0 , 7 ) :
        if ( firstday == days [ i ] ) :
            pos = i
            break
    inc = n - 28
    for i in range ( pos , pos + inc ) :
        if ( i > 6 ) :
            count [ i % 7 ] = 5
        else :
            count [ i ] = 5
    for i in range ( 0 , 7 ) :
        print ( days [ i ] , " ▁ " , count [ i ] )
n = 31
firstday = " Tuesday "
occurrenceDays ( n , firstday )

Index/key variables: i
Iterator variables: i
Python program:
import math
def findElement ( n , k ) :
    left = 1
    right = math . pow ( 2 , n ) - 1
    while 1 :
        mid = int ( ( left + right ) / 2 )
        if k == mid :
            print ( ans )
            break
        ans -= 1
        if k < mid :
            right = mid - 1
        else :
            left = mid + 1
n = 4
k = 8
findElement ( n , k )

Accumulator variables: ans
Python program:
import math
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 . data = new_data
    new_node . next = head_ref
    head_ref = new_node
    return head_ref
def firstCommon ( head1 , head2 ) :
    while ( head1 != None ) :
        p = head2
        while ( p != None ) :
            if ( p . data == head1 . data ) :
                return head1 . data
            p = p . next
        head1 = head1 . next
    return 0
if __name__ == ' _ _ main _ _ ' :
    head1 = None
    head1 = push ( head1 , 20 )
    head1 = push ( head1 , 5 )
    head1 = push ( head1 , 15 )
    head1 = push ( head1 , 10 )
    head2 = None
    head2 = push ( head2 , 10 )
    head2 = push ( head2 , 2 )
    head2 = push ( head2 , 15 )
    head2 = push ( head2 , 8 )
    print ( firstCommon ( head1 , head2 ) )

Class/struct names: Node
Python program:
def findS ( s ) :
    _sum = 0
    n = 1
    while ( _sum < s ) :
        _sum += n
        n += 1
    n -= 1
    if _sum == s :
        return n
    return - 1
s = 15
n = findS ( s )
if n == - 1 :
    print ( " - 1" )
else :
    print ( n )

Accumulator variables: _sum, n
Python program:
def getCount ( arr , n , num1 , num2 ) :
    for i in range ( 0 , n ) :
        if ( arr [ i ] == num1 ) :
            break
    if ( i >= n - 1 ) :
        return 0
    for j in range ( n - 1 , i + 1 , - 1 ) :
        if ( arr [ j ] == num2 ) :
            break
    if ( j == i ) :
        return 0
    return ( j - i - 1 )
arr = [ 3 , 5 , 7 , 6 , 4 , 9 , 12 , 4 , 8 ]
n = len ( arr )
num1 = 5
num2 = 4
print ( getCount ( arr , n , num1 , num2 ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
ROW = 3
COL = 5
def minTotalDistance ( grid : list ) -> int :
    if ROW == 0 or COL == 0 :
        return 0
    vertical = [ ]
    horizontal = [ ]
    for i in range ( ROW ) :
        for j in range ( COL ) :
            if grid [ i ] [ j ] == 1 :
                vertical . append ( i )
                horizontal . append ( j )
    vertical . sort ( )
    horizontal . sort ( )
    size = len ( vertical ) // 2
    x = vertical [ size ]
    y = horizontal [ size ]
    distance = 0
    for i in range ( ROW ) :
        for j in range ( COL ) :
            if grid [ i ] [ j ] == 1 :
                distance += abs ( x - i ) + abs ( y - j )
    return distance
if __name__ == " _ _ main _ _ " :
    grid = [ [ 1 , 0 , 1 , 0 , 1 ] , [ 0 , 1 , 0 , 0 , 0 ] , [ 0 , 1 , 1 , 0 , 0 ] ]
    print ( minTotalDistance ( grid ) )

Index/key variables: i, j, size
Accumulator variables: distance, horizontal, vertical
Iterator variables: i, j
Python program:
from random import randint
def getRandom ( x , y ) :
    return randint ( x , y )
def randomizedBinarySearch ( arr , l , r , x ) :
    while ( l <= r ) :
        m = getRandom ( l , r )
        if ( arr [ m ] == x ) :
            return m
        if ( arr [ m ] < x ) :
            l = m + 1
        else :
            r = m - 1
    return - 1
arr = [ 2 , 3 , 4 , 10 , 40 ]
n = len ( arr )
x = 10
result = randomizedBinarySearch ( arr , 0 , n - 1 , x )
if result == 1 :
    print ( " Element ▁ is ▁ not ▁ present ▁ in ▁ array " )
else :
    print ( " Element ▁ is ▁ present ▁ at ▁ index " , result )

Index/key variables: m
Python program:
def countBuildings ( arr , n ) :
    count = 1
    curr_max = arr [ 0 ]
    for i in range ( 1 , n ) :
        if ( arr [ i ] > curr_max or arr [ i ] == curr_max ) :
            count += 1
            curr_max = arr [ i ]
    return count
arr = [ 7 , 4 , 8 , 2 , 9 ]
n = len ( arr )
print ( countBuildings ( arr , n ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def findExtra ( arr1 , arr2 , n ) :
    for i in range ( 0 , n ) :
        if ( arr1 [ i ] != arr2 [ i ] ) :
            return i
    return n
arr1 = [ 2 , 4 , 6 , 8 , 10 , 12 , 13 ]
arr2 = [ 2 , 4 , 6 , 8 , 10 , 12 ]
n = len ( arr2 )
print ( findExtra ( arr1 , arr2 , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def findExtra ( arr1 , arr2 , n ) :
    left = 0
    right = n - 1
    while ( left <= right ) :
        mid = ( int ) ( ( left + right ) / 2 )
        if ( arr2 [ mid ] == arr1 [ mid ] ) :
            left = mid + 1
        else :
            index = mid
            right = mid - 1
    return index
arr1 = [ 2 , 4 , 6 , 8 , 10 , 12 , 13 ]
arr2 = [ 2 , 4 , 6 , 8 , 10 , 12 ]
n = len ( arr2 )
print ( findExtra ( arr1 , arr2 , n ) )

Index/key variables: mid
Python program:
def computeCost ( arr , N , X ) :
    cost = 0
    for i in range ( N ) :
        cost += abs ( arr [ i ] - X )
    return cost
def minCostToMakeElementEqual ( arr , N ) :
    low = high = arr [ 0 ]
    for i in range ( N ) :
        if ( low > arr [ i ] ) : low = arr [ i ]
        if ( high < arr [ i ] ) : high = arr [ i ]
    while ( ( high - low ) > 2 ) :
        mid1 = low + ( high - low ) // 3
        mid2 = high - ( high - low ) // 3
        cost1 = computeCost ( arr , N , mid1 )
        cost2 = computeCost ( arr , N , mid2 )
        if ( cost1 < cost2 ) :
            high = mid2
        else :
            low = mid1
    return computeCost ( arr , N , ( low + high ) // 2 )
arr = [ 1 , 100 , 101 ]
N = len ( arr )
print ( minCostToMakeElementEqual ( arr , N ) )

Index/key variables: i
Accumulator variables: cost
Iterator variables: i
Python program:
def minJumps ( w , l , n ) :
    if ( n == 1 ) :
        print ( 0 )
        return
    ans = 0
    pos = { }
    jump = { }
    filled = { }
    a = [ 0 for i in range ( n ) ]
    for i in range ( n ) :
        pos [ w [ i ] ] = i
        filled [ i ] = True
        jump [ w [ i ] ] = l [ i ]
        a [ i ] = w [ i ]
    a . sort ( )
    for curr in range ( 1 , n , 1 ) :
        currElementPos = pos [ a [ curr ] ]
        prevElementPos = pos [ a [ curr - 1 ] ]
        if ( currElementPos > prevElementPos ) :
            continue
        while ( currElementPos <= prevElementPos or ( currElementPos in filled and filled [ currElementPos ] ) ) :
            currElementPos += jump [ a [ curr ] ]
            ans += 1
        pos [ a [ curr ] ] = currElementPos
        filled [ currElementPos ] = True
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    W = [ 2 , 1 , 4 , 3 ]
    L = [ 4 , 1 , 2 , 4 ]
    N = len ( W )
    minJumps ( W , L , N )

Index/key variables: curr, currElementPos, i
Accumulator variables: ans
Iterator variables: curr, i
Python program:
def check ( arr , n ) :
    for i in range ( 1 , n ) :
        if ( arr [ i - 1 ] >= ( i - 1 ) ) :
            p = arr [ i - 1 ] - ( i - 1 )
            arr [ i ] += p
            arr [ i - 1 ] -= p
    for i in range ( 1 , n ) :
        if ( arr [ i ] <= arr [ i - 1 ] ) :
            print ( " No " )
            return
    print ( " Yes " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 5 , 2 , 7 , 6 ]
    N = len ( arr )
    check ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
def keyFunc ( n ) :
    rev = 0
    while ( n > 0 ) :
        rev = rev << 1
        if ( n & 1 == 1 ) :
            rev = rev ^ 1
        n = n >> 1
    return rev
def getNew ( arr ) :
    ans = [ ]
    for i in arr :
        ans . append ( [ keyFunc ( i ) , i ] )
    return ans
def getArr ( arr ) :
    ans = [ ]
    for i in arr :
        ans . append ( i [ 1 ] )
    return ans
def sortArray ( arr ) :
    newArr = getNew ( arr )
    newArr . sort ( )
    arr = getArr ( newArr )
    print ( arr )
arr = [ 43 , 52 , 61 , 41 ]
sortArray ( arr )

Accumulator variables: ans
Iterator variables: i
Python program:
def minimumSize ( arr , N , K ) :
    arr . sort ( )
    arr . reverse ( )
    zero = arr . count ( 0 )
    if zero == N :
        print ( 0 )
    elif K >= N :
        print ( 1 )
    else :
        print ( arr [ K ] )
arr = [ 2 , 4 , 8 , 2 ]
K = 2
N = len ( arr )
minimumSize ( arr , N , K )

Index/key variables: K