dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def maxTriplet ( a , n ) :
    f = [ True for i in range ( n ) ]
    bits = [ [ 0 for i in range ( 33 ) ] for i in range ( n ) ]
    for i in range ( n ) :
        num = a [ i ]
        j = 32
        while ( num ) :
            if ( num & 1 ) :
                bits [ i ] [ j ] = 1
            j -= 1
            num >>= 1
    ans = 0
    for i in range ( 33 ) :
        cnt = 0
        for j in range ( n ) :
            if ( bits [ j ] [ i ] and f [ j ] ) :
                cnt += 1
        if ( cnt >= 3 ) :
            ans += pow ( 2 , 32 - i )
            for j in range ( n ) :
                if ( bits [ j ] [ i ] == False ) :
                    f [ j ] = False
    cnt = 0
    for i in range ( n ) :
        if ( f [ i ] ) :
            cnt += 1
    NumberOfTriplets = ( cnt * ( cnt - 1 ) * ( cnt - 2 ) ) // 6
    print ( NumberOfTriplets , ans )
a = [ 4 , 11 , 10 , 15 , 26 ]
n = len ( a )
maxTriplet ( a , n )

Index/key variables: i, j
Accumulator variables: ans, cnt, num
Iterator variables: i, j
Python program:
def OR ( a , n ) :
    ans = a [ 0 ]
    for i in range ( 1 , n ) :
        ans |= a [ i ]
    return ans
if __name__ == ' _ _ main _ _ ' :
    a = [ 1 , 4 , 6 ]
    n = len ( a )
    print ( OR ( a , n ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def bit ( n ) :
    count = 0
    while ( n ) :
        count += 1
        n = n & ( n - 1 )
    return count
def maxSumOfBits ( arr , n ) :
    for i in range ( n ) :
        arr [ i ] = bit ( arr [ i ] )
    incl = arr [ 0 ]
    excl = 0
    for i in range ( 1 , n ) :
        if incl > excl :
            excl_new = incl
        else :
            excl_new = excl
        incl = excl + arr [ i ] ;
        excl = excl_new
    if incl > excl :
        return incl
    else :
        return excl
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 4 , 5 , 6 , 7 , 20 , 25 ]
    n = len ( arr )
    print ( maxSumOfBits ( arr , n ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def findOddPair ( A , N ) :
    count = 0
    for i in range ( 0 , N ) :
        if ( A [ i ] % 2 == 0 ) :
            count += 1
    return count * ( N - count )
if __name__ == ' _ _ main _ _ ' :
    a = [ 5 , 4 , 7 , 2 , 1 ]
    n = len ( a )
    print ( findOddPair ( a , n ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def MSBPosition ( N ) :
    msb_p = - 1
    while ( N ) :
        N = N >> 1
        msb_p += 1
    return msb_p
def findBitwiseOR ( L , R ) :
    res = 0
    msb_p1 = MSBPosition ( L )
    msb_p2 = MSBPosition ( R )
    while ( msb_p1 == msb_p2 ) :
        res_val = ( 1 << msb_p1 )
        res += res_val
        L -= res_val
        R -= res_val
        msb_p1 = MSBPosition ( L )
        msb_p2 = MSBPosition ( R )
    msb_p1 = max ( msb_p1 , msb_p2 )
    for i in range ( msb_p1 , - 1 , - 1 ) :
        res_val = ( 1 << i )
        res += res_val
    return res
if __name__ == " _ _ main _ _ " :
    L , R = 12 , 18
    print ( findBitwiseOR ( L , R ) )

Accumulator variables: L, R, msb_p, res
Iterator variables: i
Python program:
def minSum ( a , n ) :
    a = sorted ( a )
    num1 , num2 = 0 , 0
    for i in range ( n ) :
        if i % 2 == 0 :
            num1 = num1 * 10 + a [ i ]
        else :
            num2 = num2 * 10 + a [ i ]
    return num2 + num1
arr = [ 5 , 3 , 0 , 7 , 4 ]
n = len ( arr )
print ( " The ▁ required ▁ sum ▁ is " , minSum ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def countSetBits ( n ) :
    count = 0
    while n :
        count += n & 1
        n >>= 1
    return count
def countOfOddPascal ( n ) :
    c = countSetBits ( n )
    return pow ( 2 , c )
n = 20
print ( countOfOddPascal ( n ) )

Accumulator variables: count, n
Python program:
N = 100
def ansQueries ( prefeven , prefodd , l , r ) :
    if ( ( r - l + 1 ) % 2 == 0 ) :
        print ( "0" )
    else :
        if ( l % 2 == 0 ) :
            print ( prefeven [ r ] ^ prefeven [ l - 1 ] )
        else :
            print ( prefodd [ r ] ^ prefodd [ l - 1 ] )
def wrapper ( arr , n , l , r , q ) :
    prefodd = [ 0 ] * N
    prefeven = [ 0 ] * N
    for i in range ( 1 , n + 1 ) :
        if ( ( i ) % 2 == 0 ) :
            prefeven [ i ] = arr [ i - 1 ] ^ prefeven [ i - 1 ]
            prefodd [ i ] = prefodd [ i - 1 ]
        else :
            prefeven [ i ] = prefeven [ i - 1 ]
            prefodd [ i ] = prefodd [ i - 1 ] ^ arr [ i - 1 ]
    i = 0
    while ( i != q ) :
        ansQueries ( prefeven , prefodd , l [ i ] , r [ i ] )
        i += 1
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 4 , 5 ]
    n = len ( arr )
    l = [ 1 , 1 , 2 ]
    r = [ 2 , 3 , 4 ]
    q = len ( l )
    wrapper ( arr , n , l , r , q )

Index/key variables: i, r
Iterator variables: i
Python program:
def checkBit ( pattern , arr , n ) :
    count = 0
    for i in range ( 0 , n ) :
        if ( ( pattern & arr [ i ] ) == pattern ) :
            count = count + 1
    return count
def maxAND ( arr , n ) :
    res = 0
    for bit in range ( 31 , - 1 , - 1 ) :
        count = checkBit ( res | ( 1 << bit ) , arr , n )
        if ( count >= 2 ) :
            res = res | ( 1 << bit )
    return res
arr = [ 4 , 8 , 6 , 2 ]
n = len ( arr )
print ( " Maximum ▁ AND ▁ Value ▁ = ▁ " , maxAND ( arr , n ) )

Index/key variables: i
Iterator variables: bit, i
Python program:
def findMiniFlip ( nums ) :
    n = len ( nums )
    s = ' '
    for i in range ( n ) :
        s += str ( nums [ i ] )
    num = int ( s , 2 )
    minXor = n ;
    mask = ( 1 << ( n - 1 ) )
    while ( n - 1 > 0 ) :
        temp = ( num ^ mask )
        minXor = min ( minXor , countones ( temp ) )
        n -= 1
        mask = ( mask | ( 1 << n - 1 ) )
    return minXor
def countones ( n ) :
    c = 0
    while ( n > 0 ) :
        n = n & ( n - 1 )
        c += 1
    return c
if __name__ == " _ _ main _ _ " :
    nums = [ 1 , 0 , 1 , 1 , 0 , 0 , 0 ]
    n = findMiniFlip ( nums )
    print ( n )

Index/key variables: i
Accumulator variables: c, n, s
Iterator variables: i
Python program:
def convertStringToInt ( s ) :
    ans = 0
    for i in range ( len ( s ) ) :
        ans = ans * 2 + ( ord ( s [ i ] ) - ord ( '0' ) )
    return ans
def getNthNumber ( n ) :
    q = [ ]
    if ( n == 1 ) :
        return 1
    n = n - 1
    q . append ( "11" )
    while ( len ( q ) != 0 ) :
        curr = q . pop ( 0 )
        n -= 1
        if ( n == 0 ) :
            return convertStringToInt ( curr )
        lenn = len ( curr )
        if ( len ( curr ) % 2 == 0 ) :
            q . append ( curr [ 0 : int ( lenn / 2 ) ] + "0" + curr [ int ( lenn / 2 ) : ] )
            q . append ( curr [ 0 : int ( lenn / 2 ) ] + "1" + curr [ int ( lenn / 2 ) : ] )
        else :
            midChar = curr [ int ( lenn / 2 ) ]
            q . append ( curr [ 0 : int ( lenn / 2 ) ] + midChar + curr [ int ( lenn / 2 ) : ] )
    return 0
n = 9
print ( getNthNumber ( n ) )

Index/key variables: i
Accumulator variables: n, q
Iterator variables: i
Python program:
def findSum ( n ) :
    sum = 0
    i = 1
    while ( ( 1 << i ) < n ) :
        for j in range ( 0 , i ) :
            num = ( 1 << i ) + ( 1 << j )
            if ( num <= n ) :
                sum += num
        i += 1
    return sum
n = 10
print ( findSum ( n ) )

Accumulator variables: i, sum
Iterator variables: j
Python program:
def reverseArray ( arr , n ) :
    import sys
    x = - sys . maxsize // sys . maxsize
    for i in range ( n // 2 ) :
        arr [ i ] , arr [ n + ( x * i ) + x ] = arr [ n + ( x * i ) + x ] , arr [ i ]
if __name__ == " _ _ main _ _ " :
    arr = [ 5 , 3 , 7 , 2 , 1 , 6 ]
    n = len ( arr )
    reverseArray ( arr , n )
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " )

Index/key variables: i
Iterator variables: i
Python program:
def reverseArray ( arr , n ) :
    for i in range ( n // 2 ) :
        arr [ i ] , arr [ ( n + ~ i + 1 ) + ~ 1 + 1 ] = arr [ ( n + ~ i + 1 ) + ~ 1 + 1 ] , arr [ i ]
arr = [ 5 , 3 , 7 , 2 , 1 , 6 ]
n = len ( arr )
reverseArray ( arr , n )
for i in range ( n ) :
    print ( arr [ i ] , end = " ▁ " )

Index/key variables: i
Iterator variables: i
Python program:
def maxXORInRange ( L , R ) :
    LXR = L ^ R
    msbPos = 0
    while ( LXR ) :
        msbPos += 1
        LXR >>= 1
    maxXOR , two = 0 , 1
    while ( msbPos ) :
        maxXOR += two
        two <<= 1
        msbPos -= 1
    return maxXOR
L , R = 8 , 20
print ( maxXORInRange ( L , R ) )

Accumulator variables: LXR, maxXOR, msbPos, two
Python program:
def CountZeroBit ( n ) :
    count = 0
    while ( n ) :
        if ( not ( n & 1 ) ) :
            count += 1
        n >>= 1
    return count
def CountORandSumEqual ( N ) :
    count = CountZeroBit ( N )
    return ( 1 << count )
N = 10
print ( CountORandSumEqual ( N ) )

Accumulator variables: count, n
Python program:
def countNumbers ( n ) :
    k = 0
    count = 0
    while ( n > 0 ) :
        if ( ( n & 1 ) == 0 ) :
            count += pow ( 2 , k )
        k += 1
        n >>= 1
    return count
n = 11
print ( countNumbers ( n ) )

Accumulator variables: count, k, n
Python program:
def xorPairCount ( arr , n , x ) :
    s = set ( )
    for i in range ( 0 , n ) :
        if ( x ^ arr [ i ] in s ) :
            result = result + 1
        s . add ( arr [ i ] )
    return result
if __name__ == " _ _ main _ _ " :
    arr = [ 5 , 4 , 10 , 15 , 7 , 6 ]
    n = len ( arr )
    x = 5
    print ( " Count ▁ of ▁ pair ▁ with ▁ given ▁ XOR ▁ = ▁ " + str ( xorPairCount ( arr , n , x ) ) )

Index/key variables: i
Accumulator variables: s
Iterator variables: i
Python program:
def isMultipleOf4 ( n ) :
    if ( n == 1 ) :
        return False
    XOR = 0
    for i in range ( 1 , n + 1 ) :
        XOR = XOR ^ i
    return ( XOR == n )
for n in range ( 0 , 43 ) :
    if ( isMultipleOf4 ( n ) ) :
        print ( n , end = " ▁ " )

Iterator variables: i, n
Python program:
class newNode :
    def __init__ ( self , key ) :
        self . key = key
        self . left = self . right = None
def Sum ( t ) :
    if ( t == None ) :
        return 0
    return t . key + Sum ( t . left ) + Sum ( t . right )
def uncoveredSumLeft ( t ) :
    if ( t . left == None and t . right == None ) :
        return t . key
    if ( t . left != None ) :
        return t . key + uncoveredSumLeft ( t . left )
    else :
        return t . key + uncoveredSumLeft ( t . right )
def uncoveredSumRight ( t ) :
    if ( t . left == None and t . right == None ) :
        return t . key
    if ( t . right != None ) :
        return t . key + uncoveredSumRight ( t . right )
    else :
        return t . key + uncoveredSumRight ( t . left )
def uncoverSum ( t ) :
    lb = 0
    rb = 0
    if ( t . left != None ) :
        lb = uncoveredSumLeft ( t . left )
    if ( t . right != None ) :
        rb = uncoveredSumRight ( t . right )
    return t . key + lb + rb
def isSumSame ( root ) :
    sumUC = uncoverSum ( root )
    sumT = Sum ( root )
    return ( sumUC == ( sumT - sumUC ) )
def inorder ( root ) :
    if ( root ) :
        inorder ( root . left )
        print ( root . key , end = " ▁ " )
        inorder ( root . right )
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 8 )
    root . left = newNode ( 3 )
    root . left . left = newNode ( 1 )
    root . left . right = newNode ( 6 )
    root . left . right . left = newNode ( 4 )
    root . left . right . right = newNode ( 7 )
    root . right = newNode ( 10 )
    root . right . right = newNode ( 14 )
    root . right . right . left = newNode ( 13 )
    if ( isSumSame ( root ) ) :
        print ( " Sum ▁ of ▁ covered ▁ and ▁ uncovered ▁ is ▁ same " )
    else :
        print ( " Sum ▁ of ▁ covered ▁ and ▁ uncovered ▁ is ▁ not ▁ same " )

Class/struct names: newNode
Python program:
import math
def countSetBits ( x ) :
    count = 0
    while ( x ) :
        x = x & ( x - 1 )
        count = count + 1
    return count
def ceilLog2 ( x ) :
    count = 0
    x = x - 1
    while ( x > 0 ) :
        x = x >> 1
        count = count + 1
    return count
def isBleak ( n ) :
    for x in range ( ( n - ceilLog2 ( n ) ) , n ) :
        if ( x + countSetBits ( x ) == n ) :
            return False
    return True
if ( isBleak ( 3 ) ) :
    print ( " Yes " )
else :
    print ( " No " )
if ( isBleak ( 4 ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Iterator variables: x
Python program:
def countStrings ( n ) :
    a = [ 0 ] * n
    b = [ 0 ] * n
    a [ 0 ] = b [ 0 ] = 1
    for i in range ( 1 , n ) :
        a [ i ] = a [ i - 1 ] + b [ i - 1 ]
        b [ i ] = a [ i - 1 ]
    return ( 1 << n ) - a [ n - 1 ] - b [ n - 1 ]
print ( countStrings ( 5 ) )

Index/key variables: i
Iterator variables: i
Python program:
import math
maxsize = float ( ' inf ' )
final_path = [ None ] * ( N + 1 )
visited = [ False ] * N
final_res = maxsize
TSP ( adj )
print ( " Minimum ▁ cost ▁ : " , final_res )
print ( " Path ▁ Taken ▁ : ▁ " , end = ' ▁ ' )
for i in range ( N + 1 ) :
    print ( final_path [ i ] , end = ' ▁ ' )
def copyToFinal ( curr_path ) :
    final_path [ : N + 1 ] = curr_path [ : ]
    final_path [ N ] = curr_path [ 0 ]
def firstMin ( adj , i ) :
    min = maxsize
    for k in range ( N ) :
        if adj [ i ] [ k ] < min and i != k :
            min = adj [ i ] [ k ]
    return min
def secondMin ( adj , i ) :
    first , second = maxsize , maxsize
    for j in range ( N ) :
        if i == j :
            continue
        if adj [ i ] [ j ] <= first :
            second = first
            first = adj [ i ] [ j ]
        elif ( adj [ i ] [ j ] <= second and adj [ i ] [ j ] != first ) :
            second = adj [ i ] [ j ]
    return second
def TSPRec ( adj , curr_bound , curr_weight , level , curr_path , visited ) :
    global final_res
    if level == N :
        if adj [ curr_path [ level - 1 ] ] [ curr_path [ 0 ] ] != 0 :
            curr_res = curr_weight + adj [ curr_path [ level - 1 ] ] [ curr_path [ 0 ] ]
            if curr_res < final_res :
                copyToFinal ( curr_path )
                final_res = curr_res
        return
    for i in range ( N ) :
        if ( adj [ curr_path [ level - 1 ] ] [ i ] != 0 and visited [ i ] == False ) :
            temp = curr_bound
            curr_weight += adj [ curr_path [ level - 1 ] ] [ i ]
            if level == 1 :
                curr_bound -= ( ( firstMin ( adj , curr_path [ level - 1 ] ) + firstMin ( adj , i ) ) / 2 )
            else :
                curr_bound -= ( ( secondMin ( adj , curr_path [ level - 1 ] ) + firstMin ( adj , i ) ) / 2 )
            if curr_bound + curr_weight < final_res :
                curr_path [ level ] = i
                visited [ i ] = True
                TSPRec ( adj , curr_bound , curr_weight , level + 1 , curr_path , visited )
            curr_weight -= adj [ curr_path [ level - 1 ] ] [ i ]
            curr_bound = temp
            visited = [ False ] * len ( visited )
            for j in range ( level ) :
                if curr_path [ j ] != - 1 :
                    visited [ curr_path [ j ] ] = True
def TSP ( adj ) :
    curr_bound = 0
    curr_path = [ - 1 ] * ( N + 1 )
    visited = [ False ] * N
    for i in range ( N ) :
        curr_bound += ( firstMin ( adj , i ) + secondMin ( adj , i ) )
    curr_bound = math . ceil ( curr_bound / 2 )
    visited [ 0 ] = True
    curr_path [ 0 ] = 0
    TSPRec ( adj , curr_bound , 0 , 1 , curr_path , visited )
adj = [ [ 0 , 10 , 15 , 20 ] , [ 10 , 0 , 35 , 25 ] , [ 15 , 35 , 0 , 30 ] , [ 20 , 25 , 30 , 0 ] ]
N = 4

Index/key variables: N, i, j, k, level
Accumulator variables: curr_bound, curr_weight
Iterator variables: i, j, k
Python program:
from queue import Queue
class newNode :
    def __init__ ( self , data ) :
        self . child = [ ]
        self . key = data
def numberOfSiblings ( root , x ) :
    if ( root == None ) :
        return 0
    q = Queue ( )
    q . put ( root )
    while ( not q . empty ( ) ) :
        p = q . queue [ 0 ]
        q . get ( )
        for i in range ( len ( p . child ) ) :
            if ( p . child [ i ] . key == x ) :
                return len ( p . child ) - 1
            q . put ( p . child [ i ] )
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 50 )
    ( root . child ) . append ( newNode ( 2 ) )
    ( root . child ) . append ( newNode ( 30 ) )
    ( root . child ) . append ( newNode ( 14 ) )
    ( root . child ) . append ( newNode ( 60 ) )
    ( root . child [ 0 ] . child ) . append ( newNode ( 15 ) )
    ( root . child [ 0 ] . child ) . append ( newNode ( 25 ) )
    ( root . child [ 0 ] . child [ 1 ] . child ) . append ( newNode ( 70 ) )
    ( root . child [ 0 ] . child [ 1 ] . child ) . append ( newNode ( 100 ) )
    ( root . child [ 1 ] . child ) . append ( newNode ( 6 ) )
    ( root . child [ 1 ] . child ) . append ( newNode ( 1 ) )
    ( root . child [ 2 ] . child ) . append ( newNode ( 7 ) )
    ( root . child [ 2 ] . child [ 0 ] . child ) . append ( newNode ( 17 ) )
    ( root . child [ 2 ] . child [ 0 ] . child ) . append ( newNode ( 99 ) )
    ( root . child [ 2 ] . child [ 0 ] . child ) . append ( newNode ( 27 ) )
    ( root . child [ 3 ] . child ) . append ( newNode ( 16 ) )
    x = 100
    print ( numberOfSiblings ( root , x ) )

Index/key variables: i
Iterator variables: i
Class/struct names: newNode
Python program:
INT_MAX = 2 ** 31
INT_MIN = - 2 ** 31
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
def checkLevelLeafNode ( root ) :
    if ( not root ) :
        return 1
    q = [ ]
    q . append ( root )
    result = INT_MAX
    level = 0
    while ( len ( q ) ) :
        size = len ( q )
        level += 1
        while ( size > 0 or len ( q ) ) :
            temp = q [ 0 ]
            q . pop ( 0 )
            if ( temp . left ) :
                q . append ( temp . left )
                if ( not temp . left . right and not temp . left . left ) :
                    if ( result == INT_MAX ) :
                        result = level
                    elif ( result != level ) :
                        return 0
            if ( temp . right ) :
                q . append ( temp . right )
                if ( not temp . right . left and not temp . right . right ) :
                    if ( result == INT_MAX ) :
                        result = level
                    elif ( result != level ) :
                        return 0
                size -= 1
    return 1
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 1 )
    root . left = newNode ( 2 )
    root . right = newNode ( 3 )
    root . left . right = newNode ( 4 )
    root . right . left = newNode ( 5 )
    root . right . right = newNode ( 6 )
    result = checkLevelLeafNode ( root )
    if ( result ) :
        print ( " All ▁ leaf ▁ nodes ▁ are ▁ at ▁ same ▁ level " )
    else :
        print ( " Leaf ▁ nodes ▁ not ▁ at ▁ same ▁ level " )

Accumulator variables: level, q, size
Class/struct names: newNode
Python program:
from queue import Queue
def minIndex ( q , sortedIndex ) :
    min_index = - 1
    min_val = 999999999999
    n = q . qsize ( )
    for i in range ( n ) :
        curr = q . queue [ 0 ]
        q . get ( )
        if ( curr <= min_val and i <= sortedIndex ) :
            min_index = i
            min_val = curr
        q . put ( curr )
    return min_index
def insertMinToRear ( q , min_index ) :
    min_val = None
    n = q . qsize ( )
    for i in range ( n ) :
        curr = q . queue [ 0 ]
        q . get ( )
        if ( i != min_index ) :
            q . put ( curr )
        else :
            min_val = curr
    q . put ( min_val )
def sortQueue ( q ) :
    for i in range ( 1 , q . qsize ( ) + 1 ) :
        min_index = minIndex ( q , q . qsize ( ) - i )
        insertMinToRear ( q , min_index )
if __name__ == ' _ _ main _ _ ' :
    q = Queue ( )
    q . put ( 30 )
    q . put ( 11 )
    q . put ( 15 )
    q . put ( 4 )
    sortQueue ( q )
    while ( q . empty ( ) == False ) :
        print ( q . queue [ 0 ] , end = " ▁ " )
        q . get ( )

Iterator variables: i
Python program:
class newNode :
    def __init__ ( self , x ) :
        self . data = x
        self . left = self . right = None
def count ( root ) :
    if ( root == None ) :
        return 0
    return ( count ( root . left ) + count ( root . right ) + 1 )
def checkRec ( root , n ) :
    if ( root == None ) :
        return False
    if ( count ( root ) == n - count ( root ) ) :
        return True
    return ( checkRec ( root . left , n ) or checkRec ( root . right , n ) )
def check ( root ) :
    n = count ( root )
    return checkRec ( root , n )
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 5 )
    root . left = newNode ( 1 )
    root . right = newNode ( 6 )
    root . left . left = newNode ( 3 )
    root . right . left = newNode ( 7 )
    root . right . right = newNode ( 4 )
    if check ( root ) :
        print ( " YES " )
    else :
        print ( " NO " )

Class/struct names: newNode
Python program:
from collections import deque
def printMax ( arr , n , k ) :
    Qi = deque ( )
    for i in range ( k ) :
        while Qi and arr [ i ] >= arr [ Qi [ - 1 ] ] :
            Qi . pop ( )
        Qi . append ( i ) ;
    for i in range ( k , n ) :
        print ( str ( arr [ Qi [ 0 ] ] ) + " ▁ " , end = " " )
        while Qi and Qi [ 0 ] <= i - k :
            Qi . popleft ( )
        while Qi and arr [ i ] >= arr [ Qi [ - 1 ] ] :
            Qi . pop ( )
        Qi . append ( i )
    print ( str ( arr [ Qi [ 0 ] ] ) )
if __name__ == " _ _ main _ _ " :
    arr = [ 12 , 1 , 78 , 90 , 57 , 89 , 56 ]
    k = 3
    printMax ( arr , len ( arr ) , k )

Index/key variables: i
Accumulator variables: Qi
Iterator variables: i
Python program:
from collections import deque
def SumOfKsubArray ( arr , n , k ) :
    Sum = 0
    S = deque ( )
    G = deque ( )
    for i in range ( k ) :
        while ( len ( S ) > 0 and arr [ S [ - 1 ] ] >= arr [ i ] ) :
            S . pop ( )
        while ( len ( G ) > 0 and arr [ G [ - 1 ] ] <= arr [ i ] ) :
            G . pop ( )
        G . append ( i )
        S . append ( i )
    for i in range ( k , n ) :
        Sum += arr [ S [ 0 ] ] + arr [ G [ 0 ] ]
        while ( len ( S ) > 0 and S [ 0 ] <= i - k ) :
            S . popleft ( )
        while ( len ( G ) > 0 and G [ 0 ] <= i - k ) :
            G . popleft ( )
        while ( len ( S ) > 0 and arr [ S [ - 1 ] ] >= arr [ i ] ) :
            S . pop ( )
        while ( len ( G ) > 0 and arr [ G [ - 1 ] ] <= arr [ i ] ) :
            G . pop ( )
        G . append ( i )
        S . append ( i )
    Sum += arr [ S [ 0 ] ] + arr [ G [ 0 ] ]
    return Sum
arr = [ 2 , 5 , - 1 , 7 , - 3 , - 1 , - 2 ]
n = len ( arr )
k = 3
print ( SumOfKsubArray ( arr , n , k ) )

Index/key variables: i
Accumulator variables: G, S, Sum
Iterator variables: i
Python program:
def printDistance ( mat ) :
    global N , M
    ans = [ [ None ] * M for i in range ( N ) ]
    for i in range ( N ) :
        for j in range ( M ) :
            ans [ i ] [ j ] = 999999999999
    for i in range ( N ) :
        for j in range ( M ) :
            for k in range ( N ) :
                for l in range ( M ) :
                    if ( mat [ k ] [ l ] == 1 ) :
                        ans [ i ] [ j ] = min ( ans [ i ] [ j ] , abs ( i - k ) + abs ( j - l ) )
    for i in range ( N ) :
        for j in range ( M ) :
            print ( ans [ i ] [ j ] , end = " ▁ " )
        print ( )
N = 3
M = 4
mat = [ [ 0 , 0 , 0 , 1 ] , [ 0 , 0 , 1 , 1 ] , [ 0 , 1 , 1 , 0 ] ]
printDistance ( mat )

Index/key variables: i, j, k, l
Iterator variables: i, j, k, l