dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def findNonPalinString ( s ) :
    freq = [ 0 ] * ( 26 )
    flag = 0
    for i in range ( 0 , len ( s ) ) :
        if s [ i ] != s [ 0 ] :
            flag = 1
        freq [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1
    if not flag :
        print ( " - 1" )
    else :
        for i in range ( 0 , 26 ) :
            for j in range ( 0 , freq [ i ] ) :
                print ( chr ( ord ( ' a ' ) + i ) , end = " " )
if __name__ == " _ _ main _ _ " :
    s = " abba "
    findNonPalinString ( s )

Index/key variables: i
Iterator variables: i, j
Python program:
def minOperations ( n , m , k , matrix ) :
    arr = [ 0 ] * ( n * m )
    mod = matrix [ 0 ] [ 0 ] % k
    for i in range ( 0 , n ) :
        for j in range ( 0 , m ) :
            arr [ i * m + j ] = matrix [ i ] [ j ]
            if matrix [ i ] [ j ] % k != mod :
                return - 1
    arr . sort ( )
    median = arr [ ( n * m ) // 2 ]
    minOperations = 0
    for i in range ( 0 , n * m ) :
        minOperations += abs ( arr [ i ] - median ) // k
    if ( n * m ) % 2 == 0 :
        median2 = arr [ ( ( n * m ) // 2 ) - 1 ]
        minOperations2 = 0
        for i in range ( 0 , n * m ) :
            minOperations2 += abs ( arr [ i ] - median2 ) // k
        minOperations = min ( minOperations , minOperations2 )
    return minOperations
if __name__ == " _ _ main _ _ " :
    matrix = [ [ 2 , 4 , 6 ] , [ 8 , 10 , 12 ] , [ 14 , 16 , 18 ] , [ 20 , 22 , 24 ] ]
    n = len ( matrix )
    m = len ( matrix [ 0 ] )
    k = 2
    print ( minOperations ( n , m , k , matrix ) )

Index/key variables: i, j
Accumulator variables: minOperations, minOperations2
Iterator variables: i, j
Python program:
def countDistinct ( arr , n ) :
    res = 1
    for i in range ( 1 , n ) :
        j = 0
        for j in range ( i ) :
            if ( arr [ i ] == arr [ j ] ) :
                break
        if ( i == j + 1 ) :
            res += 1
    return res
arr = [ 12 , 10 , 9 , 45 , 2 , 10 , 10 , 45 ]
n = len ( arr )
print ( countDistinct ( arr , n ) )

Index/key variables: i, j
Accumulator variables: res
Iterator variables: i, j
Python program:
def countDistinct ( arr , n ) :
    arr . sort ( ) ;
    res = 0 ;
    i = 0 ;
    while ( i < n ) :
        while ( i < n - 1 and arr [ i ] == arr [ i + 1 ] ) :
            i += 1 ;
        res += 1 ;
        i += 1 ;
    return res ;
arr = [ 6 , 10 , 5 , 4 , 9 , 120 , 4 , 6 , 10 ] ;
n = len ( arr ) ;
print ( countDistinct ( arr , n ) ) ;

Index/key variables: i
Accumulator variables: res
Python program:
def printArray ( arr , n ) :
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " )
def printMaxMean ( arr , n ) :
    newArr = [ 0 ] * n
    arr . sort ( )
    for i in range ( n ) :
        newArr [ i ] = arr [ i + n ]
    printArray ( newArr , n )
if __name__ == " _ _ main _ _ " :
    arr = [ 4 , 8 , 3 , 1 , 3 , 7 , 0 , 4 ]
    n = len ( arr )
    printMaxMean ( arr , n // 2 )

Index/key variables: i
Iterator variables: i
Python program:
def average ( arr , n , k ) :
    total = 0
    if ( 2 * k >= n ) :
        return 0
    arr . sort ( )
    start , end = k , n - k - 1
    for i in range ( start , end + 1 ) :
        total += arr [ i ]
    return ( total / ( n - 2 * k ) )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 4 , 4 , 5 , 6 ]
    n = len ( arr )
    k = 2
    print ( average ( arr , n , k ) )

Index/key variables: i
Accumulator variables: total
Iterator variables: i
Python program:
def min_sum ( n , k , a ) :
    a . sort ( reverse = False )
    if ( a [ 0 ] < 0 ) :
        return - 1
    if ( k == 0 ) :
        if ( a [ 0 ] == a [ n - 1 ] ) :
            return ( n * a [ 0 ] )
        else :
            return - 1
    else :
        f = 0
        for i in range ( 1 , n , 1 ) :
            p = a [ i ] - a [ 0 ]
            if ( p % k == 0 ) :
                continue
            else :
                f = 1
                break
        if ( f ) :
            return - 1
        else :
            if ( k == 1 ) :
                return n
            else :
                return ( n * ( a [ 0 ] % k ) )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 3 , 4 , 5 ]
    K = 1
    N = len ( arr )
    print ( min_sum ( N , K , arr ) )

Index/key variables: i
Iterator variables: i
Python program:
def merge ( arr , start , mid , end ) :
    start2 = mid + 1
    if ( arr [ mid ] <= arr [ start2 ] ) :
        return
    while ( start <= mid and start2 <= end ) :
        if ( arr [ start ] <= arr [ start2 ] ) :
            start += 1
        else :
            value = arr [ start2 ]
            index = start2
            while ( index != start ) :
                arr [ index ] = arr [ index - 1 ]
                index -= 1
            arr [ start ] = value
            start += 1
            mid += 1
            start2 += 1
def mergeSort ( arr , l , r ) :
    if ( l < r ) :
        m = l + ( r - l ) // 2
        mergeSort ( arr , l , m )
        mergeSort ( arr , m + 1 , r )
        merge ( arr , l , m , r )
def printArray ( A , size ) :
    for i in range ( size ) :
        print ( A [ i ] , end = " ▁ " )
    print ( )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 12 , 11 , 13 , 5 , 6 , 7 ]
    arr_size = len ( arr )
    mergeSort ( arr , 0 , arr_size - 1 )
    printArray ( arr , arr_size )

Index/key variables: i, index, mid, start, start2
Iterator variables: i
Python program:
def minCost ( A , n ) :
    cost = 0
    A . sort ( ) ;
    K = A [ int ( n / 2 ) ]
    for i in range ( 0 , n ) :
        cost = cost + abs ( A [ i ] - K )
    if n % 2 == 0 :
        tempCost = 0
        K = A [ int ( n / 2 ) - 1 ]
        for i in range ( 0 , n ) :
            tempCost = tempCost + abs ( A [ i ] - K )
        cost = min ( cost , tempCost )
    return cost
A = [ 1 , 6 , 7 , 10 ]
n = len ( A )
print ( minCost ( A , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def printArray ( arr , n ) :
    arr . sort ( )
    l = 0
    r = n - 1
    flag = 0
    k = 2
    while ( l <= r ) :
        if ( flag == 0 ) :
            i = l
            while i < l + k and i <= r :
                print ( arr [ i ] , end = " ▁ " )
                i += 1
            flag = 1
            l = i
            i = r
            while i > r - k and i >= l :
                print ( arr [ i ] , end = " ▁ " )
                i -= 1
            flag = 0
            r = i
        k += 1
if __name__ == " _ _ main _ _ " :
    n = 6
    arr = [ 1 , 2 , 3 , 4 , 5 , 6 ]
    printArray ( arr , n )

Index/key variables: i
Accumulator variables: k
Python program:
def isAlphabaticOrder ( s ) :
    n = len ( s )
    for i in range ( 1 , n ) :
        if ( s [ i ] < s [ i - 1 ] ) :
            return False
    return True
if __name__ == " _ _ main _ _ " :
    s = " aabbbcc "
    if ( isAlphabaticOrder ( s ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Iterator variables: i
Python program:
def findProduct ( arr , n ) :
    sorted ( arr )
    prod = 1
    for i in range ( 0 , n , 1 ) :
        if ( arr [ i - 1 ] != arr [ i ] ) :
            prod = prod * arr [ i ]
    return prod ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 1 , 1 , 4 , 5 , 6 ]
    n = len ( arr )
    print ( findProduct ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
import sys ;
def rotateRec ( n , L , B ) :
    m = sys . maxsize ;
    for i in range ( n ) :
        if ( max ( L [ i ] , B [ i ] ) <= m ) :
            m = max ( L [ i ] , B [ i ] ) ;
        elif ( min ( L [ i ] , B [ i ] ) <= m ) :
            m = min ( L [ i ] , B [ i ] ) ;
        else :
            return 0 ;
    return 1 ;
n = 3 ;
L = [ 5 , 5 , 6 ] ;
B = [ 6 , 7 , 8 ] ;
if ( rotateRec ( n , L , B ) == 1 ) :
    print ( " YES " ) ;
else :
    print ( " NO " ) ;

Index/key variables: i
Iterator variables: i
Python program:
def minDistance ( n , k , point ) :
    for i in range ( k ) :
        point [ i ] . sort ( )
    for i in range ( k ) :
        print ( point [ i ] [ ( ( n + 1 ) // 2 ) - 1 ] , end = " ▁ " )
n = 4
k = 4
point = [ [ 1 , 5 , 2 , 4 ] , [ 6 , 2 , 0 , 6 ] , [ 9 , 5 , 1 , 3 ] , [ 6 , 7 , 5 , 9 ] ]
minDistance ( n , k , point )

Index/key variables: i
Iterator variables: i
Python program:
def printOrder ( arr , n , k ) :
    len1 = k
    len2 = n - k
    arr1 = [ 0 ] * k
    arr2 = [ 0 ] * ( n - k )
    for i in range ( k ) :
        arr1 [ i ] = arr [ i ]
    for i in range ( k , n ) :
        arr2 [ i - k ] = arr [ i ]
    arr1 . sort ( )
    arr2 . sort ( )
    for i in range ( n ) :
        if ( i < k ) :
            arr [ i ] = arr1 [ i ]
        else :
            arr [ i ] = arr2 [ len2 - 1 ]
            len2 -= 1
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ 5 , 4 , 6 , 2 , 1 , 3 , 8 , 9 , - 1 ]
    k = 4
    n = len ( arr )
    printOrder ( arr , n , k )

Index/key variables: i
Accumulator variables: len2
Iterator variables: i
Python program:
def findMaxNum ( arr , n ) :
    hash = [ 0 ] * 10
    for i in range ( n ) :
        hash [ arr [ i ] ] += 1
    for i in range ( 9 , - 1 , - 1 ) :
        for j in range ( hash [ i ] ) :
            print ( i , end = " " )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 4 , 5 , 0 ]
    n = len ( arr )
    findMaxNum ( arr , n )

Index/key variables: i
Iterator variables: i, j
Python program:
def sortK ( arr , n , k ) :
    arr . sort ( )
def printArray ( arr , size ) :
    for i in range ( size ) :
        print ( arr [ i ] , end = " ▁ " )
    print ( )
k = 3
arr = [ 2 , 6 , 3 , 12 , 56 , 8 ]
n = len ( arr )
sortK ( arr , n , k )
print ( " Following ▁ is ▁ sorted ▁ array " )
printArray ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
def distribution ( arr , n ) :
    arr . sort ( reverse = False )
    count = 1
    for i in range ( 1 , n , 1 ) :
        if ( arr [ i ] > arr [ i - 1 ] ) :
            count += 1
    return min ( count , n / 2 )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 1 , 2 , 1 , 3 , 4 ]
    n = len ( arr )
    print ( int ( distribution ( arr , n ) ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def printPairs ( arr , n ) :
    pairs = set ( )
    pair_exists = False
    for i in range ( 0 , n ) :
        if arr [ i ] > 0 :
            pairs . add ( arr [ i ] )
    for i in range ( 0 , n ) :
        if arr [ i ] < 0 :
            if ( - arr [ i ] ) in pairs :
                print ( " { } , ▁ { } " . format ( arr [ i ] , - arr [ i ] ) )
                pair_exists = True
    if pair_exists == False :
        print ( " No ▁ such ▁ pair ▁ exists " )
if __name__ == " _ _ main _ _ " :
    arr = [ 4 , 8 , 9 , - 4 , 1 , - 1 , - 8 , - 9 ]
    n = len ( arr )
    printPairs ( arr , n )

Index/key variables: i
Accumulator variables: pairs
Iterator variables: i
Boolean variables: pair_exists
Python program:
a = [ 10 , 12 , 5 ]
a . sort ( )
for i in range ( len ( a ) ) :
    print ( a [ i ] , end = ' ▁ ' )

Index/key variables: i
Iterator variables: i
Python program:
def printTriplets ( arr , n , sum ) :
    for i in range ( 0 , n - 2 , 1 ) :
        for j in range ( i + 1 , n - 1 , 1 ) :
            for k in range ( j + 1 , n , 1 ) :
                if ( arr [ i ] + arr [ j ] + arr [ k ] < sum ) :
                    print ( arr [ i ] , " , " , arr [ j ] , " , " , arr [ k ] )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 5 , 1 , 3 , 4 , 7 ]
    n = len ( arr )
    sum = 12
    printTriplets ( arr , n , sum )

Index/key variables: i, j, k
Iterator variables: i, j, k
Python program:
def countTriplets ( arr , n , a , b ) :
    ans = 0
    for i in range ( 0 , n - 2 ) :
        for j in range ( i + 1 , n - 1 ) :
            for k in range ( j + 1 , n ) :
                if ( ( arr [ i ] + arr [ j ] + arr [ k ] >= a ) and ( arr [ i ] + arr [ j ] + arr [ k ] <= b ) ) :
                    ans += 1
    return ans
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 7 , 5 , 3 , 8 , 4 , 1 , 9 ]
    n = len ( arr )
    a = 8 ; b = 16
    print ( countTriplets ( arr , n , a , b ) )

Index/key variables: i, j, k
Accumulator variables: ans
Iterator variables: i, j, k
Python program:
def countTripletsLessThan ( arr , n , val ) :
    arr . sort ( )
    ans = 0
    j = 0 ; k = 0
    sum = 0
    for i in range ( 0 , n - 2 ) :
        j = i + 1
        k = n - 1
        while j != k :
            sum = arr [ i ] + arr [ j ] + arr [ k ]
            if sum > val :
                k -= 1
            else :
                ans += ( k - j )
                j += 1
    return ans
def countTriplets ( arr , n , a , b ) :
    res = 0
    res = ( countTripletsLessThan ( arr , n , b ) - countTripletsLessThan ( arr , n , a - 1 ) )
    return res
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 7 , 5 , 3 , 8 , 4 , 1 , 9 ]
    n = len ( arr )
    a = 8 ; b = 16
    print ( countTriplets ( arr , n , a , b ) )

Index/key variables: i, j, k
Accumulator variables: ans
Iterator variables: i
Python program:
def MaxTotalRectangleArea ( a , n ) :
    a . sort ( reverse = True )
    sum = 0
    flag = False
    len = 0
    i = 0
    while ( i < n - 1 ) :
        if ( i != 0 ) :
            i = i + 1
        if ( ( a [ i ] == a [ i + 1 ] or a [ i ] - a [ i + 1 ] == 1 ) and flag == False ) :
            flag = True
            len = a [ i + 1 ]
            i = i + 1
        elif ( ( a [ i ] == a [ i + 1 ] or a [ i ] - a [ i + 1 ] == 1 ) and flag == True ) :
            sum = sum + a [ i + 1 ] * len
            flag = False
            i = i + 1
    return sum
a = [ 10 , 10 , 10 , 10 , 11 , 10 , 11 , 10 , 9 , 9 , 8 , 8 ]
n = len ( a )
print ( MaxTotalRectangleArea ( a , n ) )

Index/key variables: i
Boolean variables: flag
Python program:
def evenOddInsertionSort ( arr , n ) :
    for i in range ( 2 , n ) :
        j = i - 2
        temp = arr [ i ]
        if ( ( i + 1 ) & 1 == 1 ) :
            while ( temp >= arr [ j ] and j >= 0 ) :
                arr [ j + 2 ] = arr [ j ]
                j -= 2
            arr [ j + 2 ] = temp
        else :
            while ( temp <= arr [ j ] and j >= 0 ) :
                arr [ j + 2 ] = arr [ j ]
                j -= 2
            arr [ j + 2 ] = temp
def printArray ( arr , n ) :
    for i in range ( 0 , n ) :
        print ( arr [ i ] , end = " ▁ " )
arr = [ 12 , 11 , 13 , 5 , 6 ]
n = len ( arr )
evenOddInsertionSort ( arr , n )
printArray ( arr , n )

Index/key variables: i, j
Iterator variables: i
Python program:
def print1 ( a , n ) :
    for i in range ( 0 , n + 1 ) :
        print ( a [ i ] , end = " ▁ " )
    print ( " " )
def sort ( a , n ) :
    for i in range ( n , 0 , - 1 ) :
        for j in range ( n , n - i , - 1 ) :
            if ( a [ j ] > a [ j - 1 ] ) :
                a [ j ] , a [ j - 1 ] = a [ j - 1 ] , a [ j ]
    print1 ( a , n )
n = 7
a = [ 2 , 4 , 3 , 2 , 4 , 5 , 3 ]
sort ( a , n - 1 )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def operations ( arr , n , k ) :
    arr . sort ( ) ;
    i = 0 ; sum = 0 ;
    while ( k > 0 ) :
        while ( i < n and arr [ i ] - sum == 0 ) :
            i += 1 ;
        if ( i < n and arr [ i ] - sum > 0 ) :
            print ( arr [ i ] - sum , end = " ▁ " ) ;
            sum = arr [ i ] ;
        else :
            print ( 0 ) ;
        k -= 1 ;
k = 5 ;
arr = [ 3 , 6 , 4 , 2 ] ;
n = len ( arr ) ;
operations ( arr , n , k ) ;

Index/key variables: i
Accumulator variables: k
Python program:
import math
def sort012 ( arr , n ) :
    count0 = 0
    count1 = 0
    count2 = 0
    for i in range ( 0 , n ) :
        if ( arr [ i ] == 0 ) :
            count0 = count0 + 1
        if ( arr [ i ] == 1 ) :
            count1 = count1 + 1
        if ( arr [ i ] == 2 ) :
            count2 = count2 + 1
    for i in range ( 0 , count0 ) :
        arr [ i ] = 0
    for i in range ( count0 , ( count0 + count1 ) ) :
        arr [ i ] = 1
    for i in range ( ( count0 + count1 ) , n ) :
        arr [ i ] = 2
    return
def printArray ( arr , n ) :
    for i in range ( 0 , n ) :
        print ( arr [ i ] , end = " ▁ " )
    print ( )
arr = [ 0 , 1 , 1 , 0 , 1 , 2 , 1 , 2 , 0 , 0 , 0 , 1 ]
n = len ( arr )
sort012 ( arr , n )
printArray ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
MAX = 26
def alternateSort ( s ) :
    n = len ( s )
    lCount = [ 0 for i in range ( MAX ) ]
    uCount = [ 0 for i in range ( MAX ) ]
    s = list ( s )
    for i in range ( n ) :
        if ( s [ i ] . isupper ( ) ) :
            uCount [ ord ( s [ i ] ) - ord ( ' A ' ) ] += 1
        else :
            lCount [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1
    i = 0
    j = 0
    k = 0
    while ( k < n ) :
        while ( i < MAX and uCount [ i ] == 0 ) :
            i += 1
        if ( i < MAX ) :
            s [ k ] = chr ( ord ( ' A ' ) + i )
            k += 1
            uCount [ i ] -= 1
        while ( j < MAX and lCount [ j ] == 0 ) :
            j += 1
        if ( j < MAX ) :
            s [ k ] = chr ( ord ( ' a ' ) + j )
            k += 1
            lCount [ j ] -= 1
    print ( " " . join ( s ) )
str = " bAwutndekWEdkd "
alternateSort ( str )

Index/key variables: i, j, k
Iterator variables: i
Python program:
def distancesum ( x , y , n ) :
    sum = 0
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            sum += ( abs ( x [ i ] - x [ j ] ) + abs ( y [ i ] - y [ j ] ) )
    return sum
x = [ - 1 , 1 , 3 , 2 ]
y = [ 5 , 6 , 5 , 3 ]
n = len ( x )
print ( distancesum ( x , y , n ) )

Index/key variables: i, j
Accumulator variables: sum
Iterator variables: i, j
Python program:
def distancesum ( arr , n ) :
    arr . sort ( )
    res = 0
    sum = 0
    for i in range ( n ) :
        res += ( arr [ i ] * i - sum )
        sum += arr [ i ]
    return res
def totaldistancesum ( x , y , n ) :
    return distancesum ( x , n ) + distancesum ( y , n )
x = [ - 1 , 1 , 3 , 2 ]
y = [ 5 , 6 , 5 , 3 ]
n = len ( x )
print ( totaldistancesum ( x , y , n ) )

Index/key variables: i
Accumulator variables: res, sum
Iterator variables: i
Python program:
def sortRec ( arr , index , k , n ) :
    if ( k == 0 ) :
        for i in range ( 1 , n ) :
            print ( arr [ i ] , end = " ▁ " )
        print ( 999 , end = " " )
    elif ( k > 0 and index == 0 ) :
        index = n - 2
        for i in range ( 1 , index + 1 ) :
            arr [ i - 1 ] = arr [ i ]
        arr [ index ] = 999
    if ( index - 1 >= 0 and index + 1 < n and arr [ index - 1 ] > arr [ index + 1 ] ) :
        arr [ index ] , arr [ index + 1 ] = arr [ index + 1 ] , arr [ index ]
        arr [ index - 1 ] , arr [ index + 1 ] = arr [ index + 1 ] , arr [ index - 1 ]
    else :
        if ( index - 1 < 0 ) :
            return
        arr [ index ] , arr [ index - 1 ] = arr [ index - 1 ] , arr [ index ]
    sortRec ( arr , index - 1 , k - 1 , n )
def sort ( arr , n ) :
    index = - 1
    for i in range ( n ) :
        if ( arr [ i ] == 999 ) :
            index = i
            break
    if ( index == - 1 ) :
        return
    sortRec ( arr , index , n , n )
arr = [ 3 , 2 , 999 , 1 ]
n = len ( arr )
sort ( arr , n )

Index/key variables: i, index
Iterator variables: i
Python program:
def unsort ( l , r , a , k ) :
    if ( k < 1 or l + 1 == r ) :
        return
    k -= 2
    mid = ( l + r ) // 2
    temp = a [ mid - 1 ]
    a [ mid - 1 ] = a [ mid ]
    a [ mid ] = temp
    unsort ( l , mid , a , k )
    unsort ( mid , r , a , k )
def arrayWithKCalls ( n , k ) :
    if ( k % 2 == 0 ) :
        print ( " NO ▁ SOLUTION " )
        return
    a = [ 0 for i in range ( n + 2 ) ]
    a [ 0 ] = 1
    for i in range ( 1 , n ) :
        a [ i ] = i + 1
    k -= 1
    unsort ( 0 , n , a , k )
    for i in range ( n ) :
        print ( a [ i ] , " ▁ " , end = " " )
n = 10
k = 17
arrayWithKCalls ( n , k )

Index/key variables: i, mid
Iterator variables: i
Python program:
MAX_CHAR = 26 ;
def sortString ( str ) :
    charCount = [ 0 ] * MAX_CHAR ;
    for i in range ( len ( str ) ) :
        charCount [ ord ( str [ i ] ) - ord ( ' a ' ) ] += 1 ;
    for i in range ( MAX_CHAR - 1 , - 1 , - 1 ) :
        for j in range ( charCount [ i ] ) :
            print ( chr ( 97 + i ) , end = " " ) ;
s = " alkasingh " ;
sortString ( s ) ;

Index/key variables: i
Iterator variables: i, j
Python program:
def dualPivotQuickSort ( arr , low , high ) :
    if low < high :
        lp , rp = partition ( arr , low , high )
        dualPivotQuickSort ( arr , low , lp - 1 )
        dualPivotQuickSort ( arr , lp + 1 , rp - 1 )
        dualPivotQuickSort ( arr , rp + 1 , high )
def partition ( arr , low , high ) :
    if arr [ low ] > arr [ high ] :
        arr [ low ] , arr [ high ] = arr [ high ] , arr [ low ]
    j = k = low + 1
    g , p , q = high - 1 , arr [ low ] , arr [ high ]
    while k <= g :
        if arr [ k ] < p :
            arr [ k ] , arr [ j ] = arr [ j ] , arr [ k ]
            j += 1
        elif arr [ k ] >= q :
            while arr [ g ] > q and k < g :
                g -= 1
            arr [ k ] , arr [ g ] = arr [ g ] , arr [ k ]
            g -= 1
            if arr [ k ] < p :
                arr [ k ] , arr [ j ] = arr [ j ] , arr [ k ]
                j += 1
        k += 1
    j -= 1
    g += 1
    arr [ low ] , arr [ j ] = arr [ j ] , arr [ low ]
    arr [ high ] , arr [ g ] = arr [ g ] , arr [ high ]
    return j , g
arr = [ 24 , 8 , 42 , 75 , 29 , 77 , 38 , 57 ]
dualPivotQuickSort ( arr , 0 , 7 )
print ( ' Sorted ▁ array : ▁ ' , end = ' ' )
for i in arr :
    print ( i , end = ' ▁ ' )
print ( )

Index/key variables: g, high, j, k, low
Iterator variables: i
Python program:
def minMaxSelectionSort ( arr , n ) :
    i = 0
    j = n - 1
    while ( i < j ) :
        min = arr [ i ]
        max = arr [ i ]
        min_i = i
        max_i = i
        for k in range ( i , j + 1 , 1 ) :
            if ( arr [ k ] > max ) :
                max = arr [ k ]
                max_i = k
            elif ( arr [ k ] < min ) :
                min = arr [ k ]
                min_i = k
        temp = arr [ i ]
        arr [ i ] = arr [ min_i ]
        arr [ min_i ] = temp
        if ( arr [ min_i ] == max ) :
            temp = arr [ j ]
            arr [ j ] = arr [ min_i ]
            arr [ min_i ] = temp
        else :
            temp = arr [ j ]
            arr [ j ] = arr [ max_i ]
            arr [ max_i ] = temp
        i += 1
        j -= 1
    print ( " Sorted ▁ array : " , end = " ▁ " )
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 23 , 78 , 45 , 8 , 32 , 56 , 1 ]
    n = len ( arr )
    minMaxSelectionSort ( arr , n )

Index/key variables: i, j, k, max_i, min_i
Iterator variables: i, k
Python program:
def arrange ( arr , n , x ) :
    for i in range ( 1 , n ) :
        diff = abs ( arr [ i ] - x )
        j = i - 1
        if ( abs ( arr [ j ] - x ) > diff ) :
            temp = arr [ i ]
            while ( abs ( arr [ j ] - x ) > diff and j >= 0 ) :
                arr [ j + 1 ] = arr [ j ]
                j -= 1
            arr [ j + 1 ] = temp
def print_1 ( arr , n ) :
    for i in range ( n ) :
        print ( arr [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ 10 , 5 , 3 , 9 , 2 ]
    n = len ( arr )
    x = 7
    arrange ( arr , n , x )
    print_1 ( arr , n )

Index/key variables: i, j
Iterator variables: i
Python program:
def printOrder ( arr , n ) :
    arr . sort ( )
    for i in range ( n // 2 ) :
        print ( arr [ i ] , end = " ▁ " )
    for j in range ( n - 1 , n // 2 - 1 , - 1 ) :
        print ( arr [ j ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ 5 , 4 , 6 , 2 , 1 , 3 , 8 , - 1 ]
    n = len ( arr )
    printOrder ( arr , n )

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