dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
class createNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def insertNode ( root , x ) :
    p , q = root , None
    while p != None :
        q = p
        if p . data < x :
            p = p . right
        else :
            p = p . left
    if q == None :
        p = createNode ( x )
    else :
        if q . data < x :
            q . right = createNode ( x )
        else :
            q . left = createNode ( x )
def maxelpath ( q , x ) :
    p = q
    mx = - 999999999999
    while p . data != x :
        if p . data > x :
            mx = max ( mx , p . data )
            p = p . left
        else :
            mx = max ( mx , p . data )
            p = p . right
    return max ( mx , x )
def maximumElement ( root , x , y ) :
    p = root
    while ( ( x < p . data and y < p . data ) or ( x > p . data and y > p . data ) ) :
        if x < p . data and y < p . data :
            p = p . left
        elif x > p . data and y > p . data :
            p = p . right
    return max ( maxelpath ( p , x ) , maxelpath ( p , y ) )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 18 , 36 , 9 , 6 , 12 , 10 , 1 , 8 ]
    a , b = 1 , 10
    n = len ( arr )
    root = createNode ( arr [ 0 ] )
    for i in range ( 1 , n ) :
        insertNode ( root , arr [ i ] )
    print ( maximumElement ( root , a , b ) )

Index/key variables: i
Iterator variables: i
Class/struct names: createNode
Python program:
class newNode :
    def __init__ ( self , key ) :
        self . info = key
        self . left = None
        self . right = None
        self . lthread = True
        self . rthread = True
def insert ( root , ikey ) :
    ptr = root
    par = None
    while ptr != None :
        if ikey == ( ptr . info ) :
            print ( " Duplicate ▁ Key ▁ ! " )
            return root
        par = ptr
        if ikey < ptr . info :
            if ptr . lthread == False :
                ptr = ptr . left
            else :
                break
        else :
            if ptr . rthread == False :
                ptr = ptr . right
            else :
                break
    tmp = newNode ( ikey )
    if par == None :
        root = tmp
        tmp . left = None
        tmp . right = None
    elif ikey < ( par . info ) :
        tmp . left = par . left
        tmp . right = par
        par . lthread = False
        par . left = tmp
    else :
        tmp . left = par
        tmp . right = par . right
        par . rthread = False
        par . right = tmp
    return root
def inorderSuccessor ( ptr ) :
    if ptr . rthread == True :
        return ptr . right
    ptr = ptr . right
    while ptr . lthread == False :
        ptr = ptr . left
    return ptr
def inorder ( root ) :
    if root == None :
        print ( " Tree ▁ is ▁ empty " )
    ptr = root
    while ptr . lthread == False :
        ptr = ptr . left
    while ptr != None :
        print ( ptr . info , end = " ▁ " )
        ptr = inorderSuccessor ( ptr )
if __name__ == ' _ _ main _ _ ' :
    root = None
    root = insert ( root , 20 )
    root = insert ( root , 10 )
    root = insert ( root , 30 )
    root = insert ( root , 5 )
    root = insert ( root , 16 )
    root = insert ( root , 14 )
    root = insert ( root , 17 )
    root = insert ( root , 13 )
    inorder ( root )

Class/struct names: newNode
Python program:
MAX = 1000
def checkHV ( arr , N , M ) :
    horizontal = True
    vertical = True
    i = 0
    k = N - 1
    while ( i < N // 2 ) :
        for j in range ( M ) :
            if ( arr [ i ] [ j ] != arr [ k ] [ j ] ) :
                horizontal = False
                break
        i += 1
        k -= 1
    i = 0
    k = M - 1
    while ( i < M // 2 ) :
        for j in range ( N ) :
            if ( arr [ i ] [ j ] != arr [ k ] [ j ] ) :
                vertical = False
                break
        i += 1
        k -= 1
    if ( not horizontal and not vertical ) :
        print ( " NO " )
    elif ( horizontal and not vertical ) :
        print ( " HORIZONTAL " )
    elif ( vertical and not horizontal ) :
        print ( " VERTICAL " )
    else :
        print ( " BOTH " )
mat = [ [ 1 , 0 , 1 ] , [ 0 , 0 , 0 ] , [ 1 , 0 , 1 ] ]
checkHV ( mat , 3 , 3 )

Index/key variables: i, j, k
Iterator variables: j
Boolean variables: horizontal, vertical
Python program:
R = 3
C = 4
def gcd ( a , b ) :
    if ( b == 0 ) :
        return a
    return gcd ( b , a % b )
def replacematrix ( mat , n , m ) :
    rgcd = [ 0 ] * R
    cgcd = [ 0 ] * C
    for i in range ( n ) :
        for j in range ( m ) :
            rgcd [ i ] = gcd ( rgcd [ i ] , mat [ i ] [ j ] )
            cgcd [ j ] = gcd ( cgcd [ j ] , mat [ i ] [ j ] )
    for i in range ( n ) :
        for j in range ( m ) :
            mat [ i ] [ j ] = max ( rgcd [ i ] , cgcd [ j ] )
if __name__ == " _ _ main _ _ " :
    m = [ [ 1 , 2 , 3 , 3 ] , [ 4 , 5 , 6 , 6 ] , [ 7 , 8 , 9 , 9 ] ]
    replacematrix ( m , R , C )
    for i in range ( R ) :
        for j in range ( C ) :
            print ( m [ i ] [ j ] , end = " ▁ " )
        print ( )

Index/key variables: i, j
Iterator variables: i, j
Python program:
N = 4
def add ( A , B , C ) :
    for i in range ( N ) :
        for j in range ( N ) :
            C [ i ] [ j ] = A [ i ] [ j ] + B [ i ] [ j ]
A = [ [ 1 , 1 , 1 , 1 ] , [ 2 , 2 , 2 , 2 ] , [ 3 , 3 , 3 , 3 ] , [ 4 , 4 , 4 , 4 ] ]
B = [ [ 1 , 1 , 1 , 1 ] , [ 2 , 2 , 2 , 2 ] , [ 3 , 3 , 3 , 3 ] , [ 4 , 4 , 4 , 4 ] ]
C = A [ : ] [ : ]
add ( A , B , C )
print ( " Result ▁ matrix ▁ is " )
for i in range ( N ) :
    for j in range ( N ) :
        print ( C [ i ] [ j ] , " ▁ " , end = ' ' )
    print ( )

Index/key variables: i, j
Iterator variables: i, j
Python program:
N = 4
def subtract ( A , B , C ) :
    for i in range ( N ) :
        for j in range ( N ) :
            C [ i ] [ j ] = A [ i ] [ j ] - B [ i ] [ j ]
A = [ [ 1 , 1 , 1 , 1 ] , [ 2 , 2 , 2 , 2 ] , [ 3 , 3 , 3 , 3 ] , [ 4 , 4 , 4 , 4 ] ]
B = [ [ 1 , 1 , 1 , 1 ] , [ 2 , 2 , 2 , 2 ] , [ 3 , 3 , 3 , 3 ] , [ 4 , 4 , 4 , 4 ] ]
C = A [ : ] [ : ]
subtract ( A , B , C )
print ( " Result ▁ matrix ▁ is " )
for i in range ( N ) :
    for j in range ( N ) :
        print ( C [ i ] [ j ] , " ▁ " , end = ' ' )
    print ( )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def linearSearch ( arr , n ) :
    for i in range ( n ) :
        if arr [ i ] is i :
            return i
    return - 1
arr = [ - 10 , - 1 , 0 , 3 , 10 , 11 , 30 , 50 , 100 ]
n = len ( arr )
print ( " Fixed ▁ Point ▁ is ▁ " + str ( linearSearch ( arr , n ) ) )

Index/key variables: i
Iterator variables: i
Python program:
def binarySearch ( arr , low , high ) :
    if high >= low :
        mid = ( low + high ) // 2
    if mid is arr [ mid ] :
        return mid
    if mid > arr [ mid ] :
        return binarySearch ( arr , ( mid + 1 ) , high )
    else :
        return binarySearch ( arr , low , ( mid - 1 ) )
    return - 1
arr = [ - 10 , - 1 , 0 , 3 , 10 , 11 , 30 , 50 , 100 ]
n = len ( arr )
print ( " Fixed ▁ Point ▁ is ▁ " + str ( binarySearch ( arr , 0 , n - 1 ) ) )

Index/key variables: mid
Python program:
def maxTripletSum ( arr , n ) :
    sm = - 1000000
    for i in range ( 0 , n ) :
        for j in range ( i + 1 , n ) :
            for k in range ( j + 1 , n ) :
                if ( sm < ( arr [ i ] + arr [ j ] + arr [ k ] ) ) :
                    sm = arr [ i ] + arr [ j ] + arr [ k ]
    return sm
arr = [ 1 , 0 , 8 , 6 , 4 , 2 ]
n = len ( arr )
print ( maxTripletSum ( arr , n ) )

Index/key variables: i, j, k
Iterator variables: i, j, k
Python program:
def maxTripletSum ( arr , n ) :
    maxA = - 100000000
    maxB = - 100000000
    maxC = - 100000000
    for i in range ( 0 , n ) :
        if ( arr [ i ] > maxA ) :
            maxC = maxB
            maxB = maxA
            maxA = arr [ i ]
        elif ( arr [ i ] > maxB ) :
            maxC = maxB
            maxB = arr [ i ]
        elif ( arr [ i ] > maxC ) :
            maxC = arr [ i ]
    return ( maxA + maxB + maxC )
arr = [ 1 , 0 , 8 , 6 , 4 , 2 ]
n = len ( arr )
print ( maxTripletSum ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def search ( arr , n , x ) :
    for i in range ( 0 , n ) :
        if ( arr [ i ] == x ) :
            return i
    return - 1
arr = [ 2 , 3 , 4 , 10 , 40 ]
x = 10
n = len ( arr )
result = search ( arr , n , x )
if ( result == - 1 ) :
    print ( " Element ▁ is ▁ not ▁ present ▁ in ▁ array " )
else :
    print ( " Element ▁ is ▁ present ▁ at ▁ index " , result )

Index/key variables: i
Iterator variables: i
Python program:
def search ( arr , search_Element ) :
    left = 0
    length = len ( arr )
    position = - 1
    right = length - 1
    for left in range ( 0 , right , 1 ) :
        if ( arr [ left ] == search_Element ) :
            position = left
            print ( " Element ▁ found ▁ in ▁ Array ▁ at ▁ " , position + 1 , " ▁ Position ▁ with ▁ " , left + 1 , " ▁ Attempt " )
            break
        if ( arr [ right ] == search_Element ) :
            position = right
            print ( " Element ▁ found ▁ in ▁ Array ▁ at ▁ " , position + 1 , " ▁ Position ▁ with ▁ " , length - right , " ▁ Attempt " )
            break
        left += 1
        right -= 1
    if ( position == - 1 ) :
        print ( " Not ▁ found ▁ in ▁ Array ▁ with ▁ " , left , " ▁ Attempt " )
arr = [ 1 , 2 , 3 , 4 , 5 ]
search_element = 5
search ( arr , search_element )

Index/key variables: left, right
Iterator variables: left
Python program:
def countSort ( arr ) :
    output = [ 0 for i in range ( len ( arr ) ) ]
    count = [ 0 for i in range ( 256 ) ]
    for i in arr :
        count [ ord ( i ) ] += 1
    for i in range ( 256 ) :
        count [ i ] += count [ i - 1 ]
    for i in range ( len ( arr ) ) :
        output [ count [ ord ( arr [ i ] ) ] - 1 ] = arr [ i ]
        count [ ord ( arr [ i ] ) ] -= 1
    ans = [ " " for _ in arr ]
    for i in range ( len ( arr ) ) :
        ans [ i ] = output [ i ]
    return ans
arr = " geeksforgeeks "
ans = countSort ( arr )
print ( " Sorted ▁ character ▁ array ▁ is ▁ % ▁ s " % ( " " . join ( ans ) ) )

Index/key variables: i
Iterator variables: i
Python program:
def count_sort ( arr ) :
    max_element = int ( max ( arr ) )
    min_element = int ( min ( arr ) )
    range_of_elements = max_element - min_element + 1
    count_arr = [ 0 for _ in range ( range_of_elements ) ]
    output_arr = [ 0 for _ in range ( len ( arr ) ) ]
    for i in range ( 0 , len ( arr ) ) :
        count_arr [ arr [ i ] - min_element ] += 1
    for i in range ( 1 , len ( count_arr ) ) :
        count_arr [ i ] += count_arr [ i - 1 ]
    for i in range ( len ( arr ) - 1 , - 1 , - 1 ) :
        output_arr [ count_arr [ arr [ i ] - min_element ] - 1 ] = arr [ i ]
        count_arr [ arr [ i ] - min_element ] -= 1
    for i in range ( 0 , len ( arr ) ) :
        arr [ i ] = output_arr [ i ]
    return arr
arr = [ - 5 , - 10 , 0 , - 3 , 8 , 5 , - 1 , 10 ]
ans = count_sort ( arr )
print ( " Sorted ▁ character ▁ array ▁ is ▁ " + str ( ans ) )

Index/key variables: i
Iterator variables: i
Python program:
import math
class GFG :
    def nCr ( self , n , r ) :
        if r > n :
            return 0
        if n - r > r :
            r = n - r
        SPF = [ i for i in range ( n + 1 ) ]
        for i in range ( 4 , n + 1 , 2 ) :
            SPF [ i ] = 2
        for i in range ( 3 , n + 1 , 2 ) :
            if i * i > n :
                break
            if SPF [ i ] == i :
                for j in range ( i * i , n + 1 , i ) :
                    if SPF [ j ] == j :
                        SPF [ j ] = i
        prime_pow = { }
        for i in range ( r + 1 , n + 1 ) :
            t = i
            while t > 1 :
                if not SPF [ t ] in prime_pow :
                    prime_pow [ SPF [ t ] ] = 1
                else :
                    prime_pow [ SPF [ t ] ] += 1
                t //= SPF [ t ]
        for i in range ( 1 , n - r + 1 ) :
            t = i
            while t > 1 :
                prime_pow [ SPF [ t ] ] -= 1
                t //= SPF [ t ]
        ans = 1
        mod = 10 ** 9 + 7
        for i in prime_pow :
            ans = ( ans * pow ( i , prime_pow [ i ] , mod ) ) % mod
        return ans
n = 5
k = 2
ob = GFG ( )
print ( " Value ▁ of ▁ C ( " + str ( n ) + " , ▁ " + str ( k ) + " ) ▁ is " , ob . nCr ( n , k ) )

Index/key variables: i, j, t
Iterator variables: i, j
Class/struct names: GFG
Python program:
def binomialCoeff ( n , r ) :
    if ( r > n ) :
        return 0
    m = 1000000007
    inv = [ 0 for i in range ( r + 1 ) ]
    inv [ 0 ] = 1
    if ( r + 1 >= 2 ) :
        inv [ 1 ] = 1
    for i in range ( 2 , r + 1 ) :
        inv [ i ] = m - ( m // i ) * inv [ m % i ] % m
    ans = 1
    for i in range ( 2 , r + 1 ) :
        ans = ( ( ans % m ) * ( inv [ i ] % m ) ) % m
    for i in range ( n , n - r , - 1 ) :
        ans = ( ( ans % m ) * ( i % m ) ) % m
    return ans
n = 5
r = 2
print ( " Value ▁ of ▁ C ( " , n , " , ▁ " , r , " ) ▁ is ▁ " , binomialCoeff ( n , r ) )

Index/key variables: i
Iterator variables: i
Python program:
def findPartiion ( arr , n ) :
    Sum = 0
    for i in range ( n ) :
        Sum += arr [ i ]
    if ( Sum % 2 != 0 ) :
        return 0
    part = [ 0 ] * ( ( Sum // 2 ) + 1 )
    for i in range ( ( Sum // 2 ) + 1 ) :
        part [ i ] = 0
    for i in range ( n ) :
        for j in range ( Sum // 2 , arr [ i ] - 1 , - 1 ) :
            if ( part [ j - arr [ i ] ] == 1 or j == arr [ i ] ) :
                part [ j ] = 1
    return part [ Sum // 2 ]
arr = [ 1 , 3 , 3 , 2 , 3 , 2 ]
n = len ( arr )
if ( findPartiion ( arr , n ) == 1 ) :
    print ( " Can ▁ be ▁ divided ▁ into ▁ two ▁ subsets ▁ of ▁ equal ▁ sum " )
else :
    print ( " Can ▁ not ▁ be ▁ divided ▁ into ▁ two ▁ subsets ▁ of ▁ equal ▁ sum " )

Index/key variables: i, j
Accumulator variables: Sum
Iterator variables: i, j
Python program:
def isSubsetSum ( set , n , sum ) :
    subset = ( [ [ False for i in range ( sum + 1 ) ] for i in range ( n + 1 ) ] )
    for i in range ( n + 1 ) :
        subset [ i ] [ 0 ] = True
    for i in range ( 1 , sum + 1 ) :
        subset [ 0 ] [ i ] = False
    for i in range ( 1 , n + 1 ) :
        for j in range ( 1 , sum + 1 ) :
            if j < set [ i - 1 ] :
                subset [ i ] [ j ] = subset [ i - 1 ] [ j ]
            if j >= set [ i - 1 ] :
                subset [ i ] [ j ] = ( subset [ i - 1 ] [ j ] or subset [ i - 1 ] [ j - set [ i - 1 ] ] )
    for i in range ( n + 1 ) :
        for j in range ( sum + 1 ) :
            print ( subset [ i ] [ j ] , end = " ▁ " )
            print ( )
    return subset [ n ] [ sum ]
if __name__ == ' _ _ main _ _ ' :
    set = [ 3 , 34 , 4 , 12 , 5 , 2 ]
    sum = 9
    n = len ( set )
    if ( isSubsetSum ( set , n , sum ) == True ) :
        print ( " Found ▁ a ▁ subset ▁ with ▁ given ▁ sum " )
    else :
        print ( " No ▁ subset ▁ with ▁ given ▁ sum " )

Index/key variables: i, j, n, sum
Iterator variables: i, j
Python program:
def findoptimal ( N ) :
    if N <= 6 :
        return N
    maxi = 0
    for b in range ( N - 3 , 0 , - 1 ) :
        curr = ( N - b - 1 ) * findoptimal ( b )
        if curr > maxi :
            maxi = curr
    return maxi
if __name__ == ' _ _ main _ _ ' :
    for n in range ( 1 , 21 ) :
        print ( ' Maximum ▁ Number ▁ of ▁ As ▁ with ▁ ' , n , ' keystrokes ▁ is ▁ ' , findoptimal ( n ) )

Iterator variables: b, n
Python program:
def findoptimal ( N ) :
    if ( N <= 6 ) :
        return N
    screen = [ 0 ] * N
    for n in range ( 1 , 7 ) :
        screen [ n - 1 ] = n
    for n in range ( 7 , N + 1 ) :
        screen [ n - 1 ] = 0
        for b in range ( n - 3 , 0 , - 1 ) :
            curr = ( n - b - 1 ) * screen [ b - 1 ]
            if ( curr > screen [ n - 1 ] ) :
                screen [ n - 1 ] = curr
    return screen [ N - 1 ]
if __name__ == " _ _ main _ _ " :
    for N in range ( 1 , 21 ) :
        print ( " Maximum ▁ Number ▁ of ▁ A ' s ▁ with ▁ " , N , " ▁ keystrokes ▁ is ▁ " , findoptimal ( N ) )

Iterator variables: N, b, n
Python program:
def findoptimal ( N ) :
    if ( N <= 6 ) :
        return N
    screen = [ 0 ] * N
    for n in range ( 1 , 7 ) :
        screen [ n - 1 ] = n
    for n in range ( 7 , N + 1 ) :
        screen [ n - 1 ] = max ( 2 * screen [ n - 4 ] , max ( 3 * screen [ n - 5 ] , 4 * screen [ n - 6 ] ) ) ;
    return screen [ N - 1 ]
if __name__ == " _ _ main _ _ " :
    for N in range ( 1 , 21 ) :
        print ( " Maximum ▁ Number ▁ of ▁ A ' s ▁ with ▁ " , N , " ▁ keystrokes ▁ is ▁ " , findoptimal ( N ) )

Iterator variables: N, n
Python program:
def getAvg ( prev_avg , x , n ) :
    return ( ( prev_avg * n + x ) / ( n + 1 ) ) ;
def streamAvg ( arr , n ) :
    avg = 0 ;
    for i in range ( n ) :
        avg = getAvg ( avg , arr [ i ] , i ) ;
        print ( " Average ▁ of ▁ " , i + 1 , " ▁ numbers ▁ is ▁ " , avg ) ;
arr = [ 10 , 20 , 30 , 40 , 50 , 60 ] ;
n = len ( arr ) ;
streamAvg ( arr , n ) ;

Index/key variables: i
Iterator variables: i
Python program:
def getAvg ( x , n , sum ) :
    sum = sum + x ;
    return float ( sum ) / n ;
def streamAvg ( arr , n ) :
    avg = 0 ;
    sum = 0 ;
    for i in range ( n ) :
        avg = getAvg ( arr [ i ] , i + 1 , sum ) ;
        sum = avg * ( i + 1 ) ;
        print ( " Average ▁ of ▁ " , end = " " ) ;
        print ( i + 1 , end = " " ) ;
        print ( " ▁ numbers ▁ is ▁ " , end = " " ) ;
        print ( avg ) ;
    return ;
arr = [ 10 , 20 , 30 , 40 , 50 , 60 ] ;
n = len ( arr ) ;
streamAvg ( arr , n ) ;

Index/key variables: i
Iterator variables: i
Python program:
def binomialCoefficient ( n , k ) :
    res = 1
    if ( k > n - k ) :
        k = n - k
    for i in range ( k ) :
        res = res * ( n - i )
        res = res / ( i + 1 )
    return res
n = 8
k = 2
res = binomialCoefficient ( n , k )
print ( " Value ▁ of ▁ C ( % ▁ d , ▁ % ▁ d ) ▁ is ▁ % ▁ d " % ( n , k , res ) )

Iterator variables: i
Python program:
def printCombination ( arr , n , r ) :
    data = [ 0 ] * r ;
    combinationUtil ( arr , data , 0 , n - 1 , 0 , r ) ;
def combinationUtil ( arr , data , start , end , index , r ) :
    if ( index == r ) :
        for j in range ( r ) :
            print ( data [ j ] , end = " ▁ " ) ;
        print ( ) ;
        return ;
    i = start ;
    while ( i <= end and end - i + 1 >= r - index ) :
        data [ index ] = arr [ i ] ;
        combinationUtil ( arr , data , i + 1 , end , index + 1 , r ) ;
        i += 1 ;
arr = [ 1 , 2 , 3 , 4 , 5 ] ;
r = 3 ;
n = len ( arr ) ;
printCombination ( arr , n , r ) ;

Index/key variables: i, index, j
Iterator variables: j
Python program:
def printCombination ( arr , n , r ) :
    data = [ 0 ] * r
    combinationUtil ( arr , n , r , 0 , data , 0 )
def combinationUtil ( arr , n , r , index , data , i ) :
    if ( index == r ) :
        for j in range ( r ) :
            print ( data [ j ] , end = " ▁ " )
        print ( )
        return
    if ( i >= n ) :
        return
    data [ index ] = arr [ i ]
    combinationUtil ( arr , n , r , index + 1 , data , i + 1 )
    combinationUtil ( arr , n , r , index , data , i + 1 )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 4 , 5 ]
    r = 3
    n = len ( arr )
    printCombination ( arr , n , r )

Index/key variables: i, index, j
Iterator variables: j
Python program:
def findgroups ( arr , n ) :
    c = [ 0 , 0 , 0 ]
    res = 0
    for i in range ( 0 , n ) :
        c [ arr [ i ] % 3 ] += 1
    res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 )
    res += c [ 1 ] * c [ 2 ]
    res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) / 6
    res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) / 6
    res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) / 6 )
    res += c [ 0 ] * c [ 1 ] * c [ 2 ]
    return res
arr = [ 3 , 6 , 7 , 2 , 9 ]
n = len ( arr )
print ( " Required ▁ number ▁ of ▁ groups ▁ are " , int ( findgroups ( arr , n ) ) )

Index/key variables: i
Iterator variables: i
Python program:
def nextPowerOf2 ( n ) :
    count = 0 ;
    if ( n and not ( n & ( n - 1 ) ) ) :
        return n
    while ( n != 0 ) :
        n >>= 1
        count += 1
    return 1 << count ;
n = 0
print ( nextPowerOf2 ( n ) )

Accumulator variables: count, n
Python program:
def nextPowerOf2 ( n ) :
    p = 1
    if ( n and not ( n & ( n - 1 ) ) ) :
        return n
    while ( p < n ) :
        p <<= 1
    return p ;
n = 5
print ( nextPowerOf2 ( n ) ) ;

Accumulator variables: p
Python program:
def segregate0and1 ( arr , n ) :
    count = 0
    for i in range ( 0 , n ) :
        if ( arr [ i ] == 0 ) :
            count = count + 1
    for i in range ( 0 , count ) :
        arr [ i ] = 0
    for i in range ( count , n ) :
        arr [ i ] = 1
def print_arr ( arr , n ) :
    print ( " Array ▁ after ▁ segregation ▁ is ▁ " , end = " " )
    for i in range ( 0 , n ) :
        print ( arr [ i ] , end = " ▁ " )
arr = [ 0 , 1 , 0 , 1 , 1 , 1 ]
n = len ( arr )
segregate0and1 ( arr , n )
print_arr ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
def segregate0and1 ( arr , size ) :
    left , right = 0 , size - 1
    while left < right :
        while arr [ left ] == 0 and left < right :
            left += 1
        while arr [ right ] == 1 and left < right :
            right -= 1
        if left < right :
            arr [ left ] = 0
            arr [ right ] = 1
            left += 1
            right -= 1
    return arr
arr = [ 0 , 1 , 0 , 1 , 1 , 1 ]
arr_size = len ( arr )
print ( " Array ▁ after ▁ segregation " )
print ( segregate0and1 ( arr , arr_size ) )

Index/key variables: left, right
Python program:
def segregate0and1 ( arr , size ) :
    type0 = 0
    type1 = size - 1
    while ( type0 < type1 ) :
        if ( arr [ type0 ] == 1 ) :
            ( arr [ type0 ] , arr [ type1 ] ) = ( arr [ type1 ] , arr [ type0 ] )
            type1 -= 1
        else :
            type0 += 1
arr = [ 0 , 1 , 0 , 1 , 1 , 1 ]
arr_size = len ( arr )
segregate0and1 ( arr , arr_size )
print ( " Array ▁ after ▁ segregation ▁ is " , end = " ▁ " )
for i in range ( 0 , arr_size ) :
    print ( arr [ i ] , end = " ▁ " )

Index/key variables: i, type0, type1
Iterator variables: i
Python program:
def distantAdjacentElement ( a , n ) :
    m = dict ( )
    for i in range ( n ) :
        if a [ i ] in m :
            m [ a [ i ] ] += 1
        else :
            m [ a [ i ] ] = 1
    mx = 0
    for i in range ( n ) :
        if mx < m [ a [ i ] ] :
            mx = m [ a [ i ] ]
    if mx > ( n + 1 ) // 2 :
        print ( " NO " )
    else :
        print ( " YES " )
if __name__ == " _ _ main _ _ " :
    a = [ 7 , 7 , 7 , 7 ]
    n = len ( a )
    distantAdjacentElement ( a , n )

Index/key variables: i
Iterator variables: i
Python program:
def maxIndexDiff ( arr , n ) :
    maxDiff = - 1
    for i in range ( 0 , n ) :
        j = n - 1
        while ( j > i ) :
            if arr [ j ] > arr [ i ] and maxDiff < ( j - i ) :
                maxDiff = j - i
            j -= 1
    return maxDiff
arr = [ 9 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 18 , 0 ]
n = len ( arr )
maxDiff = maxIndexDiff ( arr , n )
print ( maxDiff )

Index/key variables: i, j
Iterator variables: i
Python program:
if __name__ == ' _ _ main _ _ ' :
    v = [ 34 , 8 , 10 , 3 , 2 , 80 , 30 , 33 , 1 ] ;
    n = len ( v ) ;
    maxFromEnd = [ - 38749432 ] * ( n + 1 ) ;
    for i in range ( n - 1 , 0 , - 1 ) :
        maxFromEnd [ i ] = max ( maxFromEnd [ i + 1 ] , v [ i ] ) ;
    result = 0 ;
    for i in range ( 0 , n ) :
        low = i + 1 ; high = n - 1 ; ans = i ;
        while ( low <= high ) :
            mid = int ( ( low + high ) / 2 ) ;
            if ( v [ i ] <= maxFromEnd [ mid ] ) :
                ans = max ( ans , mid ) ;
                low = mid + 1 ;
            else :
                high = mid - 1 ;
        result = max ( result , ans - i ) ;
    print ( result , end = " " ) ;

Index/key variables: i, mid
Iterator variables: i
Python program:
def printRepeating ( arr , size ) :
    s = set ( )
    for i in range ( size ) :
        if arr [ i ] not in s :
            s . add ( arr [ i ] )
    for i in s :
        print ( i , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 3 , 2 , 2 , 1 ]
    size = len ( arr )
    printRepeating ( arr , size )

Index/key variables: i
Accumulator variables: s
Iterator variables: i