dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
import math
def magnitude ( arr , N ) :
    magnitude = 0
    for i in range ( N ) :
        magnitude += arr [ i ] * arr [ i ]
    return math . sqrt ( magnitude )
def dotProduct ( arr , brr , N ) :
    product = 0
    for i in range ( N ) :
        product = product + arr [ i ] * brr [ i ]
    return product
def angleBetweenVectors ( arr , brr , N ) :
    dotProductOfVectors = dotProduct ( arr , brr , N )
    magnitudeOfA = magnitude ( arr , N )
    magnitudeOfB = magnitude ( brr , N )
    angle = ( dotProductOfVectors / ( magnitudeOfA * magnitudeOfB ) )
    print ( ' % .5f ' % angle )
if __name__ == " _ _ main _ _ " :
    arr = [ - 0.5 , - 2 , 1 ]
    brr = [ - 1 , - 1 , 0.3 ]
    N = len ( arr )
    angleBetweenVectors ( arr , brr , N )

Index/key variables: i
Accumulator variables: magnitude
Iterator variables: i
Python program:
class Node :
    def __init__ ( self ) :
        self . key = 0
        self . left = None
        self . right = None
def newNode ( key : int ) -> Node :
    temp = Node ( )
    temp . key = key
    temp . left = None
    temp . right = None
    return temp
def findLCA ( root : Node , n1 : int , n2 : int ) -> Node :
    if root is None :
        return None
    if root . key == n1 or root . key == n2 :
        return root
    left_lca = findLCA ( root . left , n1 , n2 )
    right_lca = findLCA ( root . right , n1 , n2 )
    if left_lca and right_lca :
        return root
    return ( left_lca if left_lca is not None else right_lca )
def countTurn ( root : Node , key : int , turn : bool ) -> bool :
    global count
    if root is None :
        return False
    if root . key == key :
        return True
    if turn is True :
        if countTurn ( root . left , key , turn ) :
            return True
        if countTurn ( root . right , key , not turn ) :
            count += 1
            return True
    else :
        if countTurn ( root . right , key , turn ) :
            return True
        if countTurn ( root . left , key , not turn ) :
            count += 1
            return True
    return False
def numberOfTurn ( root : Node , first : int , second : int ) -> int :
    global count
    LCA = findLCA ( root , first , second )
    if LCA is None :
        return - 1
    count = 0
    if LCA . key != first and LCA . key != second :
        if countTurn ( LCA . right , second , False ) or countTurn ( LCA . left , second , True ) :
            pass
        if countTurn ( LCA . left , first , True ) or countTurn ( LCA . right , first , False ) :
            pass
        return count + 1
    if LCA . key == first :
        countTurn ( LCA . right , second , False )
        countTurn ( LCA . left , second , True )
        return count
    else :
        countTurn ( LCA . right , first , False )
        countTurn ( LCA . left , first , True )
        return count
if __name__ == " _ _ main _ _ " :
    count = 0
    root = Node ( )
    root = newNode ( 1 )
    root . left = newNode ( 2 )
    root . right = newNode ( 3 )
    root . left . left = newNode ( 4 )
    root . left . right = newNode ( 5 )
    root . right . left = newNode ( 6 )
    root . right . right = newNode ( 7 )
    root . left . left . left = newNode ( 8 )
    root . right . left . left = newNode ( 9 )
    root . right . left . right = newNode ( 10 )
    turn = numberOfTurn ( root , 5 , 10 )
    if turn :
        print ( turn )
    else :
        print ( " Not ▁ possible " )

Class/struct names: Node
Python program:
class Node :
    def __init__ ( self , x ) :
        self . data = x
        self . left = None
        self . right = None
        self . abtr = None
even_ptrs = [ ]
odd_ptrs = [ ]
def preorderTraversal ( root ) :
    global even_ptrs , odd_ptrs
    if ( not root ) :
        return
    if ( root . data % 2 == 0 ) :
        even_ptrs . append ( root )
    else :
        odd_ptrs . append ( root )
    preorderTraversal ( root . left )
    preorderTraversal ( root . right )
def createLoops ( root ) :
    preorderTraversal ( root )
    i = 1
    while i < len ( even_ptrs ) :
        even_ptrs [ i - 1 ] . abtr = even_ptrs [ i ]
        i += 1
    even_ptrs [ i - 1 ] . abtr = even_ptrs [ 0 ]
    i = 1
    while i < len ( odd_ptrs ) :
        odd_ptrs [ i - 1 ] . abtr = odd_ptrs [ i ]
        i += 1
    odd_ptrs [ i - 1 ] . abtr = odd_ptrs [ 0 ]
def traverseLoop ( start ) :
    curr = start
    while True and curr :
        print ( curr . data , end = " ▁ " )
        curr = curr . abtr
        if curr == start :
            break
    print ( )
if __name__ == ' _ _ main _ _ ' :
    root = None
    root = Node ( 1 )
    root . left = Node ( 2 )
    root . right = Node ( 3 )
    root . left . left = Node ( 4 )
    root . left . right = Node ( 5 )
    root . right . left = Node ( 6 )
    root . right . right = Node ( 7 )
    createLoops ( root )
    print ( " Odd ▁ nodes : " , end = " ▁ " )
    traverseLoop ( root . right )
    print ( " Even ▁ nodes : " , end = " ▁ " )
    traverseLoop ( root . left )

Index/key variables: i
Class/struct names: Node
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
def isLeaf ( t ) :
    return ( ( t . left == None ) and ( t . right == None ) )
def findFirstUnmatch ( root1 , root2 ) :
    if ( root1 == None or root2 == None ) :
        return
    s1 = [ ]
    s2 = [ ]
    s1 . insert ( 0 , root1 )
    s2 . insert ( 0 , root2 )
    while ( len ( s1 ) or len ( s2 ) ) :
        if ( len ( s1 ) == 0 or len ( s2 ) == 0 ) :
            return
        temp1 = s1 [ 0 ]
        s1 . pop ( 0 )
        while ( temp1 and not isLeaf ( temp1 ) ) :
            s1 . insert ( 0 , temp1 . right )
            s1 . insert ( 0 , temp1 . left )
            temp1 = s1 [ 0 ]
            s1 . pop ( 0 )
        temp2 = s2 [ 0 ]
        s2 . pop ( 0 )
        while ( temp2 and not isLeaf ( temp2 ) ) :
            s2 . insert ( 0 , temp2 . right )
            s2 . insert ( 0 , temp2 . left )
            temp2 = s2 [ 0 ]
            s2 . pop ( 0 )
        if ( temp1 != None and temp2 != None ) :
            if ( temp1 . data != temp2 . data ) :
                print ( " First ▁ non ▁ matching ▁ leaves ▁ : " , temp1 . data , " " , temp2 . data )
                return
if __name__ == ' _ _ main _ _ ' :
    root1 = newNode ( 5 )
    root1 . left = newNode ( 2 )
    root1 . right = newNode ( 7 )
    root1 . left . left = newNode ( 10 )
    root1 . left . right = newNode ( 11 )
    root2 = newNode ( 6 )
    root2 . left = newNode ( 10 )
    root2 . right = newNode ( 15 )
    findFirstUnmatch ( root1 , root2 )

Class/struct names: newNode
Python program:
def maxOfLeftElement ( root ) :
    res = - 999999999999
    if ( root == None ) :
        return res
    if ( root . left != None ) :
        res = root . left . data
    return max ( { maxOfLeftElement ( root . left ) , res , maxOfLeftElement ( root . right ) } )
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 7 )
    root . left = newNode ( 6 )
    root . right = newNode ( 5 )
    root . left . left = newNode ( 4 )
    root . left . right = newNode ( 3 )
    root . right . left = newNode ( 2 )
    root . right . right = newNode ( 1 )
    print ( maxOfLeftElement ( root ) )

Class/struct names: newNode
Python program:
import math
class Optimum_distance :
    class Point :
        def __init__ ( self , x , y ) :
            self . x = x
            self . y = y
    class Line :
        def __init__ ( self , a , b , c ) :
            self . a = a
            self . b = b
            self . c = c
    def dist ( self , x , y , p ) :
        return math . sqrt ( ( x - p . x ) ** 2 + ( y - p . y ) ** 2 )
    def compute ( self , p , n , l , x ) :
        res = 0
        y = - 1 * ( l . a * x + l . c ) / l . b
        for i in range ( n ) :
            res += self . dist ( x , y , p [ i ] )
        return res
    def find_Optimum_cost_untill ( self , p , n , l ) :
        low = - 1e6
        high = 1e6
        eps = 1e-6 + 1
        while ( ( high - low ) > eps ) :
            mid1 = low + ( high - low ) / 3
            mid2 = high - ( high - low ) / 3
            dist1 = self . compute ( p , n , l , mid1 )
            dist2 = self . compute ( p , n , l , mid2 )
            if ( dist1 < dist2 ) :
                high = mid2
            else :
                low = mid1
        return self . compute ( p , n , l , ( low + high ) / 2 )
    def find_Optimum_cost ( self , p , l ) :
        n = len ( p )
        p_arr = [ None ] * n
        for i in range ( n ) :
            p_obj = self . Point ( p [ i ] [ 0 ] , p [ i ] [ 1 ] )
            p_arr [ i ] = p_obj
        return self . find_Optimum_cost_untill ( p_arr , n , l )
if __name__ == " _ _ main _ _ " :
    obj = Optimum_distance ( )
    l = obj . Line ( 1 , - 1 , - 3 )
    p = [ [ - 3 , - 2 ] , [ - 1 , 0 ] , [ - 1 , 2 ] , [ 1 , 2 ] , [ 3 , 4 ] ]
    print ( obj . find_Optimum_cost ( p , l ) )

Index/key variables: i
Accumulator variables: res
Iterator variables: i
Class/struct names: Line, Optimum_distance, Point
Python program:
def segmentUnionLength ( segments ) :
    n = len ( segments )
    points = [ None ] * ( n * 2 )
    for i in range ( n ) :
        points [ i * 2 ] = ( segments [ i ] [ 0 ] , False )
        points [ i * 2 + 1 ] = ( segments [ i ] [ 1 ] , True )
    points = sorted ( points , key = lambda x : x [ 0 ] )
    result = 0
    Counter = 0
    for i in range ( 0 , n * 2 ) :
        if ( i > 0 ) & ( points [ i ] [ 0 ] > points [ i - 1 ] [ 0 ] ) & ( Counter > 0 ) :
            result += ( points [ i ] [ 0 ] - points [ i - 1 ] [ 0 ] )
        if points [ i ] [ 1 ] :
            Counter -= 1
        else :
            Counter += 1
    return result
if __name__ == ' _ _ main _ _ ' :
    segments = [ ( 2 , 5 ) , ( 4 , 8 ) , ( 9 , 12 ) ]
    print ( segmentUnionLength ( segments ) )

Index/key variables: i
Accumulator variables: Counter, result
Iterator variables: i
Python program:
def findElements ( arr , N ) :
    i = 0 ;
    missing = [ ] ;
    duplicate = set ( ) ;
    while ( i != N ) :
        if ( arr [ i ] != arr [ arr [ i ] - 1 ] ) :
            t = arr [ i ]
            arr [ i ] = arr [ arr [ i ] - 1 ]
            arr [ t - 1 ] = t
        else :
            i += 1 ;
    for i in range ( N ) :
        if ( arr [ i ] != i + 1 ) :
            missing . append ( i + 1 ) ;
            duplicate . add ( arr [ i ] ) ;
    print ( " Missing ▁ Numbers : ▁ " , end = " " ) ;
    for it in missing :
        print ( it , end = " ▁ " ) ;
    print ( " Duplicate Numbers : " , end = " " ) ;
    for it in list ( duplicate ) :
        print ( it , end = ' ▁ ' ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 2 , 2 , 4 , 5 , 7 ] ;
    N = len ( arr ) ;
    findElements ( arr , N ) ;

Index/key variables: i
Accumulator variables: duplicate, missing
Iterator variables: i, it
Python program:
def isPossible ( A , B , C , N ) :
    if ( len ( A ) == 0 or len ( B ) == 0 ) :
        if ( len ( C ) == N ) :
            return True
        else :
            return False
    ans = False
    for x in A :
        for y in B :
            _A = A
            _A . remove ( x )
            _B = B
            _B . remove ( y )
            _C = C
            _C . add ( ( x + y ) % N )
            ans = ( ans or isPossible ( _A , _B , _C , N ) )
    return ans
def rearrangeArray ( arr , N , K ) :
    A = [ ]
    for i in range ( N ) :
        A . append ( arr [ i ] % N )
    A . sort ( )
    B = [ ]
    for i in range ( N ) :
        B . append ( ( i * K ) % N )
    B . sort ( )
    C = set ( )
    if isPossible ( A , B , C , N ) :
        print ( " YES " )
    else :
        print ( " NO " )
arr = [ 1 , 2 , 0 ]
K = 5
N = len ( arr )
rearrangeArray ( arr , N , K )

Index/key variables: i
Accumulator variables: A, B, _C
Iterator variables: i, x, y
Boolean variables: ans
Python program:
from math import sqrt
def factorTree ( N ) :
    height = 0
    while ( N > 1 ) :
        flag = False
        for i in range ( 2 , int ( sqrt ( N ) ) + 1 , 1 ) :
            if ( N % i == 0 ) :
                N = N // i
                flag = True
                break
        height += 1
        if ( flag == False ) :
            break
    return height
if __name__ == ' _ _ main _ _ ' :
    N = 48
    print ( factorTree ( N ) )

Accumulator variables: height
Iterator variables: i
Boolean variables: flag
Python program:
a = [ ]
seg_tree = [ ]
query = [ ]
def build_tree ( v , tl , tr ) :
    global a , seg_tree , query
    if ( tl != tr ) :
        if ( a [ tl ] == 0 ) :
            seg_tree [ v ] = 1
        else :
            seg_tree [ v ] = 0
    else :
        tm = int ( ( tl + tr ) / 2 )
        build_tree ( v * 2 , tl , tm )
        build_tree ( v * 2 + 1 , tm + 1 , tr )
        seg_tree [ v ] = seg_tree [ v * 2 ] + seg_tree [ v * 2 + 1 ]
def frequency_zero ( v , tl , tr , l , r ) :
    global a , seg_tree , query
    if ( l > r ) :
        return 0
    if ( l == tl and r == tr ) :
        return seg_tree [ v ]
    tm = int ( ( tl + tr ) / 2 )
    return frequency_zero ( v * 2 , tl , tm , l , min ( r , tm ) ) + frequency_zero ( v * 2 + 1 , tm + 1 , tr , max ( l , tm + 1 ) , r )
def update ( v , tl , tr , pos , new_val ) :
    global a , seg_tree , query
    if ( tl == tr ) :
        if ( new_val == 0 ) :
            seg_tree [ v ] = 1
        else :
            seg_tree [ v ] = 0
    else :
        tm = int ( ( tl + tr ) / 2 )
        if ( pos <= tm ) :
            update ( v * 2 , tl , tm , pos , new_val )
        else :
            update ( v * 2 + 1 , tm + 1 , tr , pos , new_val )
        seg_tree [ v ] = seg_tree [ v * 2 ] + seg_tree [ v * 2 + 1 ]
def solve ( n , q ) :
    global a , seg_tree , query
    qu = [ 5 , 3 , 6 ]
    seg_tree = [ 0 ] * ( 4 * n + 1 )
    build_tree ( 1 , 0 , n - 1 )
    for i in range ( len ( qu ) ) :
        print ( qu [ i ] )
    for i in range ( q , q ) :
        if query [ i - 1 ] [ 0 ] == 1 :
            l = query [ i - 1 ] [ 1 ]
            r = query [ i - 1 ] [ 2 ]
            print ( frequency_zero ( 1 , 0 , n - 1 , l , r ) )
        else :
            a [ query [ i - 1 ] [ 1 ] ] = query [ i - 1 ] [ 2 ]
            pos = query [ i - 1 ] [ 1 ]
            new_val = query [ i - 1 ] [ 2 ]
            update ( 1 , 0 , n - 1 , pos , new_val )
a = [ 9 , 5 , 7 , 6 , 9 , 0 , 0 , 0 , 0 , 5 , 6 , 7 , 3 , 9 , 0 , 7 , 0 , 9 , 0 ]
Q = 5
query = [ [ 1 , 5 , 14 ] , [ 2 , 6 , 1 ] , [ 1 , 0 , 8 ] , [ 2 , 13 , 0 ] , [ 1 , 6 , 18 ] ]
N = len ( a )
solve ( N , Q )

Index/key variables: i, tl, v
Iterator variables: i
Python program:
from collections import deque
InF = 99999
class number :
    def __init__ ( self , n , l ) :
        self . no = n
        self . level = l
def findnthnumber ( n ) :
    q = deque ( )
    r = number ( 0 , 1 )
    q . append ( r )
    while ( len ( q ) > 0 ) :
        temp = q . popleft ( )
        if ( temp . no >= InF or temp . no <= - InF ) :
            break
        if ( temp . no == n ) :
            print ( " Found ▁ number ▁ n ▁ at ▁ level " , temp . level - 1 )
            break
        q . append ( number ( temp . no + temp . level , temp . level + 1 ) )
        q . append ( number ( temp . no - temp . level , temp . level + 1 ) )
if __name__ == ' _ _ main _ _ ' :
    findnthnumber ( 13 )

Accumulator variables: q
Class/struct names: number
Python program:
def Avgdifference ( arr , N , K ) :
    min = 1000000 ;
    max = - 1 ;
    for i in range ( N - K + 1 ) :
        sum = 0 ;
        for j in range ( K ) :
            sum += arr [ i + j ] ;
        if ( min > sum ) :
            min = sum ;
        if ( max < sum ) :
            max = sum ;
    return ( max - min ) / K ;
arr = [ 3 , 8 , 9 , 15 ] ;
N = len ( arr ) ;
K = 2 ;
print ( Avgdifference ( arr , N , K ) ) ;

Accumulator variables: sum
Iterator variables: i, j
Python program:
def find ( n ) :
    ans = [ ]
    Sum = 0
    i = 0
    sign = 0
    if ( n >= 0 ) :
        sign = 1
    else :
        sign = - 1
    n = abs ( n )
    i = 1
    while ( Sum < n ) :
        ans . append ( sign * i )
        Sum += i
        i += 1
    if ( Sum > sign * n ) :
        if ( i % 2 != 0 ) :
            Sum -= n
            if ( Sum % 2 != 0 ) :
                ans . append ( sign * i )
                Sum += i
                i += 1
            ans [ int ( Sum / 2 ) - 1 ] *= - 1
        else :
            Sum -= n
            if ( Sum % 2 != 0 ) :
                Sum -= 1
                ans . append ( sign * i )
                ans . append ( sign * - 1 * ( i + 1 ) )
            ans [ int ( ( sum / 2 ) ) - 1 ] *= - 1
    return ans
n = 20
if ( n == 0 ) :
    print ( " Minimum number of Steps : 0 Step sequence : 0 " )
else :
    a = find ( n )
    print ( " Minimum ▁ number ▁ of ▁ Steps : " , len ( a ) )
    print ( " Step ▁ sequence : " )
    print ( * a , sep = " ▁ " )

Accumulator variables: Sum, ans, i
Python program:
import sys
def MaxRange ( A , n ) :
    left = [ 0 ] * n
    right = [ 0 ] * n
    s = [ ]
    s . append ( ( sys . maxsize , - 1 ) )
    for i in range ( n ) :
        while ( s [ - 1 ] [ 0 ] < A [ i ] ) :
            s . pop ( )
        left [ i ] = s [ - 1 ] [ 1 ]
        s . append ( ( A [ i ] , i ) )
    while ( len ( s ) != 0 ) :
        s . pop ( )
    s . append ( ( sys . maxsize , n ) )
    for i in range ( n - 1 , - 1 , - 1 ) :
        while ( s [ - 1 ] [ 0 ] < A [ i ] ) :
            s . pop ( )
        right [ i ] = s [ - 1 ] [ 1 ]
        s . append ( ( A [ i ] , i ) )
    for i in range ( n ) :
        print ( left [ i ] + 1 , ' ▁ ' , right [ i ] - 1 )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 3 , 2 ]
    n = len ( arr )
    MaxRange ( arr , n )

Index/key variables: i
Accumulator variables: s
Iterator variables: i
Python program:
def nthNumber ( n ) :
    divs = [ 0 for i in range ( 1000000 ) ] ;
    vis = [ 0 for i in range ( 1000000 ) ] ;
    cnt = 0 ;
    for i in range ( 2 , n ) :
        if ( divs [ i ] == 0 ) :
            for j in range ( 2 * i , 1000000 ) :
                if ( vis [ j ] ) :
                    continue ;
                vis [ j ] = 1 ;
                currNum = j ;
                count = 0 ;
                while ( currNum % i == 0 ) :
                    divs [ j ] += 1 ;
                    currNum = currNum // i ;
                    count += 1 ;
                if ( currNum == 1 and count == 3 and divs [ j ] == 3 ) :
                    cnt += 1
                elif ( currNum != 1 and divs [ currNum ] == 0 and count == 1 and divs [ j ] == 1 ) :
                    cnt += 1
                if ( cnt == n ) :
                    return j ;
    return - 1 ;
N = 24 ;
print ( nthNumber ( N ) ) ;

Index/key variables: currNum, i, j
Accumulator variables: cnt, count
Iterator variables: i, j
Python program:
def findkey ( A , B , C ) :
    ans = 0
    cur = 1
    while ( A > 0 ) :
        a = A % 10
        b = B % 10
        c = C % 10
        A = A // 10
        B = B // 10
        C = C // 10
        m = max ( a , max ( c , b ) )
        ans += cur * m
        cur = cur * 10
    return ans
if __name__ == ' _ _ main _ _ ' :
    A = 3521
    B = 2452
    C = 1352
    print ( findkey ( A , B , C ) )

Accumulator variables: ans
Python program:
from math import gcd
def distinctGCDs ( arr , N ) :
    M = - 1
    ans = 0
    Mp = { }
    for i in range ( N ) :
        M = max ( M , arr [ i ] )
        Mp [ arr [ i ] ] = 1
    for i in range ( 1 , M + 1 , 1 ) :
        currGcd = 0
        for j in range ( i , M + 1 , i ) :
            if ( j in Mp ) :
                currGcd = gcd ( currGcd , j )
                if ( currGcd == i ) :
                    ans += 1
                    break
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 11 , 14 , 6 , 12 ]
    N = len ( arr )
    print ( distinctGCDs ( arr , N ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i, j
Python program:
class TreeNode :
    def __init__ ( self , val = ' ' , left = None , right = None ) :
        self . val = val
        self . left = left
        self . right = right
def findCompressValue ( arr ) :
    ans = 0
    getBit = 1
    for i in range ( 32 ) :
        S = 0
        NS = 0
        for j in arr :
            if getBit & j :
                S += 1
            else :
                NS += 1
        if S > NS :
            ans += 2 ** i
        getBit <<= 1
    return ans
def findInteger ( root ) :
    mp = { }
    def diagonalOrder ( root , d , mp ) :
        if not root :
            return
        try :
            mp [ d ] . append ( root . val )
        except KeyError :
            mp [ d ] = [ root . val ]
        diagonalOrder ( root . left , d + 1 , mp )
        diagonalOrder ( root . right , d , mp )
    diagonalOrder ( root , 0 , mp )
    arr = [ ]
    for i in mp :
        arr . append ( findCompressValue ( mp [ i ] ) )
    return findCompressValue ( arr )
root = TreeNode ( 6 )
root . left = TreeNode ( 5 )
root . right = TreeNode ( 3 )
root . left . left = TreeNode ( 3 )
root . left . right = TreeNode ( 5 )
root . right . left = TreeNode ( 3 )
root . right . right = TreeNode ( 4 )
print ( findInteger ( root ) )

Index/key variables: d, i
Accumulator variables: NS, S, ans, arr, getBit
Iterator variables: i, j
Class/struct names: TreeNode
Python program:
import sys
def eggDrop ( n , k ) :
    if ( k == 1 or k == 0 ) :
        return k
    if ( n == 1 ) :
        return k
    min = sys . maxsize
    for x in range ( 1 , k + 1 ) :
        res = max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) )
        if ( res < min ) :
            min = res
    return min + 1
if __name__ == " _ _ main _ _ " :
    n = 2
    k = 10
    print ( " Minimum ▁ number ▁ of ▁ trials ▁ in ▁ worst ▁ case ▁ with " , n , " eggs ▁ and " , k , " floors ▁ is " , eggDrop ( n , k ) )

Iterator variables: x
Python program:
def kthDigitFromLast ( n , k ) :
    if ( k <= 0 ) :
        print ( " - 1" )
        return
    while ( ( k - 1 ) > 0 and n > 0 ) :
        n = n / 10
        k -= 1
    if ( n == 0 ) :
        print ( " - 1" )
    else :
        print ( int ( n % 10 ) )
if __name__ == ' _ _ main _ _ ' :
    n = 2354
    k = 2
    kthDigitFromLast ( n , k )

Accumulator variables: k
Python program:
def EditDistDP ( str1 , str2 ) :
    len1 = len ( str1 )
    len2 = len ( str2 )
    DP = [ [ 0 for i in range ( len1 + 1 ) ] for j in range ( 2 ) ] ;
    for i in range ( 0 , len1 + 1 ) :
        DP [ 0 ] [ i ] = i
    for i in range ( 1 , len2 + 1 ) :
        for j in range ( 0 , len1 + 1 ) :
            if ( j == 0 ) :
                DP [ i % 2 ] [ j ] = i
            elif ( str1 [ j - 1 ] == str2 [ i - 1 ] ) :
                DP [ i % 2 ] [ j ] = DP [ ( i - 1 ) % 2 ] [ j - 1 ]
            else :
                DP [ i % 2 ] [ j ] = ( 1 + min ( DP [ ( i - 1 ) % 2 ] [ j ] , min ( DP [ i % 2 ] [ j - 1 ] , DP [ ( i - 1 ) % 2 ] [ j - 1 ] ) ) )
    print ( DP [ len2 % 2 ] [ len1 ] , " " )
if __name__ == ' _ _ main _ _ ' :
    str1 = " food "
    str2 = " money "
    EditDistDP ( str1 , str2 )

Index/key variables: i, j, len1
Iterator variables: i, j
Python program:
def xorSumOfArray ( arr , n , k , count ) :
    sum = 0
    p = 1
    for i in range ( 31 ) :
        val = 0
        if ( ( k & ( 1 << i ) ) != 0 ) :
            not_set = n - count [ i ]
            val = ( ( not_set ) * p )
        else :
            val = ( count [ i ] * p )
        sum += val
        p = ( p * 2 )
    return sum
def sumOfXors ( arr , n , queries , q ) :
    count = [ 0 for i in range ( 32 ) ]
    for i in range ( n ) :
        for j in range ( 31 ) :
            if ( arr [ i ] & ( 1 << j ) ) :
                count [ j ] += 1
    for i in range ( q ) :
        k = queries [ i ]
        print ( xorSumOfArray ( arr , n , k , count ) , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 5 , 2 , 3 ]
    queries = [ 3 , 8 , 7 ]
    n = len ( arr )
    q = len ( queries )
    sumOfXors ( arr , n , queries , q )

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