dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def isPowerOfTwo ( n ) :
    return ( n and ( not ( n & ( n - 1 ) ) ) )
def findPosition ( n ) :
    if not isPowerOfTwo ( n ) :
        return - 1
    count = 0
    while ( n ) :
        n = n >> 1
        count += 1
    return count
if __name__ == " _ _ main _ _ " :
    n = 0
    pos = findPosition ( n )
    if pos == - 1 :
        print ( " n ▁ = " , n , " Invalid ▁ number " )
    else :
        print ( " n ▁ = " , n , " Position " , pos )
    n = 12
    pos = findPosition ( n )
    if pos == - 1 :
        print ( " n ▁ = " , n , " Invalid ▁ number " )
    else :
        print ( " n ▁ = " , n , " Position " , pos )
    n = 128
    pos = findPosition ( n )
    if pos == - 1 :
        print ( " n ▁ = " , n , " Invalid ▁ number " )
    else :
        print ( " n ▁ = " , n , " Position " , pos )

Accumulator variables: count
Python program:
N = 8
def printSolution ( board ) :
    for i in range ( N ) :
        for j in range ( N ) :
            print ( board [ i ] [ j ] , end = " ▁ " )
        print ( )
def isSafe ( row , col , slashCode , backslashCode , rowLookup , slashCodeLookup , backslashCodeLookup ) :
    if ( slashCodeLookup [ slashCode [ row ] [ col ] ] or backslashCodeLookup [ backslashCode [ row ] [ col ] ] or rowLookup [ row ] ) :
        return False
    return True
def solveNQueensUtil ( board , col , slashCode , backslashCode , rowLookup , slashCodeLookup , backslashCodeLookup ) :
    if ( col >= N ) :
        return True
    for i in range ( N ) :
        if ( isSafe ( i , col , slashCode , backslashCode , rowLookup , slashCodeLookup , backslashCodeLookup ) ) :
            board [ i ] [ col ] = 1
            rowLookup [ i ] = True
            slashCodeLookup [ slashCode [ i ] [ col ] ] = True
            backslashCodeLookup [ backslashCode [ i ] [ col ] ] = True
            if ( solveNQueensUtil ( board , col + 1 , slashCode , backslashCode , rowLookup , slashCodeLookup , backslashCodeLookup ) ) :
                return True
            board [ i ] [ col ] = 0
            rowLookup [ i ] = False
            slashCodeLookup [ slashCode [ i ] [ col ] ] = False
            backslashCodeLookup [ backslashCode [ i ] [ col ] ] = False
    return False
def solveNQueens ( ) :
    board = [ [ 0 for i in range ( N ) ] for j in range ( N ) ]
    slashCode = [ [ 0 for i in range ( N ) ] for j in range ( N ) ]
    backslashCode = [ [ 0 for i in range ( N ) ] for j in range ( N ) ]
    rowLookup = [ False ] * N
    x = 2 * N - 1
    slashCodeLookup = [ False ] * x
    backslashCodeLookup = [ False ] * x
    for rr in range ( N ) :
        for cc in range ( N ) :
            slashCode [ rr ] [ cc ] = rr + cc
            backslashCode [ rr ] [ cc ] = rr - cc + 7
    if ( solveNQueensUtil ( board , 0 , slashCode , backslashCode , rowLookup , slashCodeLookup , backslashCodeLookup ) == False ) :
        print ( " Solution ▁ does ▁ not ▁ exist " )
        return False
    printSolution ( board )
    return True
solveNQueens ( )

Index/key variables: cc, col, i, j, row, rr
Iterator variables: cc, i, j, rr
Python program:
def maxOnesIndex ( arr , n ) :
    max_count = 0
    max_index = 0
    prev_zero = - 1
    prev_prev_zero = - 1
    for curr in range ( n ) :
        if ( arr [ curr ] == 0 ) :
            if ( curr - prev_prev_zero > max_count ) :
                max_count = curr - prev_prev_zero
                max_index = prev_zero
            prev_prev_zero = prev_zero
            prev_zero = curr
    if ( n - prev_prev_zero > max_count ) :
        max_index = prev_zero
    return max_index
arr = [ 1 , 1 , 0 , 0 , 1 , 0 , 1 , 1 , 1 , 0 , 1 , 1 , 1 ]
n = len ( arr )
print ( " Index ▁ of ▁ 0 ▁ to ▁ be ▁ replaced ▁ is ▁ " , maxOnesIndex ( arr , n ) )

Index/key variables: curr
Iterator variables: curr
Python program:
def min ( x , y ) :
    return x if ( x < y ) else y
def max ( x , y ) :
    return x if ( x > y ) else y
def findLength ( arr , n ) :
    max_len = 1
    for i in range ( n - 1 ) :
        mn = arr [ i ]
        mx = arr [ i ]
        for j in range ( i + 1 , n ) :
            mn = min ( mn , arr [ j ] )
            mx = max ( mx , arr [ j ] )
            if ( ( mx - mn ) == j - i ) :
                max_len = max ( max_len , mx - mn + 1 )
    return max_len
arr = [ 1 , 56 , 58 , 57 , 90 , 92 , 94 , 93 , 91 , 45 ]
n = len ( arr )
print ( " Length ▁ of ▁ the ▁ longest ▁ contiguous ▁ subarray ▁ is ▁ " , findLength ( arr , n ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def printArr ( arr , k ) :
    for i in range ( k ) :
        print ( arr [ i ] , end = " ▁ " ) ;
    print ( ) ;
def printSeqUtil ( n , k , len1 , arr ) :
    if ( len1 == k ) :
        printArr ( arr , k ) ;
        return ;
    i = 1 if ( len1 == 0 ) else ( arr [ len1 - 1 ] + 1 ) ;
    len1 += 1 ;
    while ( i <= n ) :
        arr [ len1 - 1 ] = i ;
        printSeqUtil ( n , k , len1 , arr ) ;
        i += 1 ;
    len1 -= 1 ;
def printSeq ( n , k ) :
    arr = [ 0 ] * k ;
    len1 = 0 ;
    printSeqUtil ( n , k , len1 , arr ) ;
k = 3 ;
n = 7 ;
printSeq ( n , k ) ;

Index/key variables: i
Iterator variables: i
Python program:
def maxSubarrayProduct ( arr , n ) :
    result = arr [ 0 ]
    for i in range ( n ) :
        mul = arr [ i ]
        for j in range ( i + 1 , n ) :
            result = max ( result , mul )
            mul *= arr [ j ]
        result = max ( result , mul )
    return result
arr = [ 1 , - 2 , - 3 , 0 , 7 , - 8 , - 2 ]
n = len ( arr )
print ( " Maximum ▁ Sub ▁ array ▁ product ▁ is " , maxSubarrayProduct ( arr , n ) )

Index/key variables: i, j
Accumulator variables: mul
Iterator variables: i, j
Python program:
def maxCircularSum ( a , n ) :
    if ( n == 1 ) :
        return a [ 0 ]
    sum = 0
    for i in range ( n ) :
        sum += a [ i ]
    curr_max = a [ 0 ]
    max_so_far = a [ 0 ]
    curr_min = a [ 0 ]
    min_so_far = a [ 0 ]
    for i in range ( 1 , n ) :
        curr_max = max ( curr_max + a [ i ] , a [ i ] )
        max_so_far = max ( max_so_far , curr_max )
        curr_min = min ( curr_min + a [ i ] , a [ i ] )
        min_so_far = min ( min_so_far , curr_min )
    if ( min_so_far == sum ) :
        return max_so_far
    return max ( max_so_far , sum - min_so_far )
a = [ 11 , 10 , - 20 , 5 , - 3 , - 5 , 8 , - 13 , 10 ]
n = len ( a )
print ( " Maximum ▁ circular ▁ sum ▁ is " , maxCircularSum ( a , n ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def GetCeilIndex ( arr , T , l , r , key ) :
    while ( r - l > 1 ) :
        m = l + ( r - l ) // 2
        if ( arr [ T [ m ] ] >= key ) :
            r = m
        else :
            l = m
    return r
def LongestIncreasingSubsequence ( arr , n ) :
    tailIndices = [ 0 for i in range ( n + 1 ) ]
    prevIndices = [ - 1 for i in range ( n + 1 ) ]
    len = 1
    for i in range ( 1 , n ) :
        if ( arr [ i ] < arr [ tailIndices [ 0 ] ] ) :
            tailIndices [ 0 ] = i
        elif ( arr [ i ] > arr [ tailIndices [ len - 1 ] ] ) :
            prevIndices [ i ] = tailIndices [ len - 1 ]
            tailIndices [ len ] = i
            len += 1
        else :
            pos = GetCeilIndex ( arr , tailIndices , - 1 , len - 1 , arr [ i ] )
            prevIndices [ i ] = tailIndices [ pos - 1 ]
            tailIndices [ pos ] = i
    print ( " LIS ▁ of ▁ given ▁ input " )
    i = tailIndices [ len - 1 ]
    while ( i >= 0 ) :
        print ( arr [ i ] , " ▁ " , end = " " )
        i = prevIndices [ i ]
    print ( )
    return len
arr = [ 2 , 5 , 3 , 7 , 11 , 8 , 10 , 13 , 6 ]
n = len ( arr )
print ( " LIS size " , LongestIncreasingSubsequence ( arr , n ) )

Index/key variables: i, len, m, pos
Iterator variables: i
Python program:
def maxSum ( arr , n ) :
    sum = 0
    arr . sort ( )
    for i in range ( 0 , int ( n / 2 ) ) :
        sum -= ( 2 * arr [ i ] )
        sum += ( 2 * arr [ n - i - 1 ] )
    return sum
arr = [ 4 , 2 , 1 , 8 ]
n = len ( arr )
print ( maxSum ( arr , n ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def threeWayPartition ( arr , n , lowVal , highVal ) :
    start = 0
    end = n - 1
    i = 0
    while i <= end :
        if arr [ i ] < lowVal :
            temp = arr [ i ]
            arr [ i ] = arr [ start ]
            arr [ start ] = temp
            i += 1
            start += 1
        elif arr [ i ] > highVal :
            temp = arr [ i ]
            arr [ i ] = arr [ end ]
            arr [ end ] = temp
            end -= 1
        else :
            i += 1
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 14 , 5 , 20 , 4 , 2 , 54 , 20 , 87 , 98 , 3 , 1 , 32 ]
    n = len ( arr )
    threeWayPartition ( arr , n , 10 , 20 )
    print ( " Modified ▁ array " )
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " )

Index/key variables: end, i, start
Iterator variables: i
Python program:
def generateUtil ( A , B , C , i , j , m , n , len , flag ) :
    if ( flag ) :
        if ( len ) :
            printArr ( C , len + 1 )
        for k in range ( i , m ) :
            if ( not len ) :
                C [ len ] = A [ k ]
                generateUtil ( A , B , C , k + 1 , j , m , n , len , not flag )
            else :
                if ( A [ k ] > C [ len ] ) :
                    C [ len + 1 ] = A [ k ]
                    generateUtil ( A , B , C , k + 1 , j , m , n , len + 1 , not flag )
    else :
        for l in range ( j , n ) :
            if ( B [ l ] > C [ len ] ) :
                C [ len + 1 ] = B [ l ]
                generateUtil ( A , B , C , i , l + 1 , m , n , len + 1 , not flag )
def generate ( A , B , m , n ) :
    C = [ ]
    for i in range ( m + n + 1 ) :
        C . append ( 0 )
    generateUtil ( A , B , C , 0 , 0 , m , n , 0 , True )
def printArr ( arr , n ) :
    for i in range ( n ) :
        print ( arr [ i ] , " ▁ " , end = " " )
    print ( )
A = [ 10 , 15 , 25 ]
B = [ 5 , 20 , 30 ]
n = len ( A )
m = len ( B )
generate ( A , B , n , m )

Index/key variables: i, k, l, len
Accumulator variables: C
Iterator variables: i, k, l
Python program:
def updateindex ( index , a , ai , b , bi ) :
    index [ a ] = ai
    index [ b ] = bi
def minSwapsUtil ( arr , pairs , index , i , n ) :
    if ( i > n ) :
        return 0
    if ( pairs [ arr [ i ] ] == arr [ i + 1 ] ) :
        return minSwapsUtil ( arr , pairs , index , i + 2 , n )
    one = arr [ i + 1 ]
    indextwo = i + 1
    indexone = index [ pairs [ arr [ i ] ] ]
    two = arr [ index [ pairs [ arr [ i ] ] ] ]
    arr [ i + 1 ] , arr [ indexone ] = arr [ indexone ] , arr [ i + 1 ]
    updateindex ( index , one , indexone , two , indextwo )
    a = minSwapsUtil ( arr , pairs , index , i + 2 , n )
    arr [ i + 1 ] , arr [ indexone ] = arr [ indexone ] , arr [ i + 1 ]
    updateindex ( index , one , indextwo , two , indexone )
    one = arr [ i ]
    indexone = index [ pairs [ arr [ i + 1 ] ] ]
    two = arr [ index [ pairs [ arr [ i + 1 ] ] ] ]
    indextwo = i
    arr [ i ] , arr [ indexone ] = arr [ indexone ] , arr [ i ]
    updateindex ( index , one , indexone , two , indextwo )
    b = minSwapsUtil ( arr , pairs , index , i + 2 , n )
    arr [ i ] , arr [ indexone ] = arr [ indexone ] , arr [ i ]
    updateindex ( index , one , indextwo , two , indexone )
    return 1 + min ( a , b )
def minSwaps ( n , pairs , arr ) :
    index = [ ]
    for i in range ( 2 * n + 1 + 1 ) :
        index . append ( 0 )
    for i in range ( 1 , 2 * n + 1 ) :
        index [ arr [ i ] ] = i
    return minSwapsUtil ( arr , pairs , index , 1 , 2 * n )
arr = [ 0 , 3 , 5 , 6 , 4 , 1 , 2 ]
pairs = [ 0 , 3 , 6 , 1 , 5 , 4 , 2 ]
m = len ( pairs )
n = m // 2
print ( " Min ▁ swaps ▁ required ▁ is ▁ " , minSwaps ( n , pairs , arr ) )

Index/key variables: a, b, i, indexone
Accumulator variables: index
Iterator variables: i
Python program:
from __future__ import print_function
def replace_elements ( arr , n ) :
    pos = 0
    for i in range ( 0 , n ) :
        arr [ pos ] = arr [ i ]
        pos = pos + 1
        while ( pos > 1 and arr [ pos - 2 ] == arr [ pos - 1 ] ) :
            pos -= 1
            arr [ pos - 1 ] += 1
    for i in range ( 0 , pos ) :
        print ( arr [ i ] , end = " ▁ " )
arr = [ 6 , 4 , 3 , 4 , 3 , 3 , 5 ]
n = len ( arr )
replace_elements ( arr , n )

Index/key variables: i, pos
Iterator variables: i
Python program:
def arrangeString ( str1 , x , y ) :
    count_0 = 0
    count_1 = 0
    n = len ( str1 )
    for i in range ( n ) :
        if str1 [ i ] == '0' :
            count_0 += 1
        else :
            count_1 += 1
    while count_0 > 0 or count_1 > 0 :
        for i in range ( 0 , x ) :
            if count_0 > 0 :
                print ( "0" , end = " " )
                count_0 -= 1
        for j in range ( 0 , y ) :
            if count_1 > 0 :
                print ( "1" , end = " " )
                count_1 -= 1
if __name__ == ' _ _ main _ _ ' :
    str1 = "01101101101101101000000"
    x = 1
    y = 2
    arrangeString ( str1 , x , y )

Index/key variables: i
Accumulator variables: count_0, count_1
Iterator variables: i, j
Python program:
arr = [ 1 , 3 , 5 , 2 , 4 , 6 ]
def rearrange ( n ) :
    global arr
    if ( n % 2 == 1 ) :
        return
    currIdx = int ( ( n - 1 ) / 2 )
    while ( currIdx > 0 ) :
        count = currIdx
        swapIdx = currIdx
        while ( count > 0 ) :
            temp = arr [ swapIdx + 1 ]
            arr [ swapIdx + 1 ] = arr [ swapIdx ]
            arr [ swapIdx ] = temp
            swapIdx = swapIdx + 1
            count = count - 1
        currIdx = currIdx - 1
n = len ( arr )
rearrange ( n )
for i in range ( 0 , n ) :
    print ( " { } ▁ " . format ( arr [ i ] ) , end = " " )

Index/key variables: i, swapIdx
Iterator variables: i
Python program:
def maxDiff ( arr , arr_size ) :
    max_diff = arr [ 1 ] - arr [ 0 ]
    for i in range ( 0 , arr_size ) :
        for j in range ( i + 1 , arr_size ) :
            if ( arr [ j ] - arr [ i ] > max_diff ) :
                max_diff = arr [ j ] - arr [ i ]
    return max_diff
arr = [ 1 , 2 , 90 , 10 , 110 ]
size = len ( arr )
print ( " Maximum ▁ difference ▁ is " , maxDiff ( arr , size ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def maxDiff ( arr , n ) :
    maxDiff = - 1
    maxRight = arr [ n - 1 ]
    for i in range ( n - 2 , - 1 , - 1 ) :
        if ( arr [ i ] > maxRight ) :
            maxRight = arr [ i ]
        else :
            diff = maxRight - arr [ i ]
            if ( diff > maxDiff ) :
                maxDiff = diff
    return maxDiff
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 90 , 10 , 110 ]
    n = len ( arr )
    print ( " Maximum ▁ difference ▁ is " , maxDiff ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def maxDiff ( arr , n ) :
    diff = arr [ 1 ] - arr [ 0 ]
    curr_sum = diff
    max_sum = curr_sum
    for i in range ( 1 , n - 1 ) :
        diff = arr [ i + 1 ] - arr [ i ]
        if ( curr_sum > 0 ) :
            curr_sum += diff
        else :
            curr_sum = diff
        if ( curr_sum > max_sum ) :
            max_sum = curr_sum
    return max_sum
if __name__ == ' _ _ main _ _ ' :
    arr = [ 80 , 2 , 6 , 3 , 100 ]
    n = len ( arr )
    print ( " Maximum ▁ difference ▁ is " , maxDiff ( arr , n ) )

Index/key variables: i
Accumulator variables: curr_sum
Iterator variables: i
Python program:
def findMaximum ( arr , low , high ) :
    max = arr [ low ]
    i = low
    for i in range ( high + 1 ) :
        if arr [ i ] > max :
            max = arr [ i ]
    return max
arr = [ 1 , 30 , 40 , 50 , 60 , 70 , 23 , 20 ]
n = len ( arr )
print ( " The ▁ maximum ▁ element ▁ is ▁ % d " % findMaximum ( arr , 0 , n - 1 ) )

Index/key variables: i, low
Iterator variables: i
Python program:
def findMaximum ( arr , low , high ) :
    if low == high :
        return arr [ low ]
    if high == low + 1 and arr [ low ] >= arr [ high ] :
        return arr [ low ] ;
    if high == low + 1 and arr [ low ] < arr [ high ] :
        return arr [ high ]
    mid = ( low + high ) // 2
    if arr [ mid ] > arr [ mid + 1 ] and arr [ mid ] > arr [ mid - 1 ] :
        return arr [ mid ]
    if arr [ mid ] > arr [ mid + 1 ] and arr [ mid ] < arr [ mid - 1 ] :
        return findMaximum ( arr , low , mid - 1 )
    else :
        return findMaximum ( arr , mid + 1 , high )
arr = [ 1 , 3 , 50 , 10 , 9 , 7 , 6 ]
n = len ( arr )
print ( " The ▁ maximum ▁ element ▁ is ▁ % d " % findMaximum ( arr , 0 , n - 1 ) )

Index/key variables: high, low, mid
Python program:
def constructLowerArray ( arr , countSmaller , n ) :
    for i in range ( n ) :
        countSmaller [ i ] = 0
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            if ( arr [ j ] < arr [ i ] ) :
                countSmaller [ i ] += 1
def printArray ( arr , size ) :
    for i in range ( size ) :
        print ( arr [ i ] , end = " ▁ " )
    print ( )
arr = [ 12 , 10 , 5 , 4 , 2 , 20 , 6 , 1 , 0 , 2 ]
n = len ( arr )
low = [ 0 ] * n
constructLowerArray ( arr , low , n )
printArray ( low , n )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def segregate ( arr , size ) :
    j = 0
    for i in range ( size ) :
        if ( arr [ i ] <= 0 ) :
            arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]
            j += 1
    return j
def findMissingPositive ( arr , size ) :
    for i in range ( size ) :
        if ( abs ( arr [ i ] ) - 1 < size and arr [ abs ( arr [ i ] ) - 1 ] > 0 ) :
            arr [ abs ( arr [ i ] ) - 1 ] = - arr [ abs ( arr [ i ] ) - 1 ]
    for i in range ( size ) :
        if ( arr [ i ] > 0 ) :
            return i + 1
    return size + 1
def findMissing ( arr , size ) :
    shift = segregate ( arr , size )
    return findMissingPositive ( arr [ shift : ] , size - shift )
arr = [ 0 , 10 , 2 , - 10 , - 20 ]
arr_size = len ( arr )
missing = findMissing ( arr , arr_size )
print ( " The ▁ smallest ▁ positive ▁ missing ▁ number ▁ is ▁ " , missing )

Index/key variables: i, j
Iterator variables: i
Python program:
from collections import Counter
def printElements ( arr , n , k ) :
    x = n // k
    mp = Counter ( arr )
    for it in mp :
        if mp [ it ] > x :
            print ( it )
arr = [ 1 , 1 , 2 , 2 , 3 , 5 , 4 , 2 , 2 , 3 , 1 , 1 , 1 ]
n = len ( arr )
k = 4
printElements ( arr , n , k )

Index/key variables: it
Iterator variables: it
Python program:
def smallestGreater ( arr , n ) :
    for i in range ( 0 , n ) :
        diff = 1000 ;
        closest = - 1 ;
        for j in range ( 0 , n ) :
            if ( arr [ i ] < arr [ j ] and arr [ j ] - arr [ i ] < diff ) :
                diff = arr [ j ] - arr [ i ] ;
                closest = j ;
        if ( closest == - 1 ) :
            print ( " _ ▁ " , end = " " ) ;
        else :
            print ( " { } ▁ " . format ( arr [ closest ] ) , end = " " ) ;
ar = [ 6 , 3 , 9 , 8 , 10 , 2 , 1 , 15 , 7 ] ;
n = len ( ar ) ;
smallestGreater ( ar , n ) ;

Index/key variables: closest, i, j
Iterator variables: i, j
Python program:
def smallestGreater ( arr , n ) :
    s = set ( )
    for i in range ( n ) :
        s . add ( arr [ i ] )
    newAr = [ ]
    for p in s :
        newAr . append ( p )
    for i in range ( n ) :
        temp = lowerBound ( newAr , 0 , len ( newAr ) , arr [ i ] )
        if ( temp < n ) :
            print ( newAr [ temp ] , end = " ▁ " )
        else :
            print ( " _ ▁ " , end = " " )
def lowerBound ( vec , low , high , element ) :
    array = [ 0 ] * ( len ( vec ) )
    k = 0
    for val in vec :
        array [ k ] = val
        k += 1
    while ( low < high ) :
        middle = low + int ( ( high - low ) / 2 )
        if ( element > array [ middle ] ) :
            low = middle + 1
        else :
            high = middle
    return low + 1
if __name__ == ' _ _ main _ _ ' :
    ar = [ 6 , 3 , 9 , 8 , 10 , 2 , 1 , 15 , 7 ]
    n = len ( ar )
    smallestGreater ( ar , n )

Index/key variables: i, k, middle, temp
Accumulator variables: newAr, s
Iterator variables: i, p, val
Python program:
def findZeroes ( arr , n , m ) :
    wL = wR = 0
    bestL = bestWindow = 0
    zeroCount = 0
    while wR < n :
        if zeroCount <= m :
            if arr [ wR ] == 0 :
                zeroCount += 1
            wR += 1
        if zeroCount > m :
            if arr [ wL ] == 0 :
                zeroCount -= 1
            wL += 1
        if ( wR - wL > bestWindow ) and ( zeroCount <= m ) :
            bestWindow = wR - wL
            bestL = wL
    for i in range ( 0 , bestWindow ) :
        if arr [ bestL + i ] == 0 :
            print ( bestL + i , end = " ▁ " )
arr = [ 1 , 0 , 0 , 1 , 1 , 0 , 1 , 0 , 1 , 1 ]
m = 2
n = len ( arr )
print ( " Indexes ▁ of ▁ zeroes ▁ to ▁ be ▁ flipped ▁ are " , end = " ▁ " )
findZeroes ( arr , n , m )

Index/key variables: wL, wR
Accumulator variables: zeroCount
Iterator variables: i
Python program:
def countIncreasing ( arr , n ) :
    cnt = 0
    for i in range ( 0 , n ) :
        for j in range ( i + 1 , n ) :
            if arr [ j ] > arr [ j - 1 ] :
                cnt += 1
            else :
                break
    return cnt
arr = [ 1 , 2 , 2 , 4 ]
n = len ( arr )
print ( " Count ▁ of ▁ strictly ▁ increasing ▁ subarrays ▁ is " , countIncreasing ( arr , n ) )

Index/key variables: j
Accumulator variables: cnt
Iterator variables: i, j
Python program:
def countIncreasing ( arr , n ) :
    cnt = 0
    len = 1
    for i in range ( 0 , n - 1 ) :
        if arr [ i + 1 ] > arr [ i ] :
            len += 1
        else :
            cnt += ( ( ( len - 1 ) * len ) / 2 )
            len = 1
    if len > 1 :
        cnt += ( ( ( len - 1 ) * len ) / 2 )
    return cnt
arr = [ 1 , 2 , 2 , 4 ]
n = len ( arr )
print ( " Count ▁ of ▁ strictly ▁ increasing ▁ subarrays ▁ is " , int ( countIncreasing ( arr , n ) ) )

Index/key variables: i
Accumulator variables: cnt, len
Iterator variables: i
Python program:
def arraySum ( arr , n ) :
    sum = 0
    for i in range ( n ) :
        sum = sum + arr [ i ]
    return sum
def maxDiff ( arr , n , k ) :
    arr . sort ( )
    arraysum = arraySum ( arr , n )
    diff1 = abs ( arraysum - 2 * arraySum ( arr , k ) )
    arr . reverse ( )
    diff2 = abs ( arraysum - 2 * arraySum ( arr , k ) )
    return ( max ( diff1 , diff2 ) )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 7 , 4 , 8 , - 1 , 5 , 2 , 1 ]
    n = len ( arr )
    k = 3
    print ( " Maximum ▁ Difference ▁ = " , maxDiff ( arr , n , k ) )

Index/key variables: i
Iterator variables: i
Python program:
def minNumber ( a , n , x ) :
    a . sort ( reverse = False )
    k = 0
    while ( a [ int ( ( n - 1 ) / 2 ) ] != x ) :
        a [ n - 1 ] = x
        n += 1
        a . sort ( reverse = False )
        k += 1
    return k
if __name__ == ' _ _ main _ _ ' :
    x = 10
    a = [ 10 , 20 , 30 ]
    n = 3
    print ( minNumber ( a , n , x ) )

Accumulator variables: k, n
Python program:
def minNumber ( a , n , x ) :
    l = 0
    h = 0
    e = 0
    for i in range ( n ) :
        if a [ i ] == x :
            e += 1
        elif a [ i ] > x :
            h += 1
        elif a [ i ] < x :
            l += 1
    ans = 0 ;
    if l > h :
        ans = l - h
    elif l < h :
        ans = h - l - 1 ;
    return ans + 1 - e
x = 10
a = [ 10 , 20 , 30 ]
n = len ( a )
print ( minNumber ( a , n , x ) )

Index/key variables: i
Accumulator variables: e, h, l
Iterator variables: i