dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
count = [ 0 ]
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
        self . visited = False
def NthInorder ( node , n ) :
    if ( node == None ) :
        return
    if ( count [ 0 ] <= n ) :
        NthInorder ( node . left , n )
        count [ 0 ] += 1
        if ( count [ 0 ] == n ) :
            print ( node . data , end = " ▁ " )
        NthInorder ( node . right , n )
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 10 )
    root . left = newNode ( 20 )
    root . right = newNode ( 30 )
    root . left . left = newNode ( 40 )
    root . left . right = newNode ( 50 )
    n = 4
    NthInorder ( root , n )

Class/struct names: newNode
Python program:
MAX = 100
def dfs ( n , m , visit , adj , N , M ) :
    visit [ n ] [ m ] = 1
    if ( n + 1 < N and adj [ n ] [ m ] >= adj [ n + 1 ] [ m ] and not visit [ n + 1 ] [ m ] ) :
        dfs ( n + 1 , m , visit , adj , N , M )
    if ( m + 1 < M and adj [ n ] [ m ] >= adj [ n ] [ m + 1 ] and not visit [ n ] [ m + 1 ] ) :
        dfs ( n , m + 1 , visit , adj , N , M )
    if ( n - 1 >= 0 and adj [ n ] [ m ] >= adj [ n - 1 ] [ m ] and not visit [ n - 1 ] [ m ] ) :
        dfs ( n - 1 , m , visit , adj , N , M )
    if ( m - 1 >= 0 and adj [ n ] [ m ] >= adj [ n ] [ m - 1 ] and not visit [ n ] [ m - 1 ] ) :
        dfs ( n , m - 1 , visit , adj , N , M )
def printMinSources ( adj , N , M ) :
    x = [ ]
    for i in range ( N ) :
        for j in range ( M ) :
            x . append ( [ adj [ i ] [ j ] , [ i , j ] ] )
    x . sort ( )
    visit = [ [ False for i in range ( MAX ) ] for i in range ( N ) ]
    for i in range ( len ( x ) - 1 , - 1 , - 1 ) :
        if ( not visit [ x [ i ] [ 1 ] [ 0 ] ] [ x [ i ] [ 1 ] [ 1 ] ] ) :
            print ( ' { } ▁ { } ' . format ( x [ i ] [ 1 ] [ 0 ] , x [ i ] [ 1 ] [ 1 ] ) )
            dfs ( x [ i ] [ 1 ] [ 0 ] , x [ i ] [ 1 ] [ 1 ] , visit , adj , N , M )
if __name__ == ' _ _ main _ _ ' :
    N = 2
    M = 2
    adj = [ [ 3 , 3 ] , [ 1 , 1 ] ]
    printMinSources ( adj , N , M )

Index/key variables: i, j, m, n
Accumulator variables: x
Iterator variables: i, j
Python program:
import queue
class Graph :
    def __init__ ( self , V ) :
        self . V = V ;
        self . l = [ [ ] for i in range ( V ) ]
    def addedge ( self , V1 , V2 ) :
        self . l [ V1 ] . append ( V2 ) ;
        self . l [ V2 ] . append ( V1 ) ;
def SieveOfEratosthenes ( v ) :
    n = 9999
    prime = [ True ] * ( n + 1 )
    p = 2
    while p * p <= n :
        if ( prime [ p ] == True ) :
            for i in range ( p * p , n + 1 , p ) :
                prime [ i ] = False
        p += 1
    for p in range ( 1000 , n + 1 ) :
        if ( prime [ p ] ) :
            v . append ( p )
    def bfs ( self , in1 , in2 ) :
        visited = [ 0 ] * self . V
        que = queue . Queue ( )
        visited [ in1 ] = 1
        que . put ( in1 )
        while ( not que . empty ( ) ) :
            p = que . queue [ 0 ]
            que . get ( )
            i = 0
            while i < len ( self . l [ p ] ) :
                if ( not visited [ self . l [ p ] [ i ] ] ) :
                    visited [ self . l [ p ] [ i ] ] = visited [ p ] + 1
                    que . put ( self . l [ p ] [ i ] )
                if ( self . l [ p ] [ i ] == in2 ) :
                    return visited [ self . l [ p ] [ i ] ] - 1
                i += 1
def compare ( num1 , num2 ) :
    s1 = str ( num1 )
    s2 = str ( num2 )
    c = 0
    if ( s1 [ 0 ] != s2 [ 0 ] ) :
        c += 1
    if ( s1 [ 1 ] != s2 [ 1 ] ) :
        c += 1
    if ( s1 [ 2 ] != s2 [ 2 ] ) :
        c += 1
    if ( s1 [ 3 ] != s2 [ 3 ] ) :
        c += 1
    return ( c == 1 )
def shortestPath ( num1 , num2 ) :
    pset = [ ]
    SieveOfEratosthenes ( pset )
    g = Graph ( len ( pset ) )
    for i in range ( len ( pset ) ) :
        for j in range ( i + 1 , len ( pset ) ) :
            if ( compare ( pset [ i ] , pset [ j ] ) ) :
                g . addedge ( i , j )
    in1 , in2 = None , None
    for j in range ( len ( pset ) ) :
        if ( pset [ j ] == num1 ) :
            in1 = j
    for j in range ( len ( pset ) ) :
        if ( pset [ j ] == num2 ) :
            in2 = j
    return g . bfs ( in1 , in2 )
if __name__ == ' _ _ main _ _ ' :
    num1 = 1033
    num2 = 8179
    print ( shortestPath ( num1 , num2 ) )

Index/key variables: V1, V2, i, in1, j, p
Accumulator variables: v
Iterator variables: i, j, p
Class/struct names: Graph
Python program:
import queue
def printLevels ( graph , V , x ) :
    level = [ None ] * V
    marked = [ False ] * V
    que = queue . Queue ( )
    que . put ( x )
    level [ x ] = 0
    marked [ x ] = True
    while ( not que . empty ( ) ) :
        x = que . get ( )
        for i in range ( len ( graph [ x ] ) ) :
            b = graph [ x ] [ i ]
            if ( not marked [ b ] ) :
                que . put ( b )
                level [ b ] = level [ x ] + 1
                marked [ b ] = True
    print ( " Nodes " , " ▁ " , " Level " )
    for i in range ( V ) :
        print ( " ▁ " , i , " ▁ - - > ▁ " , level [ i ] )
if __name__ == ' _ _ main _ _ ' :
    V = 8
    graph = [ [ ] for i in range ( V ) ]
    graph [ 0 ] . append ( 1 )
    graph [ 0 ] . append ( 2 )
    graph [ 1 ] . append ( 3 )
    graph [ 1 ] . append ( 4 )
    graph [ 1 ] . append ( 5 )
    graph [ 2 ] . append ( 5 )
    graph [ 2 ] . append ( 6 )
    graph [ 6 ] . append ( 7 )
    printLevels ( graph , V , 0 )

Index/key variables: b, i, x
Iterator variables: i
Python program:
def dfs ( parent , ans , connectchars ) :
    ans [ parent ] = 1
    for i in range ( len ( connectchars [ parent ] ) ) :
        if ( not ans [ connectchars [ parent ] [ i ] ] ) :
            dfs ( connectchars [ parent ] [ i ] , ans , connectchars )
def printBinaryPalindrome ( n , k ) :
    arr = [ 0 ] * n
    ans = [ 0 ] * n
    connectchars = [ [ ] for i in range ( k ) ]
    for i in range ( n ) :
        arr [ i ] = i % k
    for i in range ( int ( n / 2 ) ) :
        connectchars [ arr [ i ] ] . append ( arr [ n - i - 1 ] )
        connectchars [ arr [ n - i - 1 ] ] . append ( arr [ i ] )
    dfs ( 0 , ans , connectchars )
    for i in range ( n ) :
        print ( ans [ arr [ i ] ] , end = " " )
if __name__ == ' _ _ main _ _ ' :
    n = 10
    k = 4
    printBinaryPalindrome ( n , k )

Index/key variables: i, parent
Iterator variables: i
Python program:
class createNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
flag = [ 0 ]
def NthPostordernode ( root , N ) :
    if ( root == None ) :
        return
    if ( flag [ 0 ] <= N [ 0 ] ) :
        NthPostordernode ( root . left , N )
        NthPostordernode ( root . right , N )
        flag [ 0 ] += 1
        if ( flag [ 0 ] == N [ 0 ] ) :
            print ( root . data )
if __name__ == ' _ _ main _ _ ' :
    root = createNode ( 25 )
    root . left = createNode ( 20 )
    root . right = createNode ( 30 )
    root . left . left = createNode ( 18 )
    root . left . right = createNode ( 22 )
    root . right . left = createNode ( 24 )
    root . right . right = createNode ( 32 )
    N = [ 6 ]
    NthPostordernode ( root , N )

Class/struct names: createNode
Python program:
import math
import queue
def isPossible ( m , n , k , r , X , Y ) :
    rect = [ [ 0 ] * n for i in range ( m ) ]
    for i in range ( m ) :
        for j in range ( n ) :
            for p in range ( k ) :
                if ( math . sqrt ( ( pow ( ( X [ p ] - 1 - i ) , 2 ) + pow ( ( Y [ p ] - 1 - j ) , 2 ) ) ) <= r ) :
                    rect [ i ] [ j ] = - 1
    if ( rect [ 0 ] [ 0 ] == - 1 ) :
        return False
    qu = queue . Queue ( )
    rect [ 0 ] [ 0 ] = 1
    qu . put ( [ 0 , 0 ] )
    while ( not qu . empty ( ) ) :
        arr = qu . get ( )
        elex = arr [ 0 ]
        eley = arr [ 1 ]
        if ( ( elex > 0 ) and ( eley > 0 ) and ( rect [ elex - 1 ] [ eley - 1 ] == 0 ) ) :
            rect [ elex - 1 ] [ eley - 1 ] = 1
            v = [ elex - 1 , eley - 1 ]
            qu . put ( v )
        if ( ( elex > 0 ) and ( rect [ elex - 1 ] [ eley ] == 0 ) ) :
            rect [ elex - 1 ] [ eley ] = 1
            v = [ elex - 1 , eley ]
            qu . put ( v )
        if ( ( elex > 0 ) and ( eley < n - 1 ) and ( rect [ elex - 1 ] [ eley + 1 ] == 0 ) ) :
            rect [ elex - 1 ] [ eley + 1 ] = 1
            v = [ elex - 1 , eley + 1 ]
            qu . put ( v )
        if ( ( eley > 0 ) and ( rect [ elex ] [ eley - 1 ] == 0 ) ) :
            rect [ elex ] [ eley - 1 ] = 1
            v = [ elex , eley - 1 ]
            qu . put ( v )
        if ( ( eley < n - 1 ) and ( rect [ elex ] [ eley + 1 ] == 0 ) ) :
            rect [ elex ] [ eley + 1 ] = 1
            v = [ elex , eley + 1 ]
            qu . put ( v )
        if ( ( elex < m - 1 ) and ( eley > 0 ) and ( rect [ elex + 1 ] [ eley - 1 ] == 0 ) ) :
            rect [ elex + 1 ] [ eley - 1 ] = 1
            v = [ elex + 1 , eley - 1 ]
            qu . put ( v )
        if ( ( elex < m - 1 ) and ( rect [ elex + 1 ] [ eley ] == 0 ) ) :
            rect [ elex + 1 ] [ eley ] = 1
            v = [ elex + 1 , eley ]
            qu . put ( v )
        if ( ( elex < m - 1 ) and ( eley < n - 1 ) and ( rect [ elex + 1 ] [ eley + 1 ] == 0 ) ) :
            rect [ elex + 1 ] [ eley + 1 ] = 1
            v = [ elex + 1 , eley + 1 ]
            qu . put ( v )
    return ( rect [ m - 1 ] [ n - 1 ] == 1 )
if __name__ == ' _ _ main _ _ ' :
    m1 = 5
    n1 = 5
    k1 = 2
    r1 = 1
    X1 = [ 1 , 3 ]
    Y1 = [ 3 , 3 ]
    if ( isPossible ( m1 , n1 , k1 , r1 , X1 , Y1 ) ) :
        print ( " Possible " )
    else :
        print ( " Not ▁ Possible " )
    m2 = 5
    n2 = 5
    k2 = 2
    r2 = 1
    X2 = [ 1 , 1 ]
    Y2 = [ 2 , 3 ]
    if ( isPossible ( m2 , n2 , k2 , r2 , X2 , Y2 ) ) :
        print ( " Possible " )
    else :
        print ( " Not ▁ Possible " )

Index/key variables: elex, eley, i, j, p
Iterator variables: i, j, p
Python program:
def dfs ( List , node , arrival ) :
    print ( node )
    for i in range ( len ( List [ node ] ) ) :
        if ( List [ node ] [ i ] != arrival ) :
            dfs ( List , List [ node ] [ i ] , node )
if __name__ == ' _ _ main _ _ ' :
    nodes = 5
    List = [ [ ] for i in range ( 10000 ) ]
    List [ 1 ] . append ( 2 )
    List [ 2 ] . append ( 1 )
    List [ 1 ] . append ( 3 )
    List [ 3 ] . append ( 1 )
    List [ 2 ] . append ( 4 )
    List [ 4 ] . append ( 2 )
    List [ 3 ] . append ( 5 )
    List [ 5 ] . append ( 3 )
    dfs ( List , 1 , 0 )

Index/key variables: i, node
Iterator variables: i
Python program:
def dfs ( adj , node , parent , color ) :
    count_color [ color ] += 1
    for i in range ( len ( adj [ node ] ) ) :
        if ( adj [ node ] [ i ] != parent ) :
            dfs ( adj , adj [ node ] [ i ] , node , not color )
def findMaxEdges ( adj , n ) :
    dfs ( adj , 1 , 0 , 0 )
    return ( count_color [ 0 ] * count_color [ 1 ] - ( n - 1 ) )
count_color = [ 0 , 0 ]
n = 5
adj = [ [ ] for i in range ( n + 1 ) ]
adj [ 1 ] . append ( 2 )
adj [ 1 ] . append ( 3 )
adj [ 2 ] . append ( 4 )
adj [ 3 ] . append ( 5 )
print ( findMaxEdges ( adj , n ) )

Index/key variables: color, i, node
Iterator variables: i
Python program:
def countMinSteps ( arr , target , n ) :
    arr . sort ( )
    minimumSteps = 0
    i , j = 0 , n - 1
    while i <= j :
        if arr [ i ] + arr [ j ] <= target :
            i += 1
            j -= 1
        else :
            j -= 1
        minimumSteps += 1
    return minimumSteps
arr = [ 4 , 6 , 2 , 9 , 6 , 5 , 8 , 10 ]
target = 11
size = len ( arr )
print ( countMinSteps ( arr , target , size ) )

Index/key variables: i, j
Accumulator variables: minimumSteps
Python program:
sticks = [ 6 , 7 , 4 , 6 , 5 , 4 , 6 , 5 , 2 , 4 , 4 , 3 , 6 , 6 , 6 , 5 , 7 , 6 , 5 , 3 , 5 , 4 , 6 , 4 , 3 , 4 ]
number = [ 6 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 ]
def countSticks ( st ) :
    cnt = 0
    for i in range ( len ( st ) ) :
        ch = st [ i ]
        if ( ch >= ' A ' and ch <= ' Z ' ) :
            cnt += sticks [ ord ( ch ) - ord ( ' A ' ) ]
        else :
            cnt += number [ ord ( ch ) - ord ( '0' ) ]
    return cnt
def sortArr ( arr , n ) :
    vp = [ ]
    for i in range ( n ) :
        vp . append ( [ countSticks ( arr [ i ] ) , arr [ i ] ] )
    vp . sort ( )
    for i in range ( len ( vp ) ) :
        print ( vp [ i ] [ 1 ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ " GEEKS " , " FOR " , " GEEKSFORGEEKS " ]
    n = len ( arr )
    sortArr ( arr , n )

Index/key variables: i
Accumulator variables: cnt, vp
Iterator variables: i
Python program:
def CountPairs ( arr , n ) :
    count = 0 ;
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            if ( arr [ i ] + arr [ j ] > 0 ) :
                count += 1 ;
    return count ;
if __name__ == " _ _ main _ _ " :
    arr = [ - 7 , - 1 , 3 , 2 ] ;
    n = len ( arr ) ;
    print ( CountPairs ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
MAX = 100001
def isPossible ( rangee , N ) :
    test = [ [ 0 for x in range ( 3 ) ] for x in range ( N ) ]
    for i in range ( N ) :
        test [ i ] [ 0 ] = rangee [ i ] [ 0 ]
        test [ i ] [ 1 ] = rangee [ i ] [ 1 ]
        test [ i ] [ 2 ] = rangee [ i ] [ 2 ]
    test . sort ( key = lambda x : x [ 2 ] )
    for i in range ( N ) :
        count = [ 0 ] * MAX
        current_velocity = test [ i ] [ 2 ]
        j = i
        while ( j < N and test [ j ] [ 2 ] == current_velocity ) :
            for k in range ( test [ j ] [ 0 ] , test [ j ] [ 1 ] + 1 ) :
                count [ k ] += 1
                if ( count [ k ] >= 3 ) :
                    return False
            j += 1
        i = j - 1
    return True
rangee = [ [ 1 , 2 , 3 ] , [ 2 , 5 , 1 ] , [ 3 , 10 , 1 ] , [ 4 , 4 , 1 ] , [ 5 , 7 , 10 ] ]
n = len ( rangee )
if ( isPossible ( rangee , n ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i, j, k
Iterator variables: i, k
Python program:
def get_string ( st , n ) :
    prev = st [ 0 ]
    result = [ ]
    result . append ( 0 )
    for i in range ( 1 , n ) :
        if ( st [ i ] . isdigit ( ) != prev . isdigit ( ) ) :
            result . append ( i )
        prev = st [ i ]
    st = list ( st )
    st [ : result [ 0 ] ] . sort ( )
    p = st . copy ( )
    for i in range ( len ( result ) - 1 ) :
        p [ result [ i ] : result [ i + 1 ] ] = sorted ( st [ result [ i ] : result [ i + 1 ] ] )
    p [ len ( p ) - 2 : ] = sorted ( st [ result [ - 1 ] : ] )
    return ' ' . join ( p )
if __name__ == " _ _ main _ _ " :
    st = "121geeks21"
    n = len ( st )
    print ( get_string ( st , n ) )

Index/key variables: i
Accumulator variables: result
Iterator variables: i
Python program:
N = 2005
ans = dict ( )
def dfs ( n , left , ct ) :
    if ( ct >= 15 ) :
        return
    if ( left == 0 ) :
        ans [ n ] = 1
    for i in range ( min ( left , 9 ) + 1 ) :
        dfs ( n * 10 + i , left - i , ct + 1 )
def getKthNum ( m , k ) :
    dfs ( 0 , m , 0 )
    c = 0
    for it in sorted ( ans . keys ( ) ) :
        c += 1
        if ( c == k ) :
            return it
    return - 1
m = 5
k = 3
print ( getKthNum ( m , k ) )

Index/key variables: n
Accumulator variables: c
Iterator variables: i, it
Python program:
from bisect import bisect_left as upper_bound
def Removal ( v , n ) :
    v = sorted ( v )
    ans = 10 ** 9
    for i in range ( len ( v ) ) :
        j = upper_bound ( v , ( 2 * ( a [ i ] ) ) )
        ans = min ( ans , n - ( j - i - 1 ) )
    return ans
a = [ 4 , 5 , 100 , 9 , 10 , 11 , 12 , 15 , 200 ]
n = len ( a )
print ( Removal ( a , n ) )

Index/key variables: i
Iterator variables: i
Python program:
class Queue :
    def __init__ ( self ) :
        self . queue = [ ]
    def put ( self , item ) :
        self . queue . append ( item )
    def get ( self ) :
        if len ( self . queue ) < 1 :
            return None
        return self . queue . pop ( 0 )
    def front ( self ) :
        return self . queue [ 0 ]
    def size ( self ) :
        return len ( self . queue )
    def empty ( self ) :
        return not ( len ( self . queue ) )
def FrontToLast ( q , qsize ) :
    if qsize <= 0 :
        return
    q . put ( q . get ( ) )
    FrontToLast ( q , qsize - 1 )
def pushInQueue ( q , temp , qsize ) :
    if q . empty ( ) or qsize == 0 :
        q . put ( temp )
        return
    elif temp <= q . front ( ) :
        q . put ( temp )
        FrontToLast ( q , qsize )
    else :
        q . put ( q . get ( ) )
        pushInQueue ( q , temp , qsize - 1 )
def sortQueue ( q ) :
    if q . empty ( ) :
        return
    temp = q . get ( )
    sortQueue ( q )
    pushInQueue ( q , temp , q . size ( ) )
qu = Queue ( )
qu . put ( 10 )
qu . put ( 7 )
qu . put ( 16 )
qu . put ( 9 )
qu . put ( 20 )
qu . put ( 5 )
sortQueue ( qu )
while not qu . empty ( ) :
    print ( qu . get ( ) , end = ' ▁ ' )

Class/struct names: Queue
Python program:
def partition ( arr , low , high , mod ) :
    pivot = ord ( arr [ high ] ) ;
    i = ( low - 1 ) ;
    piv = pivot % mod ;
    for j in range ( low , high ) :
        a = ord ( arr [ j ] ) % mod ;
        if ( a <= piv ) :
            i += 1 ;
            arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]
    arr [ i + 1 ] , arr [ high ] = arr [ high ] , arr [ i + 1 ]
    return ( i + 1 ) ;
def quickSort ( arr , low , high , mod ) :
    if ( low < high ) :
        pi = partition ( arr , low , high , mod ) ;
        quickSort ( arr , low , pi - 1 , mod ) ;
        quickSort ( arr , pi + 1 , high , mod ) ;
        return arr
def printArray ( arr , size ) :
    for i in range ( 0 , size ) :
        print ( arr [ i ] , end = " ▁ " ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ ' g ' , ' e ' , ' e ' , ' k ' , ' s ' ] ;
    n = len ( arr ) ;
    mod = 8 ;
    arr = quickSort ( arr , 0 , n - 1 , mod ) ;
    printArray ( arr , n ) ;

Index/key variables: high, i, j
Iterator variables: i, j
Python program:
class Node :
    def __init__ ( self , val ) :
        self . data = val
        self . next = None
def selectionSort ( head ) :
    a = b = head
    while b . next :
        c = d = b . next
        while d :
            if b . data > d . data :
                if b . next == d :
                    if b == head :
                        b . next = d . next
                        d . next = b
                        b , d = d , b
                        c = d
                        head = b
                        d = d . next
                    else :
                        b . next = d . next
                        d . next = b
                        a . next = d
                        b , d = d , b
                        c = d
                        d = d . next
                else :
                    if b == head :
                        r = b . next
                        b . next = d . next
                        d . next = r
                        c . next = b
                        b , d = d , b
                        c = d
                        d = d . next
                        head = b
                    else :
                        r = b . next
                        b . next = d . next
                        d . next = r
                        c . next = b
                        a . next = d
                        b , d = d , b
                        c = d
                        d = d . next
            else :
                c = d
                d = d . next
        a = b
        b = b . next
    return head
def printList ( head ) :
    while head :
        print ( head . data , end = " ▁ " )
        head = head . next
if __name__ == " _ _ main _ _ " :
    head = Node ( 5 )
    head . next = Node ( 4 )
    head . next . next = Node ( 3 )
    head = selectionSort ( head )
    printList ( head )

Class/struct names: Node
Python program:
import sys ;
def strBitwiseAND ( arr , n ) :
    res = " "
    smallest_size = sys . maxsize ;
    largest_size = - ( sys . maxsize - 1 ) ;
    for i in range ( n ) :
        arr [ i ] = arr [ i ] [ : : - 1 ] ;
        smallest_size = min ( smallest_size , len ( arr [ i ] ) ) ;
        largest_size = max ( largest_size , len ( arr [ i ] ) ) ;
    for i in range ( smallest_size ) :
        all_ones = True ;
        for j in range ( n ) :
            if ( arr [ j ] [ i ] == '0' ) :
                all_ones = False ;
                break ;
        if all_ones :
            res += '1' ;
        else :
            res += '0' ;
    for i in range ( largest_size - smallest_size ) :
        res += '0' ;
    res = res [ : : - 1 ] ;
    return res ;
if __name__ == " _ _ main _ _ " :
    arr = [ "101" , "110110" , "111" ] ;
    n = len ( arr ) ;
    print ( strBitwiseAND ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: res
Iterator variables: i, j
Boolean variables: all_ones
Python program:
from typing import List
from collections import deque
def printpath ( path : List [ int ] ) -> None :
    size = len ( path )
    for i in range ( size ) :
        print ( path [ i ] , end = " ▁ " )
    print ( )
def isNotVisited ( x : int , path : List [ int ] ) -> int :
    size = len ( path )
    for i in range ( size ) :
        if ( path [ i ] == x ) :
            return 0
    return 1
def findpaths ( g : List [ List [ int ] ] , src : int , dst : int , v : int ) -> None :
    q = deque ( )
    path = [ ]
    path . append ( src )
    q . append ( path . copy ( ) )
    while q :
        path = q . popleft ( )
        last = path [ len ( path ) - 1 ]
        if ( last == dst ) :
            printpath ( path )
        for i in range ( len ( g [ last ] ) ) :
            if ( isNotVisited ( g [ last ] [ i ] , path ) ) :
                newpath = path . copy ( )
                newpath . append ( g [ last ] [ i ] )
                q . append ( newpath )
if __name__ == " _ _ main _ _ " :
    v = 4
    g = [ [ ] for _ in range ( 4 ) ]
    g [ 0 ] . append ( 3 )
    g [ 0 ] . append ( 1 )
    g [ 0 ] . append ( 2 )
    g [ 1 ] . append ( 3 )
    g [ 2 ] . append ( 0 )
    g [ 2 ] . append ( 1 )
    src = 2
    dst = 3
    print ( " path ▁ from ▁ src ▁ { } ▁ to ▁ dst ▁ { } ▁ are " . format ( src , dst ) )
    findpaths ( g , src , dst , v )

Index/key variables: i, int, last
Accumulator variables: newpath, q
Iterator variables: i
Python program:
def AlternateRearrange ( arr , n ) :
    arr . sort ( )
    for i in range ( n ) :
        if ( arr [ i ] % 2 == 0 ) :
            v1 . append ( arr [ i ] )
        else :
            v2 . append ( arr [ i ] )
    index = 0
    i = 0
    j = 0
    flag = False
    if ( arr [ 0 ] % 2 == 0 ) :
        flag = True
    while ( index < n ) :
        if ( flag == True and i < len ( v1 ) ) :
            arr [ index ] = v1 [ i ]
            index += 1
            i += 1
            flag = ~ flag
        elif j < len ( v2 ) :
            arr [ index ] = v2 [ j ]
            index += 1
            j += 1
            flag = ~ flag
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " )
arr = [ 9 , 8 , 13 , 2 , 19 , 14 , 21 , 23 , 25 ]
n = len ( arr )
AlternateRearrange ( arr , n )

Index/key variables: i, index, j
Accumulator variables: v1, v2
Iterator variables: i
Boolean variables: flag
Python program:
def getNumToAdd ( arr , n ) :
    arr . sort ( reverse = False )
    d = arr [ 1 ] - arr [ 0 ]
    numToAdd = - 1
    numAdded = False
    for i in range ( 2 , n , 1 ) :
        diff = arr [ i ] - arr [ i - 1 ]
        if ( diff != d ) :
            if ( numAdded ) :
                return - 1
            if ( diff == 2 * d ) :
                numToAdd = arr [ i ] - d
                numAdded = True
            else :
                return - 1
    if ( numToAdd == - 1 ) :
        return ( arr [ n - 1 ] + d )
    return numToAdd
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 3 , 5 , 7 , 11 , 13 , 15 ]
    n = len ( arr )
    print ( getNumToAdd ( arr , n ) )

Index/key variables: i
Iterator variables: i
Boolean variables: numAdded