dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def isPossibleToSort ( arr , N ) :
    idx = - 1
    for i in range ( 1 , N ) :
        if ( arr [ i ] == 1 and arr [ i - 1 ] == 1 ) :
            idx = i
            break
    if ( idx == - 1 ) :
        print ( " YES " )
        return
    for i in range ( idx + 1 , N , 1 ) :
        if ( arr [ i ] == 0 and arr [ i - 1 ] == 0 ) :
            print ( " NO " )
            return
    print ( " YES " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 0 , 1 , 0 , 1 , 1 , 0 ]
    N = len ( arr )
    isPossibleToSort ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
def maxConsecutiveRopes ( ropes , N ) :
    curSize = 0
    ropes = sorted ( ropes )
    for i in range ( N ) :
        if ( ropes [ i ] <= curSize + 1 ) :
            curSize = curSize + ropes [ i ]
        else :
            break
    return curSize
if __name__ == ' _ _ main _ _ ' :
    N = 5
    ropes = [ 1 , 2 , 7 , 1 , 1 ]
    print ( maxConsecutiveRopes ( ropes , N ) )

Index/key variables: i
Iterator variables: i
Python program:
def maxRanges ( arr , N ) :
    arr . sort ( )
    count = 1
    prev = arr [ 0 ]
    for i in range ( 1 , N ) :
        last = arr [ i - 1 ]
        current = arr [ i ]
        if ( last [ 0 ] == current [ 0 ] and last [ 1 ] == current [ 1 ] and current [ 1 ] == current [ 0 ] ) :
            continue
        start = max ( prev [ 0 ] , current [ 0 ] - 1 )
        end = max ( prev [ 1 ] , current [ 1 ] )
        if ( end - start > 0 ) :
            prev [ 0 ] = 1 + start
            prev [ 1 ] = end
            count += 1
    return count
if __name__ == " _ _ main _ _ " :
    arr = [ [ 1 , 4 ] , [ 4 , 4 ] , [ 2 , 2 ] , [ 3 , 4 ] , [ 1 , 1 ] ]
    N = len ( arr )
    print ( maxRanges ( arr , N ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def adjust ( S , i , start , end ) :
    N = len ( S )
    start = i - 1
    while ( i < N and S [ i ] < S [ i - 1 ] ) :
        i += 1
    end = i - 1
    if ( start <= 0 and i >= N ) :
        return True , start , i , end
    if ( start >= 1 and i <= N ) :
        return ( S [ end ] >= S [ start - 1 ] and S [ start ] <= S [ i ] ) , start , i , end
    if ( start >= 1 ) :
        return ( S [ end ] >= S [ start - 1 ] ) , start , i , end
    if ( i < N ) :
        return ( S [ start ] <= S [ i ] ) , start , i , end
    return False , start , i , end
def isPossible ( S , N ) :
    start , end = - 1 , - 1
    flag = True
    i = 1
    while i < N :
        if ( S [ i ] < S [ i - 1 ] ) :
            if ( flag ) :
                f , start , i , end = adjust ( S , i , start , end )
                if ( f == False ) :
                    print ( - 1 )
                    return
                flag = False
            else :
                print ( - 1 )
                return
        i += 1
    if ( start == - 1 ) :
        start , end = 1 , 1
    print ( start , end )
if __name__ == ' _ _ main _ _ ' :
    S = " abcyxuz "
    N = len ( S )
    isPossible ( S , N )

Index/key variables: end, i, start
Boolean variables: flag
Python program:
def maximumSum ( arr , S , N , K ) :
    ans = 0
    arr = sorted ( arr ) [ : : - 1 ]
    for i in range ( K ) :
        ans += arr [ i ]
    S = sorted ( S )
    for i in range ( K ) :
        if ( S [ i ] == 1 ) :
            ans += arr [ i ]
        S [ i ] -= 1
    counter = K - 1
    for i in range ( K ) :
        counter = counter + S [ i ]
        if ( S [ i ] != 0 ) :
            ans += arr [ counter ]
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 13 , 7 , 17 ]
    S = [ 1 , 3 ]
    N = len ( arr )
    K = len ( S )
    print ( maximumSum ( arr , S , N , K ) )

Index/key variables: counter, i
Accumulator variables: ans
Iterator variables: i
Python program:
def binaryToDecimal ( n ) :
    num = n
    dec_value = 0
    base = 1
    length = len ( num )
    for i in range ( length - 1 , - 1 , - 1 ) :
        if ( num [ i ] == '1' ) :
            dec_value += base
        base = base * 2
    return dec_value
def decimalToBinary ( n ) :
    binstr = " "
    while ( n > 0 ) :
        binstr += chr ( n % 2 + 48 )
        n = n // 2
    return binstr
def reversedBinaryDecimal ( N ) :
    decimal_to_binar = decimalToBinary ( N )
    binary_to_decimal = binaryToDecimal ( decimal_to_binar )
    return binary_to_decimal
def printSortedArray ( arr , size ) :
    arr . sort ( )
    for i in range ( size ) :
        print ( arr [ i ] , end = " ▁ " )
    print ( )
def modifyArray ( arr , size ) :
    for i in range ( size ) :
        arr [ i ] = reversedBinaryDecimal ( arr [ i ] )
    printSortedArray ( arr , size )
if __name__ == " _ _ main _ _ " :
    arr = [ 98 , 43 , 66 , 83 ]
    n = len ( arr )
    modifyArray ( arr , n )

Index/key variables: i
Accumulator variables: binstr, dec_value
Iterator variables: i
Python program:
def isSortedArray ( arr , n ) :
    l = 0
    r = ( n - 1 )
    while ( ( l + 1 ) < r ) :
        if ( arr [ l ] >= max ( arr [ l + 1 ] , arr [ r - 1 ] ) and arr [ r ] >= max ( arr [ r - 1 ] , arr [ l + 1 ] ) ) :
            l += 1
            r -= 1
        else :
            return False
    return True
if __name__ == " _ _ main _ _ " :
    arr = [ 4 , 3 , 1 , 2 , 5 ]
    N = len ( arr )
    if ( isSortedArray ( arr , N ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: l, r
Python program:
def maxLenSubset ( a , n ) :
    a . sort ( reverse = False )
    index = 0
    maxlen = - 1
    i = 0
    while ( i < n ) :
        j = i
        len1 = 1
        while ( j < n - 1 ) :
            if ( 2 * a [ j ] >= a [ j + 1 ] ) :
                len1 += 1
            else :
                break
            j += 1
        if ( maxlen < len1 ) :
            maxlen = len1
            index = i
        j += 1
        i = j
    i = index
    while ( maxlen > 0 ) :
        print ( a [ i ] , end = " ▁ " )
        maxlen -= 1
        i += 1
if __name__ == ' _ _ main _ _ ' :
    a = [ 3 , 1 , 5 , 11 ]
    n = len ( a )
    maxLenSubset ( a , n )

Index/key variables: i, j
Accumulator variables: len1, maxlen
Python program:
from bisect import bisect_left
def solve ( N , X , Y ) :
    p = [ ]
    for i in range ( N ) :
        p . append ( [ X [ i ] , Y [ i ] ] )
    p = sorted ( p )
    s = { }
    s [ p [ 0 ] [ 1 ] ] = 1
    for i in range ( N ) :
        arr = list ( s . keys ( ) )
        it = bisect_left ( arr , p [ i ] [ 1 ] )
        if ( it == len ( s ) ) :
            s [ p [ i ] [ 1 ] ] = 1
        else :
            del s [ arr [ it ] ]
            s [ p [ i ] [ 1 ] ] = 1
    return len ( s )
if __name__ == ' _ _ main _ _ ' :
    N = 3
    X = [ 1 , 2 , 0 ]
    Y = [ 2 , 0 , 1 ]
    maxintersection = solve ( N , X , Y )
    print ( maxintersection )

Index/key variables: i, it
Accumulator variables: p
Iterator variables: i
Python program:
def canReduceArray ( arr , N , K ) :
    arr = sorted ( arr )
    for i in range ( N - 1 ) :
        if ( arr [ i ] - arr [ i + 1 ] > K ) :
            print ( " No " )
            return
    print ( " Yes " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 1 , 1 , 3 ]
    N = len ( arr )
    K = 1
    canReduceArray ( arr , N , K )

Index/key variables: i
Iterator variables: i
Python program:
def mergeStrings ( s1 , s2 ) :
    len1 = len ( s1 )
    len2 = len ( s2 )
    pntr1 = 0
    pntr2 = 0
    ans = " "
    while ( pntr1 < len1 and pntr2 < len2 ) :
        if ( s1 [ pntr1 ] < s2 [ pntr2 ] ) :
            ans += s1 [ pntr1 ]
            pntr1 += 1
        else :
            ans += s2 [ pntr2 ]
            pntr2 += 1
    if ( pntr1 < len1 ) :
        ans += s1 [ pntr1 : pntr1 + len1 ]
    if ( pntr2 < len2 ) :
        ans += s2 [ pntr2 : pntr2 + len2 ]
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    S1 = " abdcdtx "
    S2 = " achilp "
    mergeStrings ( S1 , S2 )

Index/key variables: pntr1, pntr2
Accumulator variables: ans
Python program:
from bisect import bisect_right
def countPairs ( arr , n , k ) :
    arr . sort ( )
    ans = 0
    for i in range ( n - 1 ) :
        high = bisect_right ( arr , k * arr [ i ] )
        ans += high - i - 1
    print ( ans )
arr = [ 2 , 3 , 9 , 5 ]
n = len ( arr )
k = 2
countPairs ( arr , n , k )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def findXOR ( mat , K ) :
    N = len ( mat )
    M = len ( mat [ 0 ] )
    digXOR = [ ]
    for l in range ( 1 , N + M , 1 ) :
        s_col = max ( 0 , l - N )
        count = min ( [ l , ( M - s_col ) , N ] )
        currXOR = 0
        for j in range ( count ) :
            currXOR = ( currXOR ^ mat [ min ( N , l ) - j - 1 ] [ s_col + j ] )
        digXOR . append ( currXOR )
    digXOR . sort ( reverse = False )
    print ( digXOR [ N + M - 1 - K ] )
if __name__ == ' _ _ main _ _ ' :
    mat = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ]
    K = 3
    findXOR ( mat , K )

Accumulator variables: digXOR
Iterator variables: j, l
Python program:
v = [ ]
def findSum ( n ) :
    global v
    um = { }
    res = 0
    cnt = 0
    for i in range ( len ( v ) ) :
        if ( cnt == n ) :
            break
        x = v [ i ] [ 1 ] [ 0 ]
        y = v [ i ] [ 1 ] [ 1 ]
        xorResult = v [ i ] [ 0 ]
        if ( x in um and um [ x ] == False and y in um and um [ y ] == False ) :
            res += xorResult
            um [ x ] = True
            um [ y ] = True
            cnt += 2
    return res
def findMaxMinSum ( a , n ) :
    global v
    for i in range ( n ) :
        for j in range ( i + 1 , n , 1 ) :
            xorResult = a [ i ] ^ a [ j ]
            v . append ( [ xorResult , [ a [ i ] , a [ j ] ] ] )
    v . sort ( reverse = False )
    maxi = 0
    mini = 0
    mini = findSum ( n )
    mini = 6
    v = v [ : : - 1 ]
    maxi = findSum ( n )
    maxi = 10
    print ( mini , maxi )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 4 ]
    N = len ( arr )
    findMaxMinSum ( arr , N )

Index/key variables: i, j, x, y
Accumulator variables: cnt, res, v
Iterator variables: i, j
Python program:
def maximumSumPermutation ( arr ) :
    N = len ( arr ) ;
    arr . sort ( ) ;
    temp = arr [ 0 ] ;
    arr [ 0 ] = arr [ N - 1 ] ;
    arr [ N - 1 ] = temp ;
    for i in arr :
        print ( i , end = " ▁ " ) ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 4 , 5 ] ;
    maximumSumPermutation ( arr ) ;

Iterator variables: i
Python program:
import math
def findMaxNumbers ( arr , n , k ) :
    arr . sort ( )
    cnt = 0
    for i in range ( n ) :
        opr = math . ceil ( math . log2 ( arr [ i ] ) )
        k -= opr
        if ( k < 0 ) :
            break
        cnt += 1
    print ( cnt )
arr = [ 5 , 8 , 4 , 7 ]
N = len ( arr )
K = 5
findMaxNumbers ( arr , N , K )

Index/key variables: i
Accumulator variables: cnt, k
Iterator variables: i
Python program:
def meanOfRemainingElements ( arr , N , K ) :
    arr . sort ( )
    kthPercent = ( N * K ) / 100
    sum = 0
    for i in range ( N ) :
        if ( i >= kthPercent and i < ( N - kthPercent ) ) :
            sum += arr [ i ]
    mean = sum / ( N - 2 * kthPercent )
    print ( ' % .5f ' % mean )
arr = [ 6 , 2 , 7 , 5 , 1 , 2 , 0 , 3 , 10 , 2 , 5 , 0 , 5 , 5 , 0 , 8 , 7 , 6 , 8 , 0 ]
arr_size = len ( arr )
K = 5
meanOfRemainingElements ( arr , arr_size , K )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def minOperation ( a , N ) :
    totOps = 0
    for i in range ( N - 1 ) :
        totOps += abs ( a [ i ] - a [ i + 1 ] )
    maxOps = max ( abs ( a [ 0 ] - a [ 1 ] ) , abs ( a [ N - 1 ] - a [ N - 2 ] ) )
    for i in range ( 1 , N - 1 ) :
        maxOps = max ( maxOps , abs ( a [ i ] - a [ i - 1 ] ) + abs ( a [ i ] - a [ i + 1 ] ) - abs ( a [ i - 1 ] - a [ i + 1 ] ) )
    print ( totOps - maxOps )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , - 1 , 0 , 1 , 1 ]
    N = len ( arr )
    minOperation ( arr , N )

Index/key variables: i
Accumulator variables: totOps
Iterator variables: i
Python program:
temp = [ 0 ] * 100000
def merge ( A , left , mid , right ) :
    swaps = 0
    i , j , k = left , mid , left
    while ( i < mid and j <= right ) :
        if ( A [ i ] <= A [ j ] ) :
            temp [ k ] = A [ i ]
            k , i = k + 1 , i + 1
        else :
            temp [ k ] = A [ j ]
            k , j = k + 1 , j + 1
            swaps += mid - i
    while ( i < mid ) :
        temp [ k ] = A [ i ]
        k , i = k + 1 , i + 1
    while ( j <= right ) :
        temp [ k ] = A [ j ]
        k , j = k + 1 , j + 1
    while ( left <= right ) :
        A [ left ] = temp [ left ]
        left += 1
    return swaps
def mergeInsertionSwap ( A , left , right ) :
    swaps = 0
    if ( left < right ) :
        mid = left + ( right - left ) // 2
        swaps += mergeInsertionSwap ( A , left , mid )
        swaps += mergeInsertionSwap ( A , mid + 1 , right )
        swaps += merge ( A , left , mid + 1 , right )
    return swaps
if __name__ == ' _ _ main _ _ ' :
    A = [ 2 , 1 , 3 , 1 , 2 ]
    N = len ( A )
    print ( mergeInsertionSwap ( A , 0 , N - 1 ) )

Index/key variables: i, j, k, left
Accumulator variables: swaps
Python program:
def maxCntRemovedfromArray ( arr , N , brr , M ) :
    arr . sort ( reverse = False )
    i = 0
    sumArr = 0
    for i in range ( N ) :
        sumArr += arr [ i ]
    sumBrr = 0
    for i in range ( M ) :
        sumBrr += brr [ i ]
    cntRemElem = 0
    while ( i < N and sumArr >= sumBrr ) :
        sumArr -= arr [ i ]
        i += 1
        if ( sumArr >= sumBrr ) :
            cntRemElem += 1
    return cntRemElem
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 4 , 6 ]
    brr = [ 7 ]
    N = len ( arr )
    M = len ( brr )
    print ( maxCntRemovedfromArray ( arr , N , brr , M ) )

Index/key variables: i
Accumulator variables: cntRemElem, sumArr, sumBrr
Iterator variables: i
Python program:
def findPair ( arr , N ) :
    for i in range ( N ) :
        a , b = arr [ i ] [ 0 ] , arr [ i ] [ 1 ]
        for j in range ( i + 1 , N ) :
            c , d = arr [ j ] [ 0 ] , arr [ j ] [ 1 ]
            if ( a < c and b > d ) :
                print ( " ( " , a , b , " ) , ▁ ( " , c , d , " ) " )
                return
    print ( " NO ▁ SUCH ▁ PAIR ▁ EXIST " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 3 , 7 ] , [ 21 , 23 ] , [ 4 , 13 ] , [ 1 , 2 ] , [ 7 , - 1 ] ]
    findPair ( arr , 5 )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def findPair ( arr , N ) :
    arr . sort ( key = lambda x : x [ 0 ] )
    for i in range ( 1 , N ) :
        b = arr [ i - 1 ] [ 1 ]
        d = arr [ i ] [ 1 ]
        if ( b > d ) :
            print ( " ( " , arr [ i - 1 ] [ 0 ] , b , " ) , ▁ ( " , arr [ i ] [ 0 ] , d , " ) " )
            return
    print ( " NO SUCH PAIR EXIST " ) ;
arr = [ [ 3 , 7 ] , [ 21 , 23 ] , [ 4 , 13 ] , [ 1 , 2 ] , [ 7 , - 1 ] ]
findPair ( arr , 5 )

Index/key variables: i
Iterator variables: i
Python program:
def printOrder ( order , N , X ) :
    vect = [ ]
    for i in range ( N ) :
        if ( order [ i ] % X == 0 ) :
            vect . append ( [ order [ i ] // X , i + 1 ] )
        else :
            vect . append ( [ order [ i ] // X + 1 , i + 1 ] )
    vect = sorted ( vect )
    for i in range ( N ) :
        print ( vect [ i ] [ 1 ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    N , X = 3 , 3
    order = [ 2 , 7 , 4 ]
    printOrder ( order , N , X )

Index/key variables: i
Accumulator variables: vect
Iterator variables: i
Python program:
def rearrange ( A , B , N , X ) :
    flag = True
    A = sorted ( A )
    B = sorted ( B ) [ : : - 1 ]
    for i in range ( N ) :
        if ( A [ i ] + B [ i ] > X ) :
            flag = False
            break
    if ( flag ) :
        print ( " Yes " )
    else :
        print ( " No " )
if __name__ == ' _ _ main _ _ ' :
    A = [ 1 , 2 , 3 ]
    B = [ 1 , 1 , 2 ]
    X = 4
    N = len ( A )
    rearrange ( A , B , N , X )

Index/key variables: i
Iterator variables: i
Boolean variables: flag
Python program:
def numOperation ( arr , N , D ) :
    arr . sort ( )
    for i in range ( N - 1 ) :
        if ( ( arr [ i + 1 ] - arr [ i ] ) % D != 0 ) :
            print ( " - 1" )
            return
    count = 0
    mid = arr [ N // 2 ]
    for i in range ( N ) :
        count += abs ( mid - arr [ i ] ) // D
    print ( count )
if __name__ == " _ _ main _ _ " :
    N = 4
    D = 2
    arr = [ 2 , 4 , 6 , 8 ]
    numOperation ( arr , N , D )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def findSum ( A , N , K ) :
    A . sort ( ) ;
    sum = 0 ;
    for i in range ( N // K , N , K - 1 ) :
        sum += A [ i ] ;
    print ( sum ) ;
if __name__ == ' _ _ main _ _ ' :
    K = 4 ;
    A = [ 2 , 3 , 1 , 4 , 7 , 5 , 6 , 1 ] ;
    N = len ( A ) ;
    findSum ( A , N , K ) ;

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def findSmallestNumLeft ( arr , N ) :
    PQ = [ ]
    for i in range ( N ) :
        PQ . append ( arr [ i ] )
    PQ = sorted ( PQ )
    while ( len ( PQ ) > 1 ) :
        top1 = PQ [ - 1 ]
        del PQ [ - 1 ]
        top2 = PQ [ - 1 ]
        del PQ [ - 1 ]
        PQ . append ( ( top1 + top2 + 1 ) // 2 )
        PQ = sorted ( PQ )
    return PQ [ - 1 ]
if __name__ == ' _ _ main _ _ ' :
    arr = [ 30 , 16 , 40 ]
    N = len ( arr )
    print ( findSmallestNumLeft ( arr , N ) )

Index/key variables: i
Accumulator variables: PQ
Iterator variables: i
Python program:
from math import ceil , sqrt
def isComposite ( n ) :
    if ( n <= 1 ) :
        return False
    if ( n <= 3 ) :
        return False
    if ( n % 2 == 0 or n % 3 == 0 ) :
        return True
    for i in range ( 5 , ceil ( sqrt ( n ) ) , 6 ) :
        if ( n % i == 0 or n % ( i + 2 ) == 0 ) :
            return True
    return False
def digitProduct ( number ) :
    product = 1
    while ( number > 0 ) :
        product *= ( number % 10 )
        number //= 10
    return product
def compositedigitProduct ( num ) :
    res = digitProduct ( num )
    if ( res == 1 ) :
        return False
    if ( isComposite ( res ) ) :
        return True
    return False
def largestCompositeDigitProduct ( a , n , k ) :
    pq = [ ]
    for i in range ( n ) :
        if ( ( i % k ) == 0 ) :
            continue
        if ( compositedigitProduct ( a [ i ] ) ) :
            b = digitProduct ( a [ i ] )
            pq . append ( [ b , a [ i ] ] )
    pq = sorted ( pq )
    return pq [ - 1 ] [ 1 ]
if __name__ == ' _ _ main _ _ ' :
    arr = [ 233 , 144 , 89 , 71 , 13 , 21 , 11 , 34 , 55 , 23 ]
    n = len ( arr )
    k = 3
    ans = largestCompositeDigitProduct ( arr , n , k )
    print ( ans )

Index/key variables: i
Accumulator variables: number, pq, product
Iterator variables: i
Python program:
def findMinimum ( arr , N , K ) :
    arr = sorted ( arr )
    ans = 0
    for i in range ( 1 , 2 * ( N // K ) , 2 ) :
        ans += arr [ i ]
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 11 , 20 , 5 , 7 , 8 , 14 , 2 , 17 , 16 , 10 ]
    N = len ( arr )
    K = 5
    findMinimum ( arr , N , K )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def findSubarrays ( arr , N ) :
    arr . sort ( ) ;
    i = 0 ;
    for i in range ( N - 1 ) :
        if ( arr [ i ] == arr [ i + 1 ] ) :
            print ( " YES " ) ;
            return ;
    print ( " NO " ) ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 3 , 0 , 1 , 2 , 0 ] ;
    N = len ( arr ) ;
    findSubarrays ( arr , N ) ;

Index/key variables: i
Iterator variables: i
Python program:
def Bubble_Sort ( arr , n ) :
    flag = True
    for i in range ( 1 , n ) :
        flag = False
        for j in range ( n - i ) :
            if ( arr [ j ] > arr [ j + 1 ] ) :
                arr [ j ] , arr [ j + 1 ] = arr [ j + 1 ] , arr [ j ]
                flag = True
        if ( flag == False ) :
            break
n = 5
arr = [ 2 , 0 , 1 , 4 , 3 ]
Bubble_Sort ( arr , n )
print ( " The ▁ Sorted ▁ Array ▁ by ▁ using ▁ Bubble ▁ Sort ▁ is ▁ : ▁ " , end = ' ' )
for i in range ( n ) :
    print ( arr [ i ] , end = " ▁ " )

Index/key variables: i, j
Iterator variables: i, j
Boolean variables: flag
Python program:
def NDivKWithFreq ( arr , N , K ) :
    arr = sorted ( arr )
    i = 0
    while i < N :
        cnt = 1
        while ( ( i + 1 ) < N and arr [ i ] == arr [ i + 1 ] ) :
            cnt += 1
            i += 1
        if ( cnt > ( N // K ) ) :
            print ( arr [ i ] , end = " ▁ " )
        i += 1
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 2 , 6 , 6 , 6 , 6 , 7 , 10 ]
    N = len ( arr )
    K = 4
    NDivKWithFreq ( arr , N , K )

Index/key variables: i
Accumulator variables: cnt
Python program:
def printCircularArray ( arr , n ) :
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " )
def sortCircularArray ( arr , n , k , m ) :
    for i in range ( m ) :
        for j in range ( k , k + m - 1 ) :
            if ( arr [ j % n ] > arr [ ( j + 1 ) % n ] ) :
                arr [ j % n ] , arr [ ( j + 1 ) % n ] = ( arr [ ( j + 1 ) % n ] , arr [ j % n ] )
    printCircularArray ( arr , n )
if __name__ == " _ _ main _ _ " :
    arr = [ 4 , 1 , 6 , 5 , 3 ]
    K = 2
    M = 3
    N = len ( arr )
    sortCircularArray ( arr , N , K , M )

Index/key variables: i
Iterator variables: i, j
Python program:
def minimumCostReqToCompthePrcess ( arr ) :
    arr . sort ( key = lambda x : x [ 0 ] - x [ 1 ] )
    n = len ( arr )
    minCost = 0
    minCostInit = 0
    for i in range ( n ) :
        if arr [ i ] [ 1 ] > minCostInit :
            minCost += ( arr [ i ] [ 1 ] - minCostInit )
            minCostInit = arr [ i ] [ 1 ]
        minCostInit -= arr [ i ] [ 0 ]
    return minCost
if __name__ == " _ _ main _ _ " :
    arr = [ [ 1 , 2 ] , [ 2 , 4 ] , [ 4 , 8 ] ]
    print ( minimumCostReqToCompthePrcess ( arr ) )

Index/key variables: i
Accumulator variables: minCost, minCostInit
Iterator variables: i
Python program:
def maximumKthLargestsumPart ( arr , N , M , K ) :
    maxSum = 0
    if ( N % M != 0 ) :
        return - 1
    sz = ( N / M )
    if ( K > sz ) :
        return - 1
    arr = sorted ( arr )
    for i in range ( 0 , N // 2 ) :
        t = arr [ i ]
        arr [ i ] = arr [ N - i - 1 ]
        arr [ N - i - 1 ] = t
    for i in range ( 1 , M + 1 ) :
        maxSum += arr [ i * K - 1 ]
    return maxSum
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 4 , 5 , 6 ]
    M = 2
    K = 1
    N = len ( arr )
    print ( maximumKthLargestsumPart ( arr , N , M , K ) )

Index/key variables: i
Accumulator variables: maxSum
Iterator variables: i
Python program:
def minimumRange ( arr , N , K ) :
    if ( K >= N ) :
        print ( 0 , end = ' ' ) ;
        return ;
    arr . sort ( ) ;
    left = 0 ; right = N - 1 ;
    for i in range ( K ) :
        if ( arr [ right - 1 ] - arr [ left ] < arr [ right ] - arr [ left + 1 ] ) :
            right -= 1 ;
        else :
            left += 1 ;
    print ( arr [ right ] - arr [ left ] , end = ' ' ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ 5 , 10 , 12 , 14 , 21 , 54 , 61 ] ;
    N = len ( arr ) ;
    K = 4 ;
    minimumRange ( arr , N , K ) ;

Index/key variables: left, right
Iterator variables: i
Python program:
def splitArray ( arr , n , K ) :
    arr . sort ( )
    i = n - 1
    result = 0
    while ( K > 0 ) :
        result += arr [ i - 1 ]
        i -= 2
        K -= 1
    print ( result )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 3 , 1 , 5 , 1 , 3 ]
    N = len ( arr )
    K = 2
    splitArray ( arr , N , K )

Accumulator variables: K, i, result