dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def getTotalNumberOfSequences ( m , n ) :
    T = [ [ 0 for i in range ( n + 1 ) ] for i in range ( m + 1 ) ]
    for i in range ( m + 1 ) :
        for j in range ( n + 1 ) :
            if i == 0 or j == 0 :
                T [ i ] [ j ] = 0
            elif i < j :
                T [ i ] [ j ] = 0
            elif j == 1 :
                T [ i ] [ j ] = i
            else :
                T [ i ] [ j ] = T [ i - 1 ] [ j ] + T [ i // 2 ] [ j - 1 ]
    return T [ m ] [ n ]
if __name__ == ' _ _ main _ _ ' :
    m = 10
    n = 4
    print ( ' Total ▁ number ▁ of ▁ possible ▁ sequences ▁ ' , getTotalNumberOfSequences ( m , n ) )

Index/key variables: i, j, m, n
Iterator variables: i, j
Python program:
def lcs ( str1 , str2 , m , n ) :
    L = [ [ 0 for i in range ( n + 1 ) ] for i in range ( m + 1 ) ]
    for i in range ( m + 1 ) :
        for j in range ( n + 1 ) :
            if ( i == 0 or j == 0 ) :
                L [ i ] [ j ] = 0
            elif ( str1 [ i - 1 ] == str2 [ j - 1 ] ) :
                L [ i ] [ j ] = L [ i - 1 ] [ j - 1 ] + 1
            else :
                L [ i ] [ j ] = max ( L [ i - 1 ] [ j ] , L [ i ] [ j - 1 ] )
    return L [ m ] [ n ]
def printMinDelAndInsert ( str1 , str2 ) :
    m = len ( str1 )
    n = len ( str2 )
    leng = lcs ( str1 , str2 , m , n )
    print ( " Minimum ▁ number ▁ of ▁ deletions ▁ = ▁ " , m - leng , sep = ' ▁ ' )
    print ( " Minimum ▁ number ▁ of ▁ insertions ▁ = ▁ " , n - leng , sep = ' ▁ ' )
str1 = " heap "
str2 = " pea "
printMinDelAndInsert ( str1 , str2 )

Index/key variables: i, j, m, n
Iterator variables: i, j
Python program:
def lis ( arr , n ) :
    result = 0
    lis = [ 0 for i in range ( n ) ]
    for i in range ( n ) :
        lis [ i ] = 1
    for i in range ( 1 , n ) :
        for j in range ( i ) :
            if ( arr [ i ] > arr [ j ] and lis [ i ] < lis [ j ] + 1 ) :
                lis [ i ] = lis [ j ] + 1
    for i in range ( n ) :
        if ( result < lis [ i ] ) :
            result = lis [ i ]
    return result
def minimumNumberOfDeletions ( arr , n ) :
    len = lis ( arr , n )
    return ( n - len )
arr = [ 30 , 40 , 2 , 5 , 1 , 7 , 45 , 50 , 8 ]
n = len ( arr )
print ( " Minimum ▁ number ▁ of ▁ deletions ▁ = ▁ " , minimumNumberOfDeletions ( arr , n ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
inf = 1000000000 ;
def minCost ( a , n , k ) :
    dp = [ [ inf for i in range ( k + 1 ) ] for j in range ( n + 1 ) ] ;
    dp [ 0 ] [ 0 ] = 0 ;
    for i in range ( 1 , n + 1 ) :
        for j in range ( 1 , k + 1 ) :
            for m in range ( i - 1 , - 1 , - 1 ) :
                dp [ i ] [ j ] = min ( dp [ i ] [ j ] , dp [ m ] [ j - 1 ] + ( a [ i - 1 ] - a [ m ] ) * ( a [ i - 1 ] - a [ m ] ) ) ;
    return dp [ n ] [ k ] ;
if __name__ == ' _ _ main _ _ ' :
    k = 2 ;
    a = [ 1 , 5 , 8 , 10 ] ;
    n = len ( a ) ;
    print ( minCost ( a , n , k ) ) ;

Index/key variables: i, j, k, m, n
Iterator variables: i, j, m
Python program:
def offeringNumber ( n , templeHeight ) :
    for i in range ( n ) :
        left = 0
        right = 0
        for j in range ( i - 1 , - 1 , - 1 ) :
            if ( templeHeight [ j ] < templeHeight [ j + 1 ] ) :
                left += 1
            else :
                break
        for j in range ( i + 1 , n ) :
            if ( templeHeight [ j ] < templeHeight [ j - 1 ] ) :
                right += 1
            else :
                break
        sum += max ( right , left ) + 1
    return sum
arr1 = [ 1 , 2 , 2 ]
print ( offeringNumber ( 3 , arr1 ) )
arr2 = [ 1 , 4 , 3 , 6 , 2 , 1 ]
print ( offeringNumber ( 6 , arr2 ) )

Index/key variables: j
Accumulator variables: left, right, sum
Iterator variables: i, j
Python program:
def modularSum ( arr , n , m ) :
    if ( n > m ) :
        return True
    DP = [ False for i in range ( m ) ]
    for i in range ( n ) :
        if ( DP [ 0 ] ) :
            return True
        temp = [ False for i in range ( m ) ]
        for j in range ( m ) :
            if ( DP [ j ] == True ) :
                if ( DP [ ( j + arr [ i ] ) % m ] == False ) :
                    temp [ ( j + arr [ i ] ) % m ] = True
        for j in range ( m ) :
            if ( temp [ j ] ) :
                DP [ j ] = True
        DP [ arr [ i ] % m ] = True
    return DP [ 0 ]
arr = [ 1 , 7 ]
n = len ( arr )
m = 5
print ( " YES " ) if ( modularSum ( arr , n , m ) ) else print ( " NO " )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def maximumDifferenceSum ( arr , N ) :
    dp = [ [ 0 , 0 ] for i in range ( N ) ]
    for i in range ( N ) :
        dp [ i ] [ 0 ] = dp [ i ] [ 1 ] = 0
    for i in range ( N - 1 ) :
        dp [ i + 1 ] [ 0 ] = max ( dp [ i ] [ 0 ] , dp [ i ] [ 1 ] + abs ( 1 - arr [ i ] ) )
        dp [ i + 1 ] [ 1 ] = max ( dp [ i ] [ 0 ] + abs ( arr [ i + 1 ] - 1 ) , dp [ i ] [ 1 ] + abs ( arr [ i + 1 ] - arr [ i ] ) )
    return max ( dp [ N - 1 ] [ 0 ] , dp [ N - 1 ] [ 1 ] )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 2 , 1 , 4 , 5 ]
    N = len ( arr )
    print ( maximumDifferenceSum ( arr , N ) )

Index/key variables: i
Iterator variables: i
Python program:
def countStrUtil ( dp , n , bCount = 1 , cCount = 2 ) :
    if ( bCount < 0 or cCount < 0 ) :
        return 0
    if ( n == 0 ) :
        return 1
    if ( bCount == 0 and cCount == 0 ) :
        return 1
    if ( dp [ n ] [ bCount ] [ cCount ] != - 1 ) :
        return dp [ n ] [ bCount ] [ cCount ]
    res = countStrUtil ( dp , n - 1 , bCount , cCount )
    res += countStrUtil ( dp , n - 1 , bCount - 1 , cCount )
    res += countStrUtil ( dp , n - 1 , bCount , cCount - 1 )
    dp [ n ] [ bCount ] [ cCount ] = res
    return dp [ n ] [ bCount ] [ cCount ]
def countStr ( n ) :
    dp = [ [ [ - 1 for x in range ( n + 2 ) ] for y in range ( 3 ) ] for z in range ( 4 ) ]
    return countStrUtil ( dp , n )
if __name__ == " _ _ main _ _ " :
    n = 3
    print ( countStr ( n ) )

Index/key variables: bCount, cCount, n
Python program:
N = 8
dx = [ 1 , 2 , 2 , 1 , - 1 , - 2 , - 2 , - 1 ]
dy = [ 2 , 1 , - 1 , - 2 , - 2 , - 1 , 1 , 2 ]
def inside ( x , y ) :
    return ( x >= 0 and x < N and y >= 0 and y < N )
def findProb ( start_x , start_y , steps ) :
    dp1 = [ [ [ 0 for i in range ( N + 5 ) ] for j in range ( N + 5 ) ] for k in range ( steps + 5 ) ]
    for i in range ( N ) :
        for j in range ( N ) :
            dp1 [ i ] [ j ] [ 0 ] = 1
    for s in range ( 1 , steps + 1 ) :
        for x in range ( N ) :
            for y in range ( N ) :
                prob = 0.0
                for i in range ( 8 ) :
                    nx = x + dx [ i ]
                    ny = y + dy [ i ]
                    if ( inside ( nx , ny ) ) :
                        prob += dp1 [ nx ] [ ny ] [ s - 1 ] / 8.0
                dp1 [ x ] [ y ] [ s ] = prob
    return dp1 [ start_x ] [ start_y ] [ steps ]
K = 3
print ( findProb ( 0 , 0 , K ) )

Index/key variables: i, j, nx, ny, s, start_x, start_y, steps, x, y
Accumulator variables: prob
Iterator variables: i, j, s, x, y
Python program:
def countSubarray ( arr , n , k ) :
    s = 0
    i = 0
    while ( i < n ) :
        if ( arr [ i ] > k ) :
            i = i + 1
            continue
        count = 0
        while ( i < n and arr [ i ] <= k ) :
            i = i + 1
            count = count + 1
        s = s + ( ( count * ( count + 1 ) ) // 2 )
    return ( n * ( n + 1 ) // 2 - s )
arr = [ 1 , 2 , 3 ]
k = 2
n = len ( arr )
print ( countSubarray ( arr , n , k ) )

Index/key variables: i
Python program:
def nCr ( n , k ) :
    C = [ [ 0 for i in range ( k + 1 ) ] for j in range ( n + 1 ) ]
    for i in range ( n + 1 ) :
        for j in range ( min ( i , k ) + 1 ) :
            if ( j == 0 or j == i ) :
                C [ i ] [ j ] = 1
            else :
                C [ i ] [ j ] = C [ i - 1 ] [ j - 1 ] + C [ i - 1 ] [ j ]
    return C [ n ] [ k ]
def resultOfAllSubsets ( arr , N ) :
    sum = 0
    for i in range ( N ) :
        sum += arr [ i ]
    for n in range ( 1 , N + 1 ) :
        result += ( sum * ( nCr ( N - 1 , n - 1 ) ) ) / n
    return result
arr = [ 2 , 3 , 5 , 7 ]
N = len ( arr )
print ( resultOfAllSubsets ( arr , N ) )

Index/key variables: i, j, k, n
Accumulator variables: result, sum
Iterator variables: i, j, n
Python program:
arr = [ 100 , 1000 , 100 , 1000 , 1 ]
sum = [ - 1 ] * 10000
def maxSumWO3Consec ( n ) :
    if ( sum [ n ] != - 1 ) :
        return sum [ n ]
    if ( n == 0 ) :
        sum [ n ] = 0
        return sum [ n ]
    if ( n == 1 ) :
        sum [ n ] = arr [ 0 ]
        return sum [ n ]
    if ( n == 2 ) :
        sum [ n ] = arr [ 1 ] + arr [ 0 ]
        return sum [ n ]
    sum [ n ] = max ( max ( maxSumWO3Consec ( n - 1 ) , maxSumWO3Consec ( n - 2 ) + arr [ n ] ) , arr [ n ] + arr [ n - 1 ] + maxSumWO3Consec ( n - 3 ) )
    return sum [ n ]
if __name__ == " _ _ main _ _ " :
    n = len ( arr )
    print ( maxSumWO3Consec ( n ) )

Index/key variables: n
Python program:
def maxSumPairWithDifferenceLessThanK ( arr , N , k ) :
    maxSum = 0
    arr . sort ( )
    i = N - 1
    while ( i > 0 ) :
        if ( arr [ i ] - arr [ i - 1 ] < k ) :
            maxSum += arr [ i ]
            maxSum += arr [ i - 1 ]
            i -= 1
        i -= 1
    return maxSum
arr = [ 3 , 5 , 10 , 15 , 17 , 12 , 9 ]
N = len ( arr )
K = 4
print ( maxSumPairWithDifferenceLessThanK ( arr , N , K ) )

Index/key variables: i
Accumulator variables: maxSum
Python program:
def countGroups ( position , previous_sum , length , num ) :
    if ( position == length ) :
        return 1
    res = 0
    sum = 0
    for i in range ( position , length ) :
        sum = sum + int ( num [ i ] )
        if ( sum >= previous_sum ) :
            res = res + countGroups ( i + 1 , sum , length , num )
    return res
if __name__ == ' _ _ main _ _ ' :
    num = "1119"
    len = len ( num )
    print ( countGroups ( 0 , 0 , len , num ) )

Index/key variables: i
Iterator variables: i
Python program:
MAX = 40
dp = [ [ - 1 for i in range ( 9 * MAX + 1 ) ] for i in range ( MAX ) ]
def countGroups ( position , previous_sum , length , num ) :
    if ( position == length ) :
        return 1
    if ( dp [ position ] [ previous_sum ] != - 1 ) :
        return dp [ position ] [ previous_sum ]
    dp [ position ] [ previous_sum ] = 0
    res = 0
    sum = 0
    for i in range ( position , length ) :
        sum += ( ord ( num [ i ] ) - ord ( '0' ) )
        if ( sum >= previous_sum ) :
            res += countGroups ( i + 1 , sum , length , num )
    dp [ position ] [ previous_sum ] = res
    return res
num = "1119"
len = len ( num )
print ( countGroups ( 0 , 0 , len , num ) )

Index/key variables: i, position, previous_sum
Accumulator variables: res, sum
Iterator variables: i
Python program:
def KnapSack ( val , wt , n , W ) :
    dp = [ 0 ] * ( W + 1 ) ;
    for i in range ( n ) :
        for j in range ( W , wt [ i ] , - 1 ) :
            dp [ j ] = max ( dp [ j ] , val [ i ] + dp [ j - wt [ i ] ] ) ;
    return dp [ W ] ;
val = [ 7 , 8 , 4 ] ;
wt = [ 3 , 8 , 6 ] ;
W = 10 ; n = 3 ;
print ( KnapSack ( val , wt , n , W ) ) ;

Index/key variables: W, i, j
Iterator variables: i, j
Python program:
def count ( a , b ) :
    m = len ( a )
    n = len ( b )
    lookup = [ [ 0 ] * ( n + 1 ) for i in range ( m + 1 ) ]
    for i in range ( n + 1 ) :
        lookup [ 0 ] [ i ] = 0
    for i in range ( m + 1 ) :
        lookup [ i ] [ 0 ] = 1
    for i in range ( 1 , m + 1 ) :
        for j in range ( 1 , n + 1 ) :
            if a [ i - 1 ] == b [ j - 1 ] :
                lookup [ i ] [ j ] = lookup [ i - 1 ] [ j - 1 ] + lookup [ i - 1 ] [ j ]
            else :
                lookup [ i ] [ j ] = lookup [ i - 1 ] [ j ]
    return lookup [ m ] [ n ]
if __name__ == ' _ _ main _ _ ' :
    a = " GeeksforGeeks "
    b = " Gks "
    print ( count ( a , b ) )

Index/key variables: i, j, m, n
Iterator variables: i, j
Python program:
def lenOfLongestGP ( sett , n ) :
    if n < 2 :
        return n
    if n == 2 :
        return 2 if ( sett [ 1 ] % sett [ 0 ] == 0 ) else 1
    sett . sort ( )
    L = [ [ 0 for i in range ( n ) ] for i in range ( n ) ]
    llgp = 1
    for i in range ( 0 , n - 1 ) :
        if sett [ n - 1 ] % sett [ i ] == 0 :
            L [ i ] [ n - 1 ] = 2
            if 2 > llgp :
                llgp = 2
        else :
            L [ i ] [ n - 1 ] = 1
    L [ n - 1 ] [ n - 1 ] = 1
    for j in range ( n - 2 , 0 , - 1 ) :
        i = j - 1
        k = j + 1
        while i >= 0 and k <= n - 1 :
            if sett [ i ] * sett [ k ] < sett [ j ] * sett [ j ] :
                k += 1
            elif sett [ i ] * sett [ k ] > sett [ j ] * sett [ j ] :
                if sett [ j ] % sett [ i ] == 0 :
                    L [ i ] [ j ] = 2
                else :
                    L [ i ] [ j ] = 1
                i -= 1
            else :
                if sett [ j ] % sett [ i ] == 0 :
                    L [ i ] [ j ] = L [ j ] [ k ] + 1
                    if L [ i ] [ j ] > llgp :
                        llgp = L [ i ] [ j ]
                else :
                    L [ i ] [ j ] = 1
                i -= 1
                k += 1
        while i >= 0 :
            if sett [ j ] % sett [ i ] == 0 :
                L [ i ] [ j ] = 2
            else :
                L [ i ] [ j ] = 1
            i -= 1
    return llgp
if __name__ == ' _ _ main _ _ ' :
    set1 = [ 1 , 3 , 9 , 27 , 81 , 243 ]
    n1 = len ( set1 )
    print ( lenOfLongestGP ( set1 , n1 ) )
    set2 = [ 1 , 3 , 4 , 9 , 7 , 27 ]
    n2 = len ( set2 )
    print ( lenOfLongestGP ( set2 , n2 ) )
    set3 = [ 2 , 3 , 5 , 7 , 11 , 13 ]
    n3 = len ( set3 )
    print ( lenOfLongestGP ( set3 , n3 ) )

Index/key variables: i, j, k
Iterator variables: i, j
Python program:
class Pair :
    def __init__ ( self , a , b ) :
        self . a = a
        self . b = b
    def __lt__ ( self , other ) :
        return self . a < other . a
def maxChainLength ( arr ) :
    arr . sort ( )
    L = [ [ ] for x in range ( len ( arr ) ) ]
    L [ 0 ] . append ( arr [ 0 ] )
    for i in range ( 1 , len ( arr ) ) :
        for j in range ( i ) :
            if ( arr [ j ] . b < arr [ i ] . a and len ( L [ j ] ) > len ( L [ i ] ) ) :
                L [ i ] = L [ j ]
        L [ i ] . append ( arr [ i ] )
    maxChain = [ ]
    for x in L :
        if len ( x ) > len ( maxChain ) :
            maxChain = x
    for pair in maxChain :
        print ( " ( { a } , { b } ) " . format ( a = pair . a , b = pair . b ) , end = " ▁ " )
    print ( )
if __name__ == " _ _ main _ _ " :
    arr = [ Pair ( 5 , 29 ) , Pair ( 39 , 40 ) , Pair ( 15 , 28 ) , Pair ( 27 , 40 ) , Pair ( 50 , 90 ) ]
    n = len ( arr )
    maxChainLength ( arr )

Index/key variables: i, j
Iterator variables: i, j, pair, x
Class/struct names: Pair
Python program:
def _print ( arr : list , size : int ) :
    for i in range ( size ) :
        print ( arr [ i ] , end = " ▁ " )
def printLBS ( arr : list , n : int ) :
    LIS = [ 0 ] * n
    for i in range ( n ) :
        LIS [ i ] = [ ]
    LIS [ 0 ] . append ( arr [ 0 ] )
    for i in range ( 1 , n ) :
        for j in range ( i ) :
            if ( ( arr [ j ] < arr [ i ] ) and ( len ( LIS [ j ] ) > len ( LIS [ i ] ) ) ) :
                LIS [ i ] = LIS [ j ] . copy ( )
        LIS [ i ] . append ( arr [ i ] )
    LDS = [ 0 ] * n
    for i in range ( n ) :
        LDS [ i ] = [ ]
    LDS [ n - 1 ] . append ( arr [ n - 1 ] )
    for i in range ( n - 2 , - 1 , - 1 ) :
        for j in range ( n - 1 , i , - 1 ) :
            if ( ( arr [ j ] < arr [ i ] ) and ( len ( LDS [ j ] ) > len ( LDS [ i ] ) ) ) :
                LDS [ i ] = LDS [ j ] . copy ( )
        LDS [ i ] . append ( arr [ i ] )
    for i in range ( n ) :
        LDS [ i ] = list ( reversed ( LDS [ i ] ) )
    max = 0
    maxIndex = - 1
    for i in range ( n ) :
        if ( len ( LIS [ i ] ) + len ( LDS [ i ] ) - 1 > max ) :
            max = len ( LIS [ i ] ) + len ( LDS [ i ] ) - 1
            maxIndex = i
    _print ( LIS [ maxIndex ] , len ( LIS [ maxIndex ] ) - 1 )
    _print ( LDS [ maxIndex ] , len ( LDS [ maxIndex ] ) )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 11 , 2 , 10 , 4 , 5 , 2 , 1 ]
    n = len ( arr )
    printLBS ( arr , n )

Index/key variables: i, j, maxIndex
Iterator variables: i, j
Python program:
def lcs ( X , Y ) :
    m = len ( X )
    n = len ( Y )
    L = [ [ 0 for i in range ( n + 1 ) ] for j in range ( 2 ) ]
    bi = bool
    for i in range ( m ) :
        bi = i & 1
        for j in range ( n + 1 ) :
            if ( i == 0 or j == 0 ) :
                L [ bi ] [ j ] = 0
            elif ( X [ i ] == Y [ j - 1 ] ) :
                L [ bi ] [ j ] = L [ 1 - bi ] [ j - 1 ] + 1
            else :
                L [ bi ] [ j ] = max ( L [ 1 - bi ] [ j ] , L [ bi ] [ j - 1 ] )
    return L [ bi ] [ n ]
X = " AGGTAB "
Y = " GXTXAYB "
print ( " Length ▁ of ▁ LCS ▁ is " , lcs ( X , Y ) )

Index/key variables: bi, i, j, n
Iterator variables: i, j
Python program:
import sys
def findMin ( a , n ) :
    su = 0
    su = sum ( a )
    dp = [ [ 0 for i in range ( su + 1 ) ] for j in range ( n + 1 ) ]
    for i in range ( n + 1 ) :
        dp [ i ] [ 0 ] = True
    for j in range ( 1 , su + 1 ) :
        dp [ 0 ] [ j ] = False
    for i in range ( 1 , n + 1 ) :
        for j in range ( 1 , su + 1 ) :
            dp [ i ] [ j ] = dp [ i - 1 ] [ j ]
            if a [ i - 1 ] <= j :
                dp [ i ] [ j ] |= dp [ i - 1 ] [ j - a [ i - 1 ] ]
    diff = sys . maxsize
    for j in range ( su // 2 , - 1 , - 1 ) :
        if dp [ n ] [ j ] == True :
            diff = su - ( 2 * j )
            break
    return diff
a = [ 3 , 1 , 4 , 2 , 2 , 1 ]
n = len ( a )
print ( " The ▁ minimum ▁ difference ▁ between ▁ " "2 ▁ sets ▁ is ▁ " , findMin ( a , n ) )

Index/key variables: i, j, n
Iterator variables: i, j
Python program:
MAX = 100
dp = [ [ [ [ - 1 for col in range ( 2 ) ] for col in range ( MAX ) ] for row in range ( MAX ) ] for row in range ( MAX ) ]
def countPathsUtil ( i , j , k , d ) :
    if ( i < 0 or j < 0 ) :
        return 0
    if ( i == 0 and j == 0 ) :
        return 1
    if ( k == 0 ) :
        if ( d == 0 and i == 0 ) :
            return 1
        if ( d == 1 and j == 0 ) :
            return 1
        return 0
    if ( dp [ i ] [ j ] [ k ] [ d ] != - 1 ) :
        return dp [ i ] [ j ] [ k ] [ d ]
    if ( d == 0 ) :
        dp [ i ] [ j ] [ k ] [ d ] = countPathsUtil ( i , j - 1 , k , d ) + countPathsUtil ( i - 1 , j , k - 1 , not d )
        return dp [ i ] [ j ] [ k ] [ d ]
    dp [ i ] [ j ] [ k ] [ d ] = countPathsUtil ( i - 1 , j , k , d ) + countPathsUtil ( i , j - 1 , k - 1 , not d )
    return dp [ i ] [ j ] [ k ] [ d ]
def countPaths ( i , j , k ) :
    if ( i == 0 and j == 0 ) :
        return 1
    return countPathsUtil ( i - 1 , j , k , 1 ) + countPathsUtil ( i , j - 1 , k , 0 )
if __name__ == ' _ _ main _ _ ' :
    m = 3
    n = 3
    k = 2
    print ( " Number ▁ of ▁ paths ▁ is " , countPaths ( m - 1 , n - 1 , k ) )

Index/key variables: d, i, j, k
Python program:
MAX = 1000
dp = [ [ - 1 for i in range ( MAX ) ] for i in range ( MAX ) ]
def minSizeRec ( arr , low , high , k ) :
    if dp [ low ] [ high ] != - 1 :
        return dp [ low ] [ high ]
    if ( high - low + 1 ) < 3 :
        return ( high - low + 1 )
    res = 1 + minSizeRec ( arr , low + 1 , high , k )
    for i in range ( low + 1 , high ) :
        for j in range ( i + 1 , high + 1 ) :
            if ( arr [ i ] == ( arr [ low ] + k ) and arr [ j ] == ( arr [ low ] + 2 * k ) and minSizeRec ( arr , low + 1 , i - 1 , k ) == 0 and minSizeRec ( arr , i + 1 , j - 1 , k ) == 0 ) :
                res = min ( res , minSizeRec ( arr , j + 1 , high , k ) )
    dp [ low ] [ high ] = res
    return res
def minSize ( arr , n , k ) :
    dp = [ [ - 1 for i in range ( MAX ) ] for i in range ( MAX ) ]
    return minSizeRec ( arr , 0 , n - 1 , k )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 3 , 4 , 5 , 6 , 4 ]
    n = len ( arr )
    k = 1
    print ( minSize ( arr , n , k ) )

Index/key variables: high, i, j, low
Iterator variables: i, j
Python program:
def countSol ( coeff , start , end , rhs ) :
    if ( rhs == 0 ) :
        return 1
    result = 0
    for i in range ( start , end + 1 ) :
        if ( coeff [ i ] <= rhs ) :
            result += countSol ( coeff , i , end , rhs - coeff [ i ] )
    return result
coeff = [ 2 , 2 , 5 ]
rhs = 4
n = len ( coeff )
print ( countSol ( coeff , 0 , n - 1 , rhs ) )

Index/key variables: i
Accumulator variables: result
Iterator variables: i
Python program:
def getMaxRec ( string , i , n , lookup ) :
    if i >= n :
        return 0
    if lookup [ i ] != - 1 :
        return lookup [ i ]
    ans = 1 + getMaxRec ( string , i + 1 , n , lookup )
    if i + 1 < n :
        if string [ i ] != string [ i + 1 ] :
            ans = max ( 4 + getMaxRec ( string , i + 2 , n , lookup ) , ans )
        else :
            ans = max ( 3 + getMaxRec ( string , i + 2 , n , lookup ) , ans )
    lookup [ i ] = ans
    return ans
def getMaxWeight ( string ) :
    n = len ( string )
    lookup = [ - 1 ] * ( n )
    return getMaxRec ( string , 0 , len ( string ) , lookup )
if __name__ == " _ _ main _ _ " :
    string = " AAAAABB "
    print ( " Maximum ▁ weight ▁ of ▁ a ▁ transformation ▁ of " , string , " is " , getMaxWeight ( string ) )

Index/key variables: i
Python program:
def possibleEqualArray ( A , N ) :
    tot_XOR = 0
    for i in range ( N ) :
        tot_XOR ^= A [ i ]
    if ( tot_XOR == 0 ) :
        print ( " YES " )
        return
    cur_XOR = 0
    cnt = 0
    for i in range ( N ) :
        cur_XOR ^= A [ i ]
        if ( cur_XOR == tot_XOR ) :
            cnt += 1
            cur_XOR = 0
    if ( cnt > 2 ) :
        print ( " YES " )
    else :
        print ( " NO " )
if __name__ == ' _ _ main _ _ ' :
    A = [ 0 , 2 , 2 ]
    N = len ( A )
    possibleEqualArray ( A , N )

Index/key variables: i
Accumulator variables: cnt, cur_XOR, tot_XOR
Iterator variables: i
Python program:
def countPalindrome ( S ) :
    N = len ( S )
    Z = [ 0 ] * N
    l = 0
    r = 0
    for i in range ( 1 , N ) :
        if i <= r :
            Z [ i ] = min ( r - i + 1 , Z [ i - 1 ] )
        while ( ( i + Z [ i ] ) < N and ( S [ Z [ i ] ] == S [ i + Z [ i ] ] ) ) :
            Z [ i ] += 1
        if ( ( i + Z [ i ] - 1 ) > r ) :
            l = ir = i + Z [ i ] - 1
    sum = 0
    for i in range ( 0 , len ( Z ) ) :
        sum += Z [ i ] + 1
    return sum
S = " abab "
print ( countPalindrome ( S ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def printSubsInDelimeters ( string ) :
    dels = [ ] ;
    for i in range ( len ( string ) ) :
        if ( string [ i ] == ' [ ' ) :
            dels . append ( i ) ;
        elif ( string [ i ] == ' ] ' and len ( dels ) != 0 ) :
            pos = dels [ - 1 ] ;
            dels . pop ( ) ;
            length = i - 1 - pos ;
            ans = string [ pos + 1 : pos + 1 + length ] ;
            print ( ans ) ;
if __name__ == " _ _ main _ _ " :
    string = " [ This ▁ is ▁ first ] ▁ ignored ▁ text ▁ [ This ▁ is ▁ second ] " ;
    printSubsInDelimeters ( string ) ;

Index/key variables: i
Accumulator variables: dels
Iterator variables: i
Python program:
def printDiagonalTraversal ( nums ) :
    m = len ( nums )
    q = [ ]
    q . append ( [ 0 , 0 ] )
    while ( len ( q ) != 0 ) :
        p = q [ 0 ]
        q . pop ( 0 ) ;
        print ( nums [ p [ 0 ] ] [ p [ 1 ] ] , end = " ▁ " )
        if ( p [ 1 ] == 0 and p [ 0 ] + 1 < m ) :
            q . append ( [ p [ 0 ] + 1 , p [ 1 ] ] ) ;
        if ( p [ 1 ] + 1 < len ( nums [ p [ 0 ] ] ) ) :
            q . append ( [ p [ 0 ] , p [ 1 ] + 1 ] ) ;
if __name__ == " _ _ main _ _ " :
    arr = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ]
    printDiagonalTraversal ( arr ) ;

Accumulator variables: q