dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def FindMax ( arr , N ) :
    maxi = - 1
    maxi2 = - 1
    count = 0
    for i in range ( N ) :
        if ( arr [ i ] == 0 ) :
            count = 0
        else :
            count += 1
            maxi = max ( maxi , count )
    for i in range ( N ) :
        if ( arr [ i ] == 1 ) :
            count += 1
            if ( count > maxi2 and count < maxi ) :
                maxi2 = count
        if ( arr [ i ] == 0 ) :
            count = 0
    maxi = max ( maxi , 0 )
    maxi2 = max ( maxi2 , 0 )
    print ( maxi2 )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 1 , 1 , 0 , 0 , 1 , 1 ]
    N = len ( arr )
    FindMax ( arr , N )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
import sys
def mindist ( left , right ) :
    res = sys . maxsize
    for i in range ( len ( left ) ) :
        num = left [ i ]
        index = right . index ( min ( [ i for i in right if num >= i ] ) )
        if ( index == 0 ) :
            res = min ( res , abs ( num - right [ index ] ) )
        elif ( index == len ( right ) ) :
            res = min ( res , min ( abs ( num - right [ index - 1 ] ) , abs ( num - right [ index ] ) ) )
    return res
def specialPairs ( nums ) :
    m = { }
    vals = [ ]
    for i in range ( len ( nums ) ) :
        m [ nums [ i ] ] = i
    for p in m :
        vals . append ( p )
    res = sys . maxsize
    for i in range ( 1 , len ( vals ) ) :
        vec = [ m [ vals [ i ] ] ]
        for i in range ( 1 , len ( vec ) ) :
            res = min ( res , abs ( vec [ i ] - vec [ i - 1 ] ) )
        if ( i ) :
            a = vals [ i ]
            left = [ m [ a ] ]
            b = vals [ i - 1 ]
            right = [ m [ b ] ]
            res = min ( res , mindist ( left , right ) ) + 1
    return res
if __name__ == " _ _ main _ _ " :
    arr = [ 0 , - 10 , 5 , - 5 , 1 ]
    print ( specialPairs ( arr ) )

Index/key variables: a, b, i, index
Accumulator variables: vals
Iterator variables: i, p
Python program:
from collections import deque , Counter , defaultdict
import sys
def maximumOccurringString ( s , K ) :
    M = { }
    D = deque ( )
    for i in range ( K ) :
        D . append ( s [ i ] )
    M [ str ( " " . join ( list ( D ) ) ) ] = M . get ( str ( " " . join ( list ( D ) ) ) , 0 ) + 1
    D . popleft ( )
    for j in range ( i , len ( s ) ) :
        D . append ( s [ j ] )
        M [ str ( " " . join ( list ( D ) ) ) ] = M . get ( str ( " " . join ( list ( D ) ) ) , 0 ) + 1
        D . popleft ( )
    maxi = - sys . maxsize - 1
    ans = deque ( )
    for it in M :
        if ( M [ it ] >= maxi ) :
            maxi = M [ it ]
            ans = it
    for i in range ( len ( ans ) ) :
        print ( ans [ i ] , end = " " )
if __name__ == ' _ _ main _ _ ' :
    s = " bbbbbaaaaabbabababa "
    K = 5
    maximumOccurringString ( s , K )

Index/key variables: i, it, j
Accumulator variables: D
Iterator variables: i, it, j
Python program:
from collections import deque
from sys import maxsize as INT_MAX
mp = dict ( )
class Node :
    def __init__ ( self , key ) :
        self . key = key
        self . left = None
        self . right = None
def calculateMin ( root : Node , levelMin : list ) -> None :
    qt = deque ( )
    qt . append ( root )
    count = 1
    min_v = INT_MAX
    while ( qt ) :
        temp = qt . popleft ( )
        min_v = min ( min_v , temp . key )
        if ( temp . left ) :
            qt . append ( temp . left )
        if ( temp . right ) :
            qt . append ( temp . right )
        count -= 1
        if ( count == 0 ) :
            levelMin . append ( min_v )
            min_v = INT_MAX
            count = len ( qt )
def findNodes ( root : Node , levelMin : list , levelResult : list , level : int ) -> None :
    if ( root == None ) :
        return
    findNodes ( root . left , levelMin , levelResult , level + 1 )
    findNodes ( root . right , levelMin , levelResult , level + 1 )
    for i in range ( level ) :
        if ( root . key <= levelMin [ i ] ) :
            levelResult [ i ] += 1
def printNodes ( root : Node ) -> None :
    levelMin = [ ]
    calculateMin ( root , levelMin )
    numLevels = len ( levelMin )
    levelResult = [ 0 ] * numLevels
    findNodes ( root , levelMin , levelResult , 0 )
    for i in range ( numLevels ) :
        print ( levelResult [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    root = Node ( 4 )
    root . left = Node ( 3 )
    root . right = Node ( 5 )
    root . right . left = Node ( 3 )
    root . right . right = Node ( 1 )
    root . left . left = Node ( 10 )
    root . left . right = Node ( 2 )
    printNodes ( root )

Index/key variables: i
Accumulator variables: count, levelMin, qt
Iterator variables: i
Class/struct names: Node
Python program:
import random
class MyDS :
    def __init__ ( self ) :
        self . arr = [ ]
        self . hashd = { }
    def add ( self , x ) :
        if x in self . hashd :
            return
        s = len ( self . arr )
        self . arr . append ( x )
        self . hashd [ x ] = s
    def remove ( self , x ) :
        index = self . hashd . get ( x , None )
        if index == None :
            return
        del self . hashd [ x ]
        size = len ( self . arr )
        last = self . arr [ size - 1 ]
        self . arr [ index ] , self . arr [ size - 1 ] = self . arr [ size - 1 ] , self . arr [ index ]
        del self . arr [ - 1 ]
        self . hashd [ last ] = index
    def getRandom ( self ) :
        index = random . randrange ( 0 , len ( self . arr ) )
        return self . arr [ index ]
    def search ( self , x ) :
        return self . hashd . get ( x , None )
if __name__ == " _ _ main _ _ " :
    ds = MyDS ( )
    ds . add ( 10 )
    ds . add ( 20 )
    ds . add ( 30 )
    ds . add ( 40 )
    print ( ds . search ( 30 ) )
    ds . remove ( 20 )
    ds . add ( 50 )
    print ( ds . search ( 50 ) )
    print ( ds . getRandom ( ) )

Index/key variables: index, last, x
Class/struct names: MyDS
Python program:
def countSubArray ( arr , n ) :
    if ( n < 2 ) :
        return n ;
    i = max_element ( arr ) ;
    j = min_element ( arr ) ;
    if ( i > j ) :
        tmp = arr [ i ] ;
        arr [ i ] = arr [ j ] ;
        arr [ j ] = tmp ;
    return ( i + 1 ) * ( n - j ) ;
def max_element ( arr ) :
    idx = 0 ;
    max = arr [ 0 ] ;
    for i in range ( 1 , len ( arr ) ) :
        if ( max < arr [ i ] ) :
            max = arr [ i ] ;
            idx = i ;
    return idx ;
def min_element ( arr ) :
    idx = 0 ;
    min = arr [ 0 ] ;
    for i in range ( 1 , len ( arr ) ) :
        if ( arr [ i ] < min ) :
            min = arr [ i ] ;
            idx = i ;
    return idx ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 1 , 2 , 3 ] ;
    n = len ( arr ) ;
    print ( countSubArray ( arr , n ) ) ;

Index/key variables: i, j
Iterator variables: i
Python program:
class newNode :
    def __init__ ( self , item ) :
        self . data = item
        self . left = None
        self . right = None
result = 0
def dfs ( root , distance ) :
    global result
    if ( root == None ) :
        res = [ 0 for i in range ( distance + 1 ) ]
        return res
    if ( root . left == None and root . right == None ) :
        res = [ 0 for i in range ( distance + 1 ) ]
        res [ 1 ] += 1
        return res
    left = dfs ( root . left , distance )
    right = dfs ( root . right , distance )
    res = [ 0 for i in range ( distance + 1 ) ]
    i = len ( res ) - 2
    while ( i >= 1 ) :
        res [ i + 1 ] = left [ i ] + right [ i ]
        i -= 1
    for l in range ( 1 , len ( left ) ) :
        for r in range ( len ( right ) ) :
            if ( l + r <= distance ) :
                result += left [ l ] * right [ r ]
    return res
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 1 )
    root . left = newNode ( 2 )
    root . right = newNode ( 3 )
    root . left . left = newNode ( 4 )
    K = 3
    dfs ( root , K )
    print ( result )

Index/key variables: i, l, r
Accumulator variables: result
Iterator variables: l, r
Class/struct names: newNode
Python program:
from collections import deque
def maxAbsDiffLevelSum ( N , M , cost , Edges ) :
    adj = [ [ ] for i in range ( N ) ]
    for i in range ( M ) :
        u = Edges [ i ] [ 0 ]
        v = Edges [ i ] [ 1 ]
        adj [ u ] . append ( v )
    maxSum = cost [ 0 ]
    minSum = cost [ 0 ]
    q = deque ( )
    q . append ( 0 )
    while len ( q ) > 0 :
        count = len ( q )
        sum = 0
        while ( count ) :
            temp = q . popleft ( )
            q . pop ( )
            sum = sum + cost [ temp ]
            for i in adj [ temp ] :
                q . append ( i )
            count -= 1
        maxSum = max ( sum , maxSum )
        minSum = min ( sum , minSum )
    print ( abs ( maxSum - minSum ) )
if __name__ == ' _ _ main _ _ ' :
    N = 10
    M = 9
    Edges = [ [ 0 , 1 ] , [ 0 , 2 ] , [ 0 , 3 ] , [ 1 , 4 ] , [ 1 , 5 ] , [ 3 , 6 ] , [ 6 , 7 ] , [ 6 , 8 ] , [ 6 , 9 ] ]
    cost = [ 1 , 2 , - 1 , 3 , 4 , 5 , 8 , 6 , 12 , 7 ]
    maxAbsDiffLevelSum ( N , M , cost , Edges )

Index/key variables: i, temp, u
Accumulator variables: count, q
Iterator variables: i
Python program:
import sys
def findMinCost ( a , k , n ) :
    max_ele = max ( a )
    dp = [ 0 ] * ( n + 1 )
    for i in range ( 1 , n + 1 ) :
        dp [ i ] = sys . maxsize
    dp [ 0 ] = 0
    for i in range ( 0 , n ) :
        freq = [ 0 ] * ( max_ele + 1 )
        for j in range ( i , n ) :
            freq [ a [ j ] ] += 1
            cost = 0
            for x in range ( 0 , max_ele + 1 ) :
                cost += ( 0 if ( freq [ x ] == 1 ) else freq [ x ] )
            dp [ j + 1 ] = min ( dp [ i ] + cost + k , dp [ j + 1 ] )
    return dp [ n ]
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 1 , 1 , 1 ] ;
    K = 2 ;
    n = len ( arr ) ;
    print ( findMinCost ( arr , K , n ) ) ;

Index/key variables: i, j, n, x
Accumulator variables: cost
Iterator variables: i, j, x
Python program:
maxn = 100005
BITree = [ [ 0 for x in range ( maxn ) ] for y in range ( 26 ) ]
N = 0
def update_BITree ( index , C , val ) :
    while ( index <= N ) :
        BITree [ ord ( C ) - ord ( ' a ' ) ] [ index ] += val
        index += ( index & - index )
def sum_BITree ( index , C ) :
    s = 0
    while ( index ) :
        s += BITree [ ord ( C ) - ord ( ' a ' ) ] [ index ]
        index -= ( index & - index )
    return s
def buildTree ( st ) :
    for i in range ( 1 , N + 1 ) :
        update_BITree ( i , st [ i ] , 1 )
    print ( )
def printCharacter ( st , l , r , k ) :
    count = 0
    for C in range ( ord ( ' z ' ) , ord ( ' a ' ) - 1 , - 1 ) :
        times = ( sum_BITree ( r , chr ( C ) ) - sum_BITree ( l - 1 , chr ( C ) ) )
        count += times
        if ( count >= k ) :
            ans = chr ( C )
            break
    return ans
def updateTree ( st , pos , s ) :
    index = pos ;
    update_BITree ( index , st [ index ] , - 1 )
    st . replace ( st [ index ] , s , 1 )
    update_BITree ( index , s , 1 )
if __name__ == " _ _ main _ _ " :
    st = " abcddef "
    N = len ( st )
    Q = 3
    buildTree ( st )
    print ( printCharacter ( st , 1 , 2 , 2 ) )
    updateTree ( st , 4 , ' g ' )
    print ( printCharacter ( st , 1 , 5 , 4 ) )

Index/key variables: i, index
Accumulator variables: count, s
Iterator variables: C, i
Python program:
def generatePassword ( s , T ) :
    result = [ ]
    for currentString in s :
        person = currentString . split ( " : " )
        name = person [ 0 ]
        number = person [ 1 ]
        n = len ( name )
        max = 0
        for i in range ( len ( number ) ) :
            temp = int ( number [ i ] )
            if ( temp > max and temp <= n ) :
                max = temp
        if max == 0 :
            result . append ( T )
        else :
            result . append ( name [ max - 1 ] )
    return result
arr = [ " Geeks : 89167" , " gfg : 68795" ]
T = ' X '
print ( * generatePassword ( arr , T ) , sep = " " )

Index/key variables: i
Accumulator variables: result
Iterator variables: currentString, i
Python program:
vec = [ [ ] for i in range ( 100001 ) ]
vis = [ False ] * 100001
cc = 1
def dfs ( node ) :
    global cc
    vis [ node ] = True
    for x in vec [ node ] :
        if ( vis [ x ] == 0 ) :
            cc += 1
            dfs ( x )
def addEdge ( u , v ) :
    vec [ u ] . append ( v )
    vec [ v ] . append ( u )
def minEdgeRemoved ( N , M , Edges ) :
    global cc
    for i in range ( M ) :
        addEdge ( Edges [ i ] [ 0 ] , Edges [ i ] [ 1 ] )
    memset ( vis , false , sizeof ( vis ) )
    k = 0
    for i in range ( 1 , N + 1 ) :
        if ( not vis [ i ] ) :
            cc = 1
            dfs ( i )
            k += 1
    print ( M - N + k )
if __name__ == ' _ _ main _ _ ' :
    N = 3
    M = 2
    Edges = [ [ 1 , 2 ] , [ 2 , 3 ] ]
    minEdgeRemoved ( N , M , Edges )

Index/key variables: i, node, u, v, x
Accumulator variables: cc, k
Iterator variables: i, x
Python program:
ALPHA = 26
def getDiffString ( str ) :
    shift = " "
    for i in range ( 1 , len ( str ) ) :
        dif = ( ord ( str [ i ] ) - ord ( str [ i - 1 ] ) )
        if ( dif < 0 ) :
            dif += ALPHA
        shift += chr ( dif + ord ( ' a ' ) )
    return shift
def groupShiftedString ( str , n ) :
    groupMap = { }
    for i in range ( n ) :
        diffStr = getDiffString ( str [ i ] )
        if diffStr not in groupMap :
            groupMap [ diffStr ] = [ i ]
        else :
            groupMap [ diffStr ] . append ( i )
    for it in groupMap :
        v = groupMap [ it ]
        for i in range ( len ( v ) ) :
            print ( str [ v [ i ] ] , end = " ▁ " )
        print ( )
str = [ " acd " , " dfg " , " wyz " , " yab " , " mop " , " bdfh " , " a " , " x " , " moqs " ]
n = len ( str )
groupShiftedString ( str , n )

Index/key variables: diffStr, i, it
Accumulator variables: dif, shift
Iterator variables: i, it
Python program:
pairFound = False
S = set ( )
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def pairSum ( root , target ) :
    global pairFound
    global S
    if ( root == None ) :
        return
    if ( root . left == None and root . right == None ) :
        temp = list ( S )
        if ( temp . count ( target - root . data ) ) :
            print ( target - root . data , root . data )
            pairFound = True
            return
        else :
            S . add ( root . data )
    pairSum ( root . left , target )
    pairSum ( root . right , target )
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 1 )
    root . left = newNode ( 2 )
    root . left . left = newNode ( 4 )
    root . left . right = newNode ( 5 )
    root . right = newNode ( 3 )
    root . right . left = newNode ( 6 )
    root . right . right = newNode ( 7 )
    root . right . right . right = newNode ( 8 )
    K = 13
    pairSum ( root , K )
    if ( pairFound == False ) :
        print ( - 1 )

Boolean variables: pairFound
Class/struct names: newNode
Python program:
def countRooks ( n , k , pos ) :
    row = [ 0 for i in range ( n ) ]
    col = [ 0 for i in range ( n ) ]
    for i in range ( k ) :
        row [ pos [ i ] [ 0 ] - 1 ] = 1
        col [ pos [ i ] [ 1 ] - 1 ] = 1
    res = n - k
    print ( res )
    ri = 0
    ci = 0
    while ( res > 0 ) :
        while ( row [ ri ] == 1 ) :
            ri += 1
        while ( col [ ci ] == 1 ) :
            ci += 1
        print ( ( ri + 1 ) , ( ci + 1 ) )
        ri += 1
        ci += 1
        res -= 1
if __name__ == ' _ _ main _ _ ' :
    N = 4
    K = 2
    pos = [ [ 1 , 4 ] , [ 2 , 2 ] ]
    countRooks ( N , K , pos )

Index/key variables: ci, i, ri
Accumulator variables: res
Iterator variables: i
Python program:
import math as mt
def minInsertion ( tr1 ) :
    n = len ( str1 )
    res = 0
    count = [ 0 for i in range ( 26 ) ]
    for i in range ( n ) :
        count [ ord ( str1 [ i ] ) - ord ( ' a ' ) ] += 1
    for i in range ( 26 ) :
        if ( count [ i ] % 2 == 1 ) :
            res += 1
    if ( res == 0 ) :
        return 0
    else :
        return res - 1
str1 = " geeksforgeeks "
print ( minInsertion ( str1 ) )

Index/key variables: i
Accumulator variables: res
Iterator variables: i
Python program:
def isPalindrome ( string : list ) -> bool :
    n = len ( string )
    for i in range ( n // 2 ) :
        if string [ i ] != string [ n - 1 - i ] :
            return False
    return True
def Query ( string : list , Q : int ) -> None :
    for i in range ( Q ) :
        inp = list ( input ( ) . split ( ) )
        i1 = int ( inp [ 0 ] )
        i2 = int ( inp [ 1 ] )
        ch = inp [ 2 ]
        string [ i1 ] = string [ i2 ] = ch
        if isPalindrome ( string ) :
            print ( " Yes " )
        else :
            print ( " No " )
if __name__ == " _ _ main _ _ " :
    string = list ( " geeks " )
    Q = 2
    Query ( string , Q )

Index/key variables: i, i1, i2
Iterator variables: i
Python program:
def check ( ans , s , n , m ) :
    for i in range ( 1 , n ) :
        count = 0
        for j in range ( m ) :
            if ( ans [ j ] != s [ i ] [ j ] ) :
                count += 1
        if ( count > 1 ) :
            return False
    return True
def findString ( s ) :
    n = len ( s )
    m = len ( s [ 0 ] )
    ans = s [ 0 ]
    flag = 0
    for i in range ( m ) :
        for j in range ( 26 ) :
            x = list ( ans )
            x [ i ] = chr ( j + ord ( ' a ' ) )
            if ( check ( x , s , n , m ) ) :
                ans = x
                flag = 1
                break
        if ( flag == 1 ) :
            break
    if ( flag == 0 ) :
        return " - 1"
    else :
        return ' ' . join ( ans )
s = [ " geeks " , " teeds " ]
print ( findString ( s ) )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
def getMinOps ( arr ) :
    ans = 0
    for i in range ( len ( arr ) - 1 ) :
        ans += max ( arr [ i ] - arr [ i + 1 ] , 0 )
    return ans
arr = [ 1 , 3 , 1 , 2 , 4 ]
print ( getMinOps ( arr ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
from collections import defaultdict
def maxdiff ( arr , n ) :
    freq = defaultdict ( lambda : 0 )
    for i in range ( n ) :
        freq [ arr [ i ] ] += 1
    ans = 0
    for i in range ( n ) :
        for j in range ( n ) :
            if freq [ arr [ i ] ] > freq [ arr [ j ] ] and arr [ i ] > arr [ j ] :
                ans = max ( ans , freq [ arr [ i ] ] - freq [ arr [ j ] ] )
            elif freq [ arr [ i ] ] < freq [ arr [ j ] ] and arr [ i ] < arr [ j ] :
                ans = max ( ans , freq [ arr [ j ] ] - freq [ arr [ i ] ] )
    return ans
arr = [ 3 , 1 , 3 , 2 , 3 , 2 ]
n = len ( arr )
print ( maxdiff ( arr , n ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def maxdiff ( arr , n ) :
    freq = { }
    dist = [ 0 ] * n
    j = 0
    for i in range ( n ) :
        if ( arr [ i ] not in freq ) :
            dist [ j ] = arr [ i ]
            j += 1
            freq [ arr [ i ] ] = 0
        if ( arr [ i ] in freq ) :
            freq [ arr [ i ] ] += 1
    dist = dist [ : j ]
    dist . sort ( )
    min_freq = n + 1
    ans = 0
    for i in range ( j ) :
        cur_freq = freq [ dist [ i ] ]
        ans = max ( ans , cur_freq - min_freq )
        min_freq = min ( min_freq , cur_freq )
    return ans
arr = [ 3 , 1 , 3 , 2 , 3 , 2 ]
n = len ( arr )
print ( maxdiff ( arr , n ) )

Index/key variables: i, j
Iterator variables: i
Python program:
import sys
def maxSum ( grid ) :
    prefsum = [ [ 0 for x in range ( m ) ] for y in range ( m ) ]
    for i in range ( n ) :
        for x in range ( m ) :
            if ( x == 0 ) :
                prefsum [ i ] [ x ] = grid [ i ] [ x ]
            else :
                prefsum [ i ] [ x ] = ( prefsum [ i ] [ x - 1 ] + grid [ i ] [ x ] )
    dp = [ [ - sys . maxsize - 1 for x in range ( X + 1 ) ] for y in range ( n ) ]
    for i in range ( n ) :
        dp [ i ] [ 0 ] = 0
    for i in range ( 1 , min ( m , X ) ) :
        dp [ 0 ] [ i ] = ( dp [ 0 ] [ i - 1 ] + grid [ 0 ] [ i - 1 ] )
    for i in range ( 1 , n ) :
        for j in range ( 1 , X + 1 ) :
            dp [ i ] [ j ] = dp [ i - 1 ] [ j ]
            for x in range ( 1 , min ( j , m ) + 1 ) :
                dp [ i ] [ j ] = max ( dp [ i ] [ j ] , dp [ i - 1 ] [ j - x ] + prefsum [ i ] [ x - 1 ] )
    return dp [ n - 1 ] [ X ]
if __name__ == " _ _ main _ _ " :
    n = 4
    m = 4
    X = 6
    grid = [ [ 3 , 2 , 6 , 1 ] , [ 1 , 9 , 2 , 4 ] , [ 4 , 1 , 3 , 9 ] , [ 3 , 8 , 2 , 1 ] ]
    ans = maxSum ( grid )
    print ( ans )

Index/key variables: X, i, j, x
Iterator variables: i, j, x
Python program:
def findDiff ( arr , n ) :
    arr . sort ( )
    count = 0 ; max_count = 0 ; min_count = n
    for i in range ( 0 , ( n - 1 ) ) :
        if arr [ i ] == arr [ i + 1 ] :
            count += 1
            continue
        else :
            max_count = max ( max_count , count )
            min_count = min ( min_count , count )
            count = 0
    return max_count - min_count
arr = [ 7 , 8 , 4 , 5 , 4 , 1 , 1 , 7 , 7 , 2 , 5 ]
n = len ( arr )
print ( findDiff ( arr , n ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def min_operations ( A ) :
    if len ( A ) == 0 :
        return 0
    ans = A [ 0 ]
    for i in range ( 1 , len ( A ) ) :
        if A [ i ] > A [ i - 1 ] :
            ans += A [ i ] - A [ i - 1 ]
    return ans
A = [ 1 , 2 , 3 , 2 , 1 ]
print ( min_operations ( A ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
from collections import defaultdict
def findDiff ( arr , n ) :
    mp = defaultdict ( lambda : 0 )
    for i in range ( n ) :
        mp [ arr [ i ] ] += 1
    max_count = 0 ; min_count = n
    for key , values in mp . items ( ) :
        max_count = max ( max_count , values )
        min_count = min ( min_count , values )
    return max_count - min_count
arr = [ 7 , 8 , 4 , 5 , 4 , 1 , 1 , 7 , 7 , 2 , 5 ]
n = len ( arr )
print ( findDiff ( arr , n ) )

Index/key variables: i
Iterator variables: i, key, values
Python program:
from queue import Queue
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
def areIdentical ( root1 , root2 ) :
    if ( root1 and root2 ) :
        return True
    if ( root1 or root2 ) :
        return False
    q1 = Queue ( )
    q2 = Queue ( )
    q1 . put ( root1 )
    q2 . put ( root2 )
    while ( not q1 . empty ( ) and not q2 . empty ( ) ) :
        n1 = q1 . queue [ 0 ]
        n2 = q2 . queue [ 0 ]
        if ( n1 . data != n2 . data ) :
            return False
        q1 . get ( )
        q2 . get ( )
        if ( n1 . left and n2 . left ) :
            q1 . put ( n1 . left )
            q2 . put ( n2 . left )
        elif ( n1 . left or n2 . left ) :
            return False
        if ( n1 . right and n2 . right ) :
            q1 . put ( n1 . right )
            q2 . put ( n2 . right )
        elif ( n1 . right or n2 . right ) :
            return False
    return True
if __name__ == ' _ _ main _ _ ' :
    root1 = newNode ( 1 )
    root1 . left = newNode ( 2 )
    root1 . right = newNode ( 3 )
    root1 . left . left = newNode ( 4 )
    root1 . left . right = newNode ( 5 )
    root2 = newNode ( 1 )
    root2 . left = newNode ( 2 )
    root2 . right = newNode ( 3 )
    root2 . left . left = newNode ( 4 )
    root2 . left . right = newNode ( 5 )
    if areIdentical ( root1 , root2 ) :
        print ( " Yes " )
    else :
        print ( " No " )

Class/struct names: newNode