dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def fixArray ( ar , n ) :
    for i in range ( n ) :
        for j in range ( n ) :
            if ( ar [ j ] == i ) :
                ar [ j ] , ar [ i ] = ar [ i ] , ar [ j ]
    for i in range ( n ) :
        if ( ar [ i ] != i ) :
            ar [ i ] = - 1
    print ( " Array ▁ after ▁ Rearranging " )
    for i in range ( n ) :
        print ( ar [ i ] , end = " ▁ " )
ar = [ - 1 , - 1 , 6 , 1 , 9 , 3 , 2 , - 1 , 4 , - 1 ]
n = len ( ar )
fixArray ( ar , n ) ;

Index/key variables: i, j
Iterator variables: i, j
Python program:
def getFinalSum ( a , n , queries , q , k ) :
    answer = 0
    for i in range ( n ) :
        answer += a [ i ]
    contribution = [ ]
    for i in range ( q ) :
        contribution . append ( queries [ i ] [ 1 ] - queries [ i ] [ 0 ] + 1 )
    contribution . sort ( reverse = True )
    i = 0
    while ( i < k ) :
        answer += contribution [ i ]
        i += 1
    return answer
if __name__ == ' _ _ main _ _ ' :
    a = [ 1 , 1 , 2 , 2 , 2 , 3 ]
    n = len ( a )
    queries = [ [ 0 , 4 ] , [ 1 , 2 ] , [ 2 , 5 ] , [ 2 , 3 ] , [ 2 , 4 ] ]
    q = len ( queries ) ;
    k = 3
    print ( getFinalSum ( a , n , queries , q , k ) )

Index/key variables: i
Accumulator variables: answer, contribution
Iterator variables: i
Python program:
def answerQuery ( arr , l , r ) :
    answer = abs ( arr [ l - 1 ] [ 1 ] - arr [ r - 1 ] [ 1 ] )
    return answer
def solveQueries ( a , n , q , m ) :
    arr = [ [ 0 for i in range ( n ) ] for j in range ( n ) ]
    for i in range ( n ) :
        arr [ i ] [ 0 ] = a [ i ]
        arr [ i ] [ 1 ] = i
    arr . sort ( reverse = False )
    for i in range ( m ) :
        print ( answerQuery ( arr , q [ i ] [ 0 ] , q [ i ] [ 1 ] ) )
if __name__ == ' _ _ main _ _ ' :
    a = [ 1 , 5 , 4 , 2 , 8 , 6 , 7 ]
    n = len ( a )
    q = [ [ 2 , 5 ] , [ 1 , 3 ] , [ 1 , 5 ] , [ 3 , 6 ] ]
    m = len ( q )
    solveQueries ( a , n , q , m )

Index/key variables: i
Iterator variables: i
Python program:
class newNode :
    def __init__ ( self , key ) :
        self . data = key
        self . left = None
        self . right = None
def findFullNode ( root ) :
    if ( root != None ) :
        findFullNode ( root . left )
        if ( root . left != None and root . right != None ) :
            print ( root . data , end = " ▁ " )
        findFullNode ( root . right )
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 1 )
    root . left = newNode ( 2 )
    root . right = newNode ( 3 )
    root . left . left = newNode ( 4 )
    root . right . left = newNode ( 5 )
    root . right . right = newNode ( 6 )
    root . right . left . right = newNode ( 7 )
    root . right . right . right = newNode ( 8 )
    root . right . left . right . left = newNode ( 9 )
    findFullNode ( root )

Class/struct names: newNode
Python program:
def kThLexString ( st , k , n ) :
    z = set ( )
    for i in range ( n ) :
        pp = " "
        for j in range ( i , i + k ) :
            if ( j >= n ) :
                break
            pp += s [ j ]
            z . add ( pp )
    fin = list ( z )
    fin . sort ( )
    print ( fin [ k - 1 ] )
s = " geeksforgeeks "
k = 5
n = len ( s )
kThLexString ( s , k , n )

Index/key variables: j
Accumulator variables: pp, z
Iterator variables: i, j
Python program:
import array as a
import numpy as np
def rearrangeArr ( arr , n ) :
    evenPos = int ( n / 2 )
    oddPos = n - evenPos
    tempArr = np . empty ( n , dtype = object )
    for i in range ( 0 , n ) :
        tempArr [ i ] = arr [ i ]
    tempArr . sort ( )
    j = oddPos - 1
    for i in range ( 0 , n , 2 ) :
        arr [ i ] = tempArr [ j ]
        j = j - 1
    j = oddPos
    for i in range ( 1 , n , 2 ) :
        arr [ i ] = tempArr [ j ]
        j = j + 1
    for i in range ( 0 , n ) :
        print ( arr [ i ] , end = ' ▁ ' )
arr = a . array ( ' i ' , [ 1 , 2 , 3 , 4 , 5 , 6 , 7 ] )
rearrangeArr ( arr , 7 )

Index/key variables: i, j
Iterator variables: i
Python program:
from math import sqrt
prime = [ 0 ] * 100005
def SieveOfEratosthenes ( n ) :
    for i in range ( len ( prime ) ) :
        prime [ i ] = True
    prime [ 1 ] = False
    for p in range ( 2 , int ( sqrt ( n ) ) + 1 ) :
        if prime [ p ] == True :
            for i in range ( p * 2 , n , p ) :
                prime [ i ] = False
def sortedArray ( arr , n ) :
    SieveOfEratosthenes ( 100005 )
    v = [ ]
    for i in range ( n ) :
        if prime [ arr [ i ] ] == 0 :
            v . append ( arr [ i ] )
    v . sort ( )
    j = 0
    for i in range ( n ) :
        if prime [ arr [ i ] ] == True :
            print ( arr [ i ] , end = " ▁ " )
        else :
            print ( v [ j ] , end = " ▁ " )
            j += 1
if __name__ == " _ _ main _ _ " :
    n = 6
    arr = [ 100 , 11 , 500 , 2 , 17 , 1 ]
    sortedArray ( arr , n )

Index/key variables: i, j, p
Accumulator variables: v
Iterator variables: i, p
Python program:
class newNode :
    def __init__ ( self , key ) :
        self . key = key
        self . left = None
        self . right = None
def addBT ( root ) :
    if ( root == None ) :
        return 0
    return ( root . key + addBT ( root . left ) + addBT ( root . right ) )
if __name__ == ' _ _ main _ _ ' :
    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 . right . left . right = newNode ( 8 )
    sum = addBT ( root )
    print ( " Sum ▁ of ▁ all ▁ the ▁ nodes ▁ is : " , sum )

Class/struct names: newNode
Python program:
def minSwap ( arr , n , k ) :
    count = 0
    for i in range ( 0 , n ) :
        if ( arr [ i ] <= k ) :
            count = count + 1
    bad = 0
    for i in range ( 0 , count ) :
        if ( arr [ i ] > k ) :
            bad = bad + 1
    ans = bad
    j = count
    for i in range ( 0 , n ) :
        if ( j == n ) :
            break
        if ( arr [ i ] > k ) :
            bad = bad - 1
        if ( arr [ j ] > k ) :
            bad = bad + 1
        ans = min ( ans , bad )
        j = j + 1
    return ans
arr = [ 2 , 1 , 5 , 6 , 3 ]
n = len ( arr )
k = 3
print ( minSwap ( arr , n , k ) )
arr1 = [ 2 , 7 , 9 , 5 , 8 , 7 , 4 ]
n = len ( arr1 )
k = 5
print ( minSwap ( arr1 , n , k ) )

Index/key variables: i, j
Iterator variables: i
Python program:
def maxProductSubarrayOfSizeK ( A , n , k ) :
    A . sort ( )
    product = 1
    if ( A [ n - 1 ] == 0 and ( k & 1 ) ) :
        return 0
    if ( A [ n - 1 ] <= 0 and ( k & 1 ) ) :
        for i in range ( n - 1 , n - k + 1 , - 1 ) :
            product *= A [ i ]
        return product
    i = 0
    j = n - 1
    if ( k & 1 ) :
        product *= A [ j ]
        j -= 1
        k -= 1
    k >>= 1
    for itr in range ( k ) :
        left_product = A [ i ] * A [ i + 1 ]
        right_product = A [ j ] * A [ j - 1 ]
        if ( left_product > right_product ) :
            product *= left_product
            i += 2
        else :
            product *= right_product
            j -= 2
    return product
if __name__ == " _ _ main _ _ " :
    A = [ 1 , 2 , - 1 , - 3 , - 6 , 4 ]
    n = len ( A )
    k = 4
    print ( maxProductSubarrayOfSizeK ( A , n , k ) )

Index/key variables: i, j
Accumulator variables: product
Iterator variables: i, itr
Python program:
def reorder ( arr , index , n ) :
    temp = [ 0 ] * n ;
    for i in range ( 0 , n ) :
        temp [ index [ i ] ] = arr [ i ]
    for i in range ( 0 , n ) :
        arr [ i ] = temp [ i ]
        index [ i ] = i
arr = [ 50 , 40 , 70 , 60 , 90 ]
index = [ 3 , 0 , 4 , 1 , 2 ]
n = len ( arr )
reorder ( arr , index , n )
print ( " Reordered ▁ array ▁ is : " )
for i in range ( 0 , n ) :
    print ( arr [ i ] , end = " ▁ " )
print ( " Modified Index array is : " )
for i in range ( 0 , n ) :
    print ( index [ i ] , end = " ▁ " )

Index/key variables: i
Iterator variables: i
Python program:
def reorder ( arr , index , n ) :
    for i in range ( 0 , n ) :
        while ( index [ i ] != i ) :
            oldTargetI = index [ index [ i ] ]
            oldTargetE = arr [ index [ i ] ]
            arr [ index [ i ] ] = arr [ i ]
            index [ index [ i ] ] = index [ i ]
            index [ i ] = oldTargetI
            arr [ i ] = oldTargetE
arr = [ 50 , 40 , 70 , 60 , 90 ]
index = [ 3 , 0 , 4 , 1 , 2 ]
n = len ( arr )
reorder ( arr , index , n )
print ( " Reordered ▁ array ▁ is : " )
for i in range ( 0 , n ) :
    print ( arr [ i ] , end = " ▁ " )
print ( " Modified Index array is : " )
for i in range ( 0 , n ) :
    print ( index [ i ] , end = " ▁ " )

Index/key variables: i
Iterator variables: i
Python program:
def heapify ( arr , index , i ) :
    largest = i
    left = 2 * i + 1
    right = 2 * i + 2
    global heapSize
    if ( left < heapSize and index [ left ] > index [ largest ] ) :
        largest = left
    if ( right < heapSize and index [ right ] > index [ largest ] ) :
        largest = right
    if ( largest != i ) :
        arr [ largest ] , arr [ i ] = arr [ i ] , arr [ largest ]
        index [ largest ] , index [ i ] = index [ i ] , index [ largest ]
        heapify ( arr , index , largest )
def heapSort ( arr , index , n ) :
    global heapSize
    for i in range ( int ( ( n - 1 ) / 2 ) , - 1 , - 1 ) :
        heapify ( arr , index , i )
    for i in range ( n - 1 , 0 , - 1 ) :
        index [ 0 ] , index [ i ] = index [ i ] , index [ 0 ]
        arr [ 0 ] , arr [ i ] = arr [ i ] , arr [ 0 ]
        heapSize -= 1
        heapify ( arr , index , 0 )
arr = [ 50 , 40 , 70 , 60 , 90 ]
index = [ 3 , 0 , 4 , 1 , 2 ]
n = len ( arr )
global heapSize
heapSize = n
heapSort ( arr , index , n )
print ( " Reordered ▁ array ▁ is : ▁ " )
print ( * arr , sep = ' ▁ ' )
print ( " Modified ▁ Index ▁ array ▁ is : ▁ " )
print ( * index , sep = ' ▁ ' )

Index/key variables: i, largest, left, right
Accumulator variables: heapSize
Iterator variables: i
Python program:
class getNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
def SumOfParentOfX ( root , Sum , x ) :
    if ( not root ) :
        return
    if ( ( root . left and root . left . data == x ) or ( root . right and root . right . data == x ) ) :
        Sum [ 0 ] += root . data
    SumOfParentOfX ( root . left , Sum , x )
    SumOfParentOfX ( root . right , Sum , x )
def SumOfParentOfXUtil ( root , x ) :
    Sum = [ 0 ]
    SumOfParentOfX ( root , Sum , x )
    return Sum [ 0 ]
if __name__ == ' _ _ main _ _ ' :
    root = getNode ( 4 )
    root . left = getNode ( 2 )
    root . right = getNode ( 5 )
    root . left . left = getNode ( 7 )
    root . left . right = getNode ( 2 )
    root . right . left = getNode ( 2 )
    root . right . right = getNode ( 3 )
    x = 2
    print ( " Sum ▁ = ▁ " , SumOfParentOfXUtil ( root , x ) )

Class/struct names: getNode
Python program:
def bitonicGenerator ( arr , n ) :
    i = 1
    j = n - 1
    if ( j % 2 != 0 ) :
        j = j - 1
    while ( i < j ) :
        arr [ j ] , arr [ i ] = arr [ i ] , arr [ j ]
        i = i + 2
        j = j - 2
    arr_f = [ ]
    arr_s = [ ]
    for i in range ( int ( ( n + 1 ) / 2 ) ) :
        arr_f . append ( arr [ i ] )
    i = int ( ( n + 1 ) / 2 )
    while ( i < n ) :
        arr_s . append ( arr [ i ] )
        i = i + 1
    arr_f . sort ( )
    arr_s . sort ( reverse = True )
    for i in arr_s :
        arr_f . append ( i )
    return arr_f
arr = [ 1 , 5 , 8 , 9 , 6 , 7 , 3 , 4 , 2 , 0 ]
n = len ( arr )
arr = bitonicGenerator ( arr , n )
print ( arr )

Index/key variables: i, j
Accumulator variables: arr_f, arr_s
Iterator variables: i
Python program:
def cocktailSort ( a ) :
    n = len ( a )
    swapped = True
    start = 0
    end = n - 1
    while ( swapped == True ) :
        swapped = False
        for i in range ( start , end ) :
            if ( a [ i ] > a [ i + 1 ] ) :
                a [ i ] , a [ i + 1 ] = a [ i + 1 ] , a [ i ]
                swapped = True
        if ( swapped == False ) :
            break
        swapped = False
        end = end - 1
        for i in range ( end - 1 , start - 1 , - 1 ) :
            if ( a [ i ] > a [ i + 1 ] ) :
                a [ i ] , a [ i + 1 ] = a [ i + 1 ] , a [ i ]
                swapped = True
        start = start + 1
a = [ 5 , 1 , 4 , 2 , 8 , 0 , 2 ]
cocktailSort ( a )
print ( " Sorted ▁ array ▁ is : " )
for i in range ( len ( a ) ) :
    print ( " % ▁ d " % a [ i ] )

Index/key variables: i
Iterator variables: i
Boolean variables: swapped
Python program:
def findMaxGuests ( arrl , exit , n ) :
    arrl . sort ( ) ;
    exit . sort ( ) ;
    guests_in = 1 ;
    max_guests = 1 ;
    time = arrl [ 0 ] ;
    i = 1 ;
    j = 0 ;
    while ( i < n and j < n ) :
        if ( arrl [ i ] <= exit [ j ] ) :
            guests_in = guests_in + 1 ;
            if ( guests_in > max_guests ) :
                max_guests = guests_in ;
                time = arrl [ i ] ;
            i = i + 1 ;
        else :
            guests_in = guests_in - 1 ;
            j = j + 1 ;
    print ( " Maximum ▁ Number ▁ of ▁ Guests ▁ = " , max_guests , " at ▁ time " , time )
arrl = [ 1 , 2 , 10 , 5 , 5 ] ;
exit = [ 4 , 5 , 12 , 9 , 12 ] ;
n = len ( arrl ) ;
findMaxGuests ( arrl , exit , n ) ;

Index/key variables: i, j
Python program:
def rearrange ( arr , n ) :
    for i in range ( n ) :
        arr [ arr [ i ] % n ] += i * n
    for i in range ( n ) :
        arr [ i ] //= n
def prArray ( arr , n ) :
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " )
    print ( )
arr = [ 2 , 0 , 1 , 4 , 5 , 3 ]
n = len ( arr )
print ( " Given ▁ array ▁ is ▁ : ▁ " )
prArray ( arr , n )
rearrange ( arr , n )
print ( " Modified ▁ array ▁ is ▁ : " )
prArray ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
def rearrange ( arr , n ) :
    temp = n * [ None ]
    small , large = 0 , n - 1
    flag = True
    for i in range ( n ) :
        if flag is True :
            temp [ i ] = arr [ large ]
            large -= 1
        else :
            temp [ i ] = arr [ small ]
            small += 1
        flag = bool ( 1 - flag )
    for i in range ( n ) :
        arr [ i ] = temp [ i ]
    return arr
arr = [ 1 , 2 , 3 , 4 , 5 , 6 ]
n = len ( arr )
print ( " Original ▁ Array " )
print ( arr )
print ( " Modified ▁ Array " )
print ( rearrange ( arr , n ) )

Index/key variables: i, large, small
Iterator variables: i
Boolean variables: flag
Python program:
def minimumcoins ( arr , N ) :
    coins = 0
    j = 0
    if ( arr [ 0 ] == 1 ) :
        coins += 1
    for i in range ( 1 , N ) :
        if ( arr [ i ] == 2 ) :
            continue
        j = i
        while ( j < N and arr [ j ] == 1 ) :
            j += 1
        x = ( j - i )
        coins += x // 3
        i = j - 1
    return coins
N = 8
arr = [ 1 , 2 , 1 , 1 , 2 , 1 , 1 , 1 ]
print ( minimumcoins ( arr , N ) )

Index/key variables: i, j
Accumulator variables: coins
Iterator variables: i
Python program:
def rearrange ( arr , n ) :
    max_idx = n - 1
    min_idx = 0
    max_elem = arr [ n - 1 ] + 1
    for i in range ( 0 , n ) :
        if i % 2 == 0 :
            arr [ i ] += ( arr [ max_idx ] % max_elem ) * max_elem
            max_idx -= 1
        else :
            arr [ i ] += ( arr [ min_idx ] % max_elem ) * max_elem
            min_idx += 1
    for i in range ( 0 , n ) :
        arr [ i ] = arr [ i ] / max_elem
arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]
n = len ( arr )
print ( " Original ▁ Array " )
for i in range ( 0 , n ) :
    print ( arr [ i ] , end = " ▁ " )
rearrange ( arr , n )
print ( " Modified Array " )
for i in range ( 0 , n ) :
    print ( int ( arr [ i ] ) , end = " ▁ " )

Index/key variables: i, max_idx, min_idx
Iterator variables: i
Python program:
def rearrange ( arr , n ) :
    max_ele = arr [ n - 1 ]
    min_ele = arr [ 0 ]
    for i in range ( n ) :
        if i % 2 == 0 :
            arr [ i ] = max_ele
            max_ele -= 1
        else :
            arr [ i ] = min_ele
            min_ele += 1
arr = [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]
n = len ( arr )
print ( " Origianl ▁ Array " )
for i in range ( n ) :
    print ( arr [ i ] , end = " ▁ " )
rearrange ( arr , n )
print ( " Modified Array " )
for i in range ( n ) :
    print ( arr [ i ] , end = " ▁ " )

Index/key variables: i
Accumulator variables: max_ele, min_ele
Iterator variables: i
Python program:
def rearrange ( arr , n ) :
    j = 0
    for i in range ( 0 , n ) :
        if ( arr [ i ] < 0 ) :
            temp = arr [ i ]
            arr [ i ] = arr [ j ]
            arr [ j ] = temp
            j = j + 1
    print ( arr )
arr = [ - 1 , 2 , - 3 , 4 , 5 , 6 , - 7 , 8 , 9 ]
n = len ( arr )
rearrange ( arr , n )

Index/key variables: i, j
Iterator variables: i
Python program:
def maxSum ( arr ) :
    m = len ( arr )
    n = len ( arr [ 0 ] ) - 1
    dp = [ [ 0 for i in range ( n + 1 ) ] for j in range ( m ) ]
    for i in range ( 1 , m , 1 ) :
        dp [ i ] [ 1 ] = arr [ i ] [ 1 ]
    for i in range ( 1 , n + 1 , 1 ) :
        for j in range ( 1 , m , 1 ) :
            mx = 0
            for k in range ( 1 , m , 1 ) :
                if ( k != j ) :
                    if ( dp [ k ] [ i - 1 ] > mx ) :
                        mx = dp [ k ] [ i - 1 ]
            if ( mx and arr [ j ] [ i ] ) :
                dp [ j ] [ i ] = arr [ j ] [ i ] + mx
    ans = - 1
    for i in range ( 1 , m , 1 ) :
        if ( dp [ i ] [ n ] ) :
            ans = max ( ans , dp [ i ] [ n ] )
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 0 , 0 , 0 , 0 , 0 ] , [ 0 , 10 , 2 , 20 , 0 ] , [ 0 , 0 , 0 , 5 , 0 ] , [ 0 , 0 , 0 , 0 , 6 ] , [ 0 , 4 , 0 , 11 , 5 ] , [ 0 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 ] , [ 0 , 0 , 0 , 0 , 0 ] ]
    print ( maxSum ( arr ) )

Index/key variables: i, j, k, n
Iterator variables: i, j, k
Python program:
def rearrange ( arr , n ) :
    for i in range ( n - 1 ) :
        if ( i % 2 == 0 and arr [ i ] > arr [ i + 1 ] ) :
            temp = arr [ i ]
            arr [ i ] = arr [ i + 1 ]
            arr [ i + 1 ] = temp
        if ( i % 2 != 0 and arr [ i ] < arr [ i + 1 ] ) :
            temp = arr [ i ]
            arr [ i ] = arr [ i + 1 ]
            arr [ i + 1 ] = temp
def printArray ( arr , size ) :
    for i in range ( size ) :
        print ( arr [ i ] , " ▁ " , end = " " )
    print ( )
arr = [ 6 , 4 , 2 , 1 , 8 , 3 ]
n = len ( arr )
print ( " Before ▁ rearranging : ▁ " )
printArray ( arr , n )
rearrange ( arr , n )
print ( " After ▁ rearranging : " )
printArray ( arr , n ) ;

Index/key variables: i
Iterator variables: i
Python program:
def shortestDistance ( S , N ) :
    minDis = len ( S )
    for i in range ( N ) :
        for j in range ( i + 1 , N ) :
            if ( S [ i ] == S [ j ] and ( j - i ) < minDis ) :
                minDis = j - i
                break
    if ( minDis == len ( S ) ) :
        return - 1
    else :
        return minDis - 1
S = " geeksforgeeks "
N = 13
print ( shortestDistance ( S , N ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def rearrange ( a , size ) :
    positive = 0
    negative = 1
    while ( True ) :
        while ( positive < size and a [ positive ] >= 0 ) :
            positive = positive + 2
        while ( negative < size and a [ negative ] <= 0 ) :
            negative = negative + 2
        if ( positive < size and negative < size ) :
            temp = a [ positive ]
            a [ positive ] = a [ negative ]
            a [ negative ] = temp
        else :
            break
arr = [ 1 , - 3 , 5 , 6 , - 3 , 6 , 7 , - 4 , 9 , 10 ]
n = len ( arr )
rearrange ( arr , n )
for i in range ( 0 , n ) :
    print ( arr [ i ] , end = " ▁ " )

Index/key variables: i, negative, positive
Iterator variables: i
Python program:
def possibleNumbers ( N , M , A , B ) :
    if ( A > B ) :
        temp = A
        A = B
        B = temp
    number = N + M * A
    print ( number , end = " ▁ " )
    if ( A != B ) :
        for i in range ( M ) :
            number = number - A + B
            print ( number , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    N = 5
    M = 3
    A = 4
    B = 6
    possibleNumbers ( N , M , A , B )

Iterator variables: i
Python program:
def printArray ( a , n ) :
    for i in a :
        print ( i , end = " ▁ " )
    print ( )
arr = [ 1 , - 3 , 5 , 6 , - 3 , 6 , 7 , - 4 , 9 , 10 ]
n = len ( arr )
printArray ( arr , n )
for i in range ( n ) :
    if ( arr [ i ] >= 0 and i % 2 == 1 ) :
        for j in range ( i + 1 , n ) :
            if ( arr [ j ] < 0 and j % 2 == 0 ) :
                arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]
                break
    elif ( arr [ i ] < 0 and i % 2 == 0 ) :
        for j in range ( i + 1 , n ) :
            if ( arr [ j ] >= 0 and j % 2 == 1 ) :
                arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]
                break
printArray ( arr , n ) ;

Index/key variables: i, j
Iterator variables: i, j
Python program:
def arrayEvenAndOdd ( arr , n ) :
    ind = 0 ;
    a = [ 0 for i in range ( n ) ]
    for i in range ( n ) :
        if ( arr [ i ] % 2 == 0 ) :
            a [ ind ] = arr [ i ]
            ind += 1
    for i in range ( n ) :
        if ( arr [ i ] % 2 != 0 ) :
            a [ ind ] = arr [ i ]
            ind += 1
    for i in range ( n ) :
        print ( a [ i ] , end = " ▁ " )
    print ( )
arr = [ 1 , 3 , 2 , 4 , 7 , 6 , 9 , 10 ]
n = len ( arr )
arrayEvenAndOdd ( arr , n )

Index/key variables: i, ind
Iterator variables: i
Python program:
def arrayEvenAndOdd ( arr , n ) :
    i = - 1
    j = 0
    while ( j != n ) :
        if ( arr [ j ] % 2 == 0 ) :
            i = i + 1
            arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]
        j = j + 1
    for i in arr :
        print ( str ( i ) + " ▁ " , end = ' ' )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 3 , 2 , 4 , 7 , 6 , 9 , 10 ]
    n = len ( arr )
    arrayEvenAndOdd ( arr , n )

Index/key variables: i, j
Iterator variables: i
Python program:
def Check ( A , B , M , N , X ) :
    for i in range ( M ) :
        for j in range ( N - X + 1 ) :
            if ( A [ i ] [ j ] != B [ i ] [ j ] ) :
                diff = B [ i ] [ j ] - A [ i ] [ j ]
                for k in range ( X ) :
                    A [ i ] [ j + k ] = A [ i ] [ j + k ] + diff
    for i in range ( M - X + 1 ) :
        for j in range ( N ) :
            if ( A [ i ] [ j ] != B [ i ] [ j ] ) :
                diff = B [ i ] [ j ] - A [ i ] [ j ]
                for k in range ( X ) :
                    A [ i + k ] [ j ] = A [ i + k ] [ j ] + diff
    for i in range ( M ) :
        for j in range ( N ) :
            if ( A [ i ] [ j ] != B [ i ] [ j ] ) :
                return 0
    return 1
if __name__ == ' _ _ main _ _ ' :
    M , N , X = 2 , 2 , 2
    A = [ [ 0 , 0 ] , [ 0 , 0 ] ]
    B = [ [ 1 , 2 ] , [ 0 , 1 ] ]
    if ( Check ( A , B , M , N , X ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i, j
Iterator variables: i, j, k
Python program:
def find3largest ( arr , n ) :
    arr = sorted ( arr )
    check = 0
    count = 1
    for i in range ( 1 , n + 1 ) :
        if ( count < 4 ) :
            if ( check != arr [ n - i ] ) :
                print ( arr [ n - i ] , end = " ▁ " )
                check = arr [ n - i ]
                count += 1
        else :
            break
arr = [ 12 , 45 , 1 , - 1 , 45 , 54 , 23 , 5 , 0 , - 10 ]
n = len ( arr )
find3largest ( arr , n )

Accumulator variables: count
Iterator variables: i
Python program:
def minCntCharDeletionsfrequency ( str , N ) :
    mp = { }
    pq = [ ]
    cntChar = 0
    for i in range ( N ) :
        mp [ str [ i ] ] = mp . get ( str [ i ] , 0 ) + 1
    for it in mp :
        pq . append ( mp [ it ] )
    pq = sorted ( pq )
    while ( len ( pq ) > 0 ) :
        frequent = pq [ - 1 ]
        del pq [ - 1 ]
        if ( len ( pq ) == 0 ) :
            return cntChar
        if ( frequent == pq [ - 1 ] ) :
            if ( frequent > 1 ) :
                pq . append ( frequent - 1 )
            cntChar += 1
        pq = sorted ( pq )
    return cntChar
if __name__ == ' _ _ main _ _ ' :
    str = " abbbcccd "
    N = len ( str )
    print ( minCntCharDeletionsfrequency ( str , N ) )

Index/key variables: i, it
Accumulator variables: cntChar, pq
Iterator variables: i, it