dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def findMaxVal ( arr , n , num , maxLimit ) :
    ind = - 1 ;
    val = - 1 ;
    dp = [ [ 0 for i in range ( maxLimit + 1 ) ] for j in range ( n ) ] ;
    for ind in range ( n ) :
        for val in range ( maxLimit + 1 ) :
            if ( ind == 0 ) :
                if ( num - arr [ ind ] == val or num + arr [ ind ] == val ) :
                    dp [ ind ] [ val ] = 1 ;
                else :
                    dp [ ind ] [ val ] = 0 ;
            else :
                if ( val - arr [ ind ] >= 0 and val + arr [ ind ] <= maxLimit ) :
                    if ( dp [ ind - 1 ] [ val - arr [ ind ] ] == 1 or dp [ ind - 1 ] [ val + arr [ ind ] ] == 1 ) :
                        dp [ ind ] [ val ] = 1 ;
                elif ( val - arr [ ind ] >= 0 ) :
                    dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ] ;
                elif ( val + arr [ ind ] <= maxLimit ) :
                    dp [ ind ] [ val ] = dp [ ind - 1 ] [ val + arr [ ind ] ] ;
                else :
                    dp [ ind ] [ val ] = 0 ;
    for val in range ( maxLimit , - 1 , - 1 ) :
        if ( dp [ n - 1 ] [ val ] == 1 ) :
            return val ;
    return - 1 ;
if __name__ == ' _ _ main _ _ ' :
    num = 1 ;
    arr = [ 3 , 10 , 6 , 4 , 5 ] ;
    n = len ( arr ) ;
    maxLimit = 15 ;
    print ( findMaxVal ( arr , n , num , maxLimit ) ) ;

Index/key variables: ind, val
Iterator variables: ind, val
Python program:
def gen ( n ) :
    if n == 0 :
        return 0
    elif n == 1 :
        return 1
    elif n % 2 == 0 :
        return 4 * gen ( n // 2 )
    elif n % 2 == 1 :
        return 4 * gen ( n // 2 ) + 1
def moserDeBruijn ( n ) :
    for i in range ( n ) :
        print ( gen ( i ) , end = " ▁ " )
n = 15
print ( " First " , n , " terms ▁ of ▁ " , " Moser - de ▁ Bruijn ▁ Sequence : " )
moserDeBruijn ( n )

Iterator variables: i
Python program:
def minSumPath ( A ) :
    memo = [ None ] * len ( A )
    n = len ( A ) - 1
    for i in range ( len ( A [ n ] ) ) :
        memo [ i ] = A [ n ] [ i ]
    for i in range ( len ( A ) - 2 , - 1 , - 1 ) :
        for j in range ( len ( A [ i ] ) ) :
            memo [ j ] = A [ i ] [ j ] + min ( memo [ j ] , memo [ j + 1 ] ) ;
    return memo [ 0 ]
A = [ [ 2 ] , [ 3 , 9 ] , [ 1 , 6 , 7 ] ]
print ( minSumPath ( A ) )

Index/key variables: i, j, n
Iterator variables: i, j
Python program:
MAX = 100
dp = [ [ 0 for i in range ( MAX ) ] for i in range ( MAX ) ]
for i in range ( 0 , MAX ) :
    for j in range ( 0 , MAX ) :
        dp [ i ] [ j ] = - 1
def countRemovals ( a , i , j , k ) :
    global dp
    if ( i >= j ) :
        return 0
    elif ( ( a [ j ] - a [ i ] ) <= k ) :
        return 0
    elif ( dp [ i ] [ j ] != - 1 ) :
        return dp [ i ] [ j ]
    elif ( ( a [ j ] - a [ i ] ) > k ) :
        dp [ i ] [ j ] = 1 + min ( countRemovals ( a , i + 1 , j , k ) , countRemovals ( a , i , j - 1 , k ) )
    return dp [ i ] [ j ]
def removals ( a , n , k ) :
    a . sort ( )
    if ( n == 1 ) :
        return 0
    else :
        return countRemovals ( a , 0 , n - 1 , k )
a = [ 1 , 3 , 4 , 9 , 10 , 11 , 12 , 17 , 20 ]
n = len ( a )
k = 4
print ( removals ( a , n , k ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def findInd ( key , i , n , k , arr ) :
    ind = - 1
    start = i + 1
    end = n - 1 ;
    while ( start < end ) :
        mid = int ( start + ( end - start ) / 2 )
        if ( arr [ mid ] - key <= k ) :
            ind = mid
            start = mid + 1
        else :
            end = mid
    return ind
def removals ( arr , n , k ) :
    ans = n - 1
    arr . sort ( )
    for i in range ( 0 , n ) :
        j = findInd ( arr [ i ] , i , n , k , arr )
        if ( j != - 1 ) :
            ans = min ( ans , n - ( j - i + 1 ) )
    return ans
a = [ 1 , 3 , 4 , 9 , 10 , 11 , 12 , 17 , 20 ]
n = len ( a )
k = 4
print ( removals ( a , n , k ) )

Index/key variables: i, mid
Iterator variables: i
Python program:
def countPairs ( a , n ) :
    count = 0
    for i in range ( 0 , n ) :
        for j in range ( i + 1 , n ) :
            if ( a [ i ] & a [ j ] ) == 0 :
                count += 2
    return count
a = [ 3 , 4 , 2 ]
n = len ( a )
print ( countPairs ( a , n ) )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
N = 15
def countPairs ( a , n ) :
    Hash = { }
    dp = [ [ 0 for i in range ( N + 1 ) ] for j in range ( 1 << N ) ]
    for i in range ( n ) :
        if a [ i ] not in Hash :
            Hash [ a [ i ] ] = 1
        else :
            Hash [ a [ i ] ] += 1
    mask = 0
    while ( mask < ( 1 << N ) ) :
        if mask not in Hash :
            Hash [ mask ] = 0
        if ( mask & 1 ) :
            dp [ mask ] [ 0 ] = Hash [ mask ] + Hash [ mask ^ 1 ]
            dp [ mask ] [ 0 ] = Hash [ mask ]
        for i in range ( 1 , N + 1 ) :
            if ( mask & ( 1 << i ) ) :
                dp [ mask ] [ i ] = dp [ mask ] [ i - 1 ] + dp [ mask ^ ( 1 << i ) ] [ i - 1 ]
                dp [ mask ] [ i ] = dp [ mask ] [ i - 1 ]
        mask += 1
    ans = 0
    for i in range ( n ) :
        ans += dp [ ( ( 1 << N ) - 1 ) ^ a [ i ] ] [ N ]
    return ans
a = [ 5 , 4 , 1 , 6 ]
n = len ( a )
print ( countPairs ( a , n ) )

Index/key variables: N, i, mask
Accumulator variables: ans
Iterator variables: i
Python program:
import numpy as np
import sys
dp = np . zeros ( ( 1000 , 1000 ) )
def sum ( a , i , j ) :
    ans = 0
    for m in range ( i , j + 1 ) :
        ans = ( ans + a [ m ] ) % 100
    return ans
def solve ( a , i , j ) :
    if ( i == j ) :
        return 0
    if ( dp [ i ] [ j ] != - 1 ) :
        return dp [ i ] [ j ]
    dp [ i ] [ j ] = sys . maxsize
    for k in range ( i , j ) :
        dp [ i ] [ j ] = min ( dp [ i ] [ j ] , ( solve ( a , i , k ) + solve ( a , k + 1 , j ) + ( sum ( a , i , k ) * sum ( a , k + 1 , j ) ) ) )
    return dp [ i ] [ j ]
def initialize ( n ) :
    for i in range ( n + 1 ) :
        for j in range ( n + 1 ) :
            dp [ i ] [ j ] = - 1
if __name__ == " _ _ main _ _ " :
    a = [ 40 , 60 , 20 ]
    n = len ( a )
    initialize ( n )
    print ( int ( solve ( a , 0 , n - 1 ) ) )

Index/key variables: i, j, m
Iterator variables: i, j, k, m
Python program:
def reverseFibonacci ( n ) :
    a = [ 0 ] * n
    a [ 0 ] = 0
    a [ 1 ] = 1
    for i in range ( 2 , n ) :
        a [ i ] = a [ i - 2 ] + a [ i - 1 ]
    for i in range ( n - 1 , - 1 , - 1 ) :
        print ( a [ i ] , end = " ▁ " )
n = 5
reverseFibonacci ( n )

Index/key variables: i
Iterator variables: i
Python program:
def check ( s1 , s2 ) :
    n = len ( s1 )
    m = len ( s2 )
    dp = ( [ [ False for i in range ( m + 1 ) ] for i in range ( n + 1 ) ] )
    dp [ 0 ] [ 0 ] = True
    for i in range ( len ( s1 ) ) :
        for j in range ( len ( s2 ) + 1 ) :
            if ( dp [ i ] [ j ] ) :
                if ( ( j < len ( s2 ) and ( s1 [ i ] . upper ( ) == s2 [ j ] ) ) ) :
                    dp [ i + 1 ] [ j + 1 ] = True
                if ( s1 [ i ] . isupper ( ) == False ) :
                    dp [ i + 1 ] [ j ] = True
    return ( dp [ n ] [ m ] )
if __name__ == ' _ _ main _ _ ' :
    s1 = " daBcd "
    s2 = " ABC "
    if ( check ( s1 , s2 ) ) :
        print ( " YES " )
    else :
        print ( " NO " )

Index/key variables: i, j, m, n
Iterator variables: i, j
Python program:
def find_prob ( N , P ) :
    dp = [ 0 ] * ( n + 1 )
    dp [ 0 ] = 1
    dp [ 1 ] = 0
    dp [ 2 ] = P
    dp [ 3 ] = 1 - P
    for i in range ( 4 , N + 1 ) :
        dp [ i ] = ( P ) * dp [ i - 2 ] + ( 1 - P ) * dp [ i - 3 ]
    return dp [ N ]
n = 5
p = 0.2
print ( round ( find_prob ( n , p ) , 2 ) )

Index/key variables: N, i
Iterator variables: i
Python program:
INT_MAX = 99999999999
def getLevenstein ( inpt ) :
    revInput = inpt [ : : - 1 ]
    n = len ( inpt )
    dp = [ [ - 1 for _ in range ( n + 1 ) ] for __ in range ( n + 1 ) ]
    for i in range ( n + 1 ) :
        dp [ 0 ] [ i ] = i
        dp [ i ] [ 0 ] = i
    for i in range ( 1 , n + 1 ) :
        for j in range ( 1 , n + 1 ) :
            if inpt [ i - 1 ] == revInput [ j - 1 ] :
                dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ]
            else :
                dp [ i ] [ j ] = 1 + min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] )
    res = INT_MAX
    i , j = n , 0
    while i >= 0 :
        res = min ( res , dp [ i ] [ j ] )
        if i < n :
            res = min ( res , dp [ i + 1 ] [ j ] )
        if i > 0 :
            res = min ( res , dp [ i - 1 ] [ j ] )
        i -= 1
        j += 1
    return res
if __name__ == " _ _ main _ _ " :
    inpt = " myfirstgeekarticle "
    print ( getLevenstein ( inpt ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
N = 5
def printHosoya ( n ) :
    dp = [ [ 0 for i in range ( N ) ] for i in range ( N ) ]
    dp [ 0 ] [ 0 ] = dp [ 1 ] [ 0 ] = dp [ 1 ] [ 1 ] = 1
    for i in range ( 2 , n ) :
        for j in range ( n ) :
            if ( i > j ) :
                dp [ i ] [ j ] = ( dp [ i - 1 ] [ j ] + dp [ i - 2 ] [ j ] )
            else :
                dp [ i ] [ j ] = ( dp [ i - 1 ] [ j - 1 ] + dp [ i - 2 ] [ j - 2 ] )
    for i in range ( n ) :
        for j in range ( i + 1 ) :
            print ( dp [ i ] [ j ] , end = ' ▁ ' )
        print ( )
n = 5
printHosoya ( n )

Index/key variables: i, j
Iterator variables: i, j
Python program:
MAX = 100
import numpy as np
def numberofways ( n , m ) :
    dp = np . zeros ( ( n + 2 , n + 2 ) )
    dp [ 0 ] [ n + 1 ] = 1
    for k in range ( n , m - 1 , - 1 ) :
        for i in range ( n + 1 ) :
            dp [ i ] [ k ] = dp [ i ] [ k + 1 ]
            if ( i - k >= 0 ) :
                dp [ i ] [ k ] = ( dp [ i ] [ k ] + dp [ i - k ] [ k ] )
    return dp [ n ] [ m ]
if __name__ == " _ _ main _ _ " :
    n , m = 3 , 1
    print ( numberofways ( n , m ) )

Index/key variables: i, k, m, n
Iterator variables: i, k
Python program:
def eulerian ( n , m ) :
    dp = [ [ 0 for x in range ( m + 1 ) ] for y in range ( n + 1 ) ]
    for i in range ( 1 , n + 1 ) :
        for j in range ( 0 , m + 1 ) :
            if ( i > j ) :
                if ( j == 0 ) :
                    dp [ i ] [ j ] = 1
                else :
                    dp [ i ] [ j ] = ( ( ( i - j ) * dp [ i - 1 ] [ j - 1 ] ) + ( ( j + 1 ) * dp [ i - 1 ] [ j ] ) )
    return dp [ n ] [ m ]
n = 3
m = 1
print ( eulerian ( n , m ) )

Index/key variables: i, j, m, n
Iterator variables: i, j
Python program:
def dealnnoy ( n , m ) :
    dp = [ [ 0 for x in range ( n + 1 ) ] for x in range ( m + 1 ) ]
    for i in range ( m ) :
        dp [ 0 ] [ i ] = 1
    for i in range ( 1 , m + 1 ) :
        dp [ i ] [ 0 ] = 1
    for i in range ( 1 , m + 1 ) :
        for j in range ( 1 , n + 1 ) :
            dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] + dp [ i ] [ j - 1 ] ;
    return dp [ m ] [ n ]
n = 3
m = 4
print ( dealnnoy ( n , m ) )

Index/key variables: i, j, m, n
Iterator variables: i, j
Python program:
def longestAlternating ( arr , n ) :
    count = [ None ] * n
    count [ n - 1 ] = 1
    i = n - 2
    while i >= 0 :
        if ( arr [ i ] * arr [ i + 1 ] < 0 ) :
            count [ i ] = count [ i + 1 ] + 1
        else :
            count [ i ] = 1 ;
        i = i - 1
    i = 0
    while i < n :
        print ( count [ i ] , end = " ▁ " )
        i = i + 1
a = [ - 5 , - 1 , - 1 , 2 , - 2 , - 3 ]
n = len ( a )
longestAlternating ( a , n ) ;

Index/key variables: i
Python program:
def maxDP ( n ) :
    res = list ( )
    res . append ( 0 )
    res . append ( 1 )
    i = 2
    while i < n + 1 :
        res . append ( max ( i , ( res [ int ( i / 2 ) ] + res [ int ( i / 3 ) ] + res [ int ( i / 4 ) ] + res [ int ( i / 5 ) ] ) ) )
        i = i + 1
    return res [ n ]
n = 60
print ( " MaxSum ▁ = " , maxDP ( n ) )

Index/key variables: n
Accumulator variables: res
Python program:
MAX = 100
def allones ( s , n ) :
    co = 0
    for i in s :
        co += 1 if i == '1' else 0
    return co == n
def findlength ( arr , s , n , ind , st , dp ) :
    if ind >= n :
        return 0
    if dp [ ind ] [ st ] != - 1 :
        return dp [ ind ] [ st ]
    if not st :
        dp [ ind ] [ st ] = max ( arr [ ind ] + findlength ( arr , s , n , ind + 1 , 1 , dp ) , ( findlength ( arr , s , n , ind + 1 , 0 , dp ) ) )
    else :
        dp [ ind ] [ st ] = max ( arr [ ind ] + findlength ( arr , s , n , ind + 1 , 1 , dp ) , 0 )
    return dp [ ind ] [ st ]
def maxLen ( s , n ) :
    if allones ( s , n ) :
        return - 1
    arr = [ 0 ] * MAX
    for i in range ( n ) :
        arr [ i ] = 1 if s [ i ] == '0' else - 1
    dp = [ [ - 1 ] * 3 for _ in range ( MAX ) ]
    return findlength ( arr , s , n , 0 , 0 , dp )
s = "11000010001"
n = 11
print ( maxLen ( s , n ) )

Index/key variables: i, ind, st
Accumulator variables: co
Iterator variables: i
Python program:
R = 4
C = 3
def isSafe ( x , y ) :
    return ( x < R and y < C )
def minJump ( height , x , y ) :
    if ( x == R - 1 and y == C - 1 ) :
        return 0
    diag = 10 ** 9
    if ( isSafe ( x + 1 , y + 1 ) ) :
        diag = ( minJump ( height , x + 1 , y + 1 ) + abs ( height [ x ] [ y ] - height [ x + 1 ] [ y + 1 ] ) )
    down = 10 ** 9
    if ( isSafe ( x + 1 , y ) ) :
        down = ( minJump ( height , x + 1 , y ) + abs ( height [ x ] [ y ] - height [ x + 1 ] [ y ] ) )
    right = 10 ** 9
    if ( isSafe ( x , y + 1 ) ) :
        right = ( minJump ( height , x , y + 1 ) + abs ( height [ x ] [ y ] - height [ x ] [ y + 1 ] ) )
    return min ( [ down , right , diag ] )
height = [ [ 5 , 4 , 2 ] , [ 9 , 2 , 1 ] , [ 2 , 5 , 9 ] , [ 1 , 3 , 11 ] ]
print ( minJump ( height , 0 , 0 ) )

Index/key variables: x, y
Python program:
def maxSum ( arr , N , k ) :
    MS = [ 0 for i in range ( N ) ]
    MS [ N - 1 ] = arr [ N - 1 ]
    for i in range ( N - 2 , - 1 , - 1 ) :
        if ( i + k + 1 >= N ) :
            MS [ i ] = max ( arr [ i ] , MS [ i + 1 ] )
        else :
            MS [ i ] = max ( arr [ i ] + MS [ i + k + 1 ] , MS [ i + 1 ] )
    return MS [ 0 ]
N = 10 ; k = 2
arr = [ 50 , 70 , 40 , 50 , 90 , 70 , 60 , 40 , 70 , 50 ]
print ( maxSum ( arr , N , k ) )

Index/key variables: i
Iterator variables: i
Python program:
def maxLength ( s , n ) :
    invalidOpenBraces = 0 ;
    invalidCloseBraces = 0 ;
    for i in range ( n ) :
        if ( s [ i ] == ' ( ' ) :
            invalidOpenBraces += 1
        else :
            if ( invalidOpenBraces == 0 ) :
                invalidCloseBraces += 1
            else :
                invalidOpenBraces -= 1
    return ( n - ( invalidOpenBraces + invalidCloseBraces ) )
s = " ( ) ( ( ( ( ( ( ) "
n = len ( s )
print ( maxLength ( s , n ) )

Index/key variables: i
Accumulator variables: invalidCloseBraces, invalidOpenBraces
Iterator variables: i
Python program:
def alternateSubarray ( arr , n ) :
    len = [ ]
    for i in range ( n + 1 ) :
        len . append ( 0 )
    len [ n - 1 ] = 1
    for i in range ( n - 2 , - 1 , - 1 ) :
        if ( arr [ i ] ^ arr [ i + 1 ] == True ) :
            len [ i ] = len [ i + 1 ] + 1
        else :
            len [ i ] = 1
    for i in range ( n ) :
        print ( len [ i ] , " ▁ " , end = " " )
arr = [ True , False , True , False , False , True ]
n = len ( arr )
alternateSubarray ( arr , n )

Index/key variables: i
Accumulator variables: len
Iterator variables: i
Python program:
MAX = 10
def lcs ( dp , arr1 , n , arr2 , m , k ) :
    if k < 0 :
        return - ( 10 ** 7 )
    if n < 0 or m < 0 :
        return 0
    ans = dp [ n ] [ m ] [ k ]
    if ans != - 1 :
        return ans
    ans = max ( lcs ( dp , arr1 , n - 1 , arr2 , m , k ) , lcs ( dp , arr1 , n , arr2 , m - 1 , k ) )
    if arr1 [ n - 1 ] == arr2 [ m - 1 ] :
        ans = max ( ans , 1 + lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k ) )
    ans = max ( ans , lcs ( dp , arr1 , n - 1 , arr2 , m - 1 , k - 1 ) )
    return ans
if __name__ == " _ _ main _ _ " :
    k = 1
    arr1 = [ 1 , 2 , 3 , 4 , 5 ]
    arr2 = [ 5 , 3 , 1 , 4 , 2 ]
    n = len ( arr1 )
    m = len ( arr2 )
    dp = [ [ [ - 1 for i in range ( MAX ) ] for j in range ( MAX ) ] for k in range ( MAX ) ]
    print ( lcs ( dp , arr1 , n , arr2 , m , k ) )

Index/key variables: k, m, n
Python program:
def countWays ( n ) :
    dp = [ [ 0 ] * ( n + 1 ) for i in range ( 2 ) ]
    dp [ 0 ] [ 1 ] = 1
    dp [ 1 ] [ 1 ] = 2
    for i in range ( 2 , n + 1 ) :
        dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + dp [ 1 ] [ i - 1 ]
        dp [ 1 ] [ i ] = ( dp [ 0 ] [ i - 1 ] * 2 + dp [ 1 ] [ i - 1 ] )
    return dp [ 0 ] [ n ] + dp [ 1 ] [ n ]
if __name__ == " _ _ main _ _ " :
    n = 5
    print ( " Total ▁ no ▁ of ▁ ways ▁ with ▁ n ▁ = " , n , " are : " , countWays ( n ) )

Index/key variables: i, n
Iterator variables: i
Python program:
def countways ( n ) :
    A = [ 0 for i in range ( n + 2 ) ]
    A [ 0 ] = 1
    A [ 1 ] = 3
    A [ 2 ] = 7
    for i in range ( 2 , n + 1 ) :
        A [ i ] = 2 * A [ i - 1 ] + A [ i - 2 ]
    return A [ n ]
n = 5
print ( countways ( 5 ) )

Index/key variables: i, n
Iterator variables: i
Python program:
def findWinner ( x , y , n ) :
    dp = [ 0 for i in range ( n + 1 ) ]
    dp [ 0 ] = False
    dp [ 1 ] = True
    for i in range ( 2 , n + 1 ) :
        if ( i - 1 >= 0 and not dp [ i - 1 ] ) :
            dp [ i ] = True
        elif ( i - x >= 0 and not dp [ i - x ] ) :
            dp [ i ] = True
        elif ( i - y >= 0 and not dp [ i - y ] ) :
            dp [ i ] = True
        else :
            dp [ i ] = False
    return dp [ n ]
x = 3 ; y = 4 ; n = 5
if ( findWinner ( x , y , n ) ) :
    print ( ' A ' )
else :
    print ( ' B ' )

Index/key variables: i, n
Iterator variables: i
Python program:
def maxGameByWinner ( N ) :
    dp = [ 0 for i in range ( N ) ]
    dp [ 0 ] = 1
    dp [ 1 ] = 2
    i = 1
    while dp [ i ] <= N :
        i = i + 1
        dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ]
    return ( i - 1 )
N = 10
print ( maxGameByWinner ( N ) )

Index/key variables: i
Python program:
def minRemove ( arr , n ) :
    LIS = [ 0 for i in range ( n ) ]
    len = 0
    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 ( i - j ) <= ( arr [ i ] - arr [ j ] ) ) :
                LIS [ i ] = max ( LIS [ i ] , LIS [ j ] + 1 )
        len = max ( len , LIS [ i ] )
    return ( n - len )
arr = [ 1 , 2 , 6 , 5 , 4 ]
n = len ( arr )
print ( minRemove ( arr , n ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def countTransformation ( a , b ) :
    n = len ( a )
    m = len ( b )
    if m == 0 :
        return 1
    dp = [ [ 0 ] * ( n ) for _ in range ( m ) ]
    for i in range ( m ) :
        for j in range ( i , n ) :
            if i == 0 :
                if j == 0 :
                    if a [ j ] == b [ i ] :
                        dp [ i ] [ j ] = 1
                    else :
                        dp [ i ] [ j ] = 0
                elif a [ j ] == b [ i ] :
                    dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + 1
                else :
                    dp [ i ] [ j ] = dp [ i ] [ j - 1 ]
            else :
                if a [ j ] == b [ i ] :
                    dp [ i ] [ j ] = ( dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ j - 1 ] )
                else :
                    dp [ i ] [ j ] = dp [ i ] [ j - 1 ]
    return dp [ m - 1 ] [ n - 1 ]
if __name__ == " _ _ main _ _ " :
    a = " abcccdf "
    b = " abccdf "
    print ( countTransformation ( a , b ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
max = 100000 ;
def baseconversion ( arr , num , base ) :
    i = 0 ;
    if ( num == 0 ) :
        return 0 ;
    while ( num > 0 ) :
        rem = num % base ;
        i = i + 1 ;
        arr [ i ] = rem ;
        num = num // base ;
    return i ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 0 for i in range ( max ) ] ;
    n = 10 ;
    size = baseconversion ( arr , n - 1 , 6 ) ;
    if ( size == 0 ) :
        print ( size ) ;
    for i in range ( size , 0 , - 1 ) :
        print ( arr [ i ] , end = " " ) ;

Index/key variables: i
Iterator variables: i
Python program:
MAX = 1000
def maxSubsequenceSubstring ( x , y , n , m ) :
    dp = [ [ 0 for i in range ( MAX ) ] for i in range ( MAX ) ]
    for i in range ( 1 , m + 1 ) :
        for j in range ( 1 , n + 1 ) :
            if ( x [ j - 1 ] == y [ i - 1 ] ) :
                dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]
            else :
                dp [ i ] [ j ] = dp [ i ] [ j - 1 ]
    ans = 0
    for i in range ( 1 , m + 1 ) :
        ans = max ( ans , dp [ i ] [ n ] )
    return ans
x = " ABCD "
y = " BACDBDCD "
n = len ( x )
m = len ( y )
print ( maxSubsequenceSubstring ( x , y , n , m ) )

Index/key variables: i, j, n
Iterator variables: i, j
Python program:
INT_MIN = - 9999999999
def maxWeightRec ( wt , val , K , mp , last , diff ) :
    if last == - 1 :
        if diff == 0 :
            return 0
        else :
            return INT_MIN
    tmp = ( last , diff )
    if tmp in mp :
        return mp [ tmp ]
    mp [ tmp ] = max ( maxWeightRec ( wt , val , K , mp , last - 1 , diff ) , wt [ last ] + maxWeightRec ( wt , val , K , mp , last - 1 , diff + wt [ last ] - val [ last ] * K ) )
    return mp [ tmp ]
def maxWeight ( wt , val , K , N ) :
    return maxWeightRec ( wt , val , K , { } , N - 1 , 0 )
if __name__ == " _ _ main _ _ " :
    wt = [ 4 , 8 , 9 ]
    val = [ 2 , 4 , 6 ]
    N = len ( wt )
    K = 2
    print ( maxWeight ( wt , val , K , N ) )

Index/key variables: last, tmp
Python program:
def minPyramidCost ( arr : list , N ) :
    left = [ 0 ] * N
    right = [ 0 ] * N
    left [ 0 ] = min ( arr [ 0 ] , 1 )
    for i in range ( 1 , N ) :
        left [ i ] = min ( arr [ i ] , min ( left [ i - 1 ] + 1 , i + 1 ) )
    right [ N - 1 ] = min ( arr [ N - 1 ] , 1 )
    for i in range ( N - 2 , - 1 , - 1 ) :
        right [ i ] = min ( arr [ i ] , min ( right [ i + 1 ] + 1 , N - i ) )
    tot = [ 0 ] * N
    for i in range ( N ) :
        tot [ i ] = min ( right [ i ] , left [ i ] )
    max_ind = 0
    for i in range ( N ) :
        if tot [ i ] > tot [ max_ind ] :
            max_ind = i
    cost = 0
    height = tot [ max_ind ]
    for x in range ( max_ind , - 1 , - 1 ) :
        cost += arr [ x ] - height
        if height > 0 :
            height -= 1
    height = tot [ max_ind ] - 1
    for x in range ( max_ind + 1 , N ) :
        cost += arr [ x ] - height
        if height > 0 :
            height -= 1
    return cost
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 4 , 2 , 1 ]
    N = len ( arr )
    print ( minPyramidCost ( arr , N ) )

Index/key variables: i, max_ind, x
Accumulator variables: cost, height
Iterator variables: i, x
Python program:
string = " GeeksforGeeks "
for i in range ( 0 , len ( string ) ) :
    flag = 0
    for j in range ( 0 , len ( string ) ) :
        if ( string [ i ] == string [ j ] and i != j ) :
            flag = 1
            break
    if ( flag == 0 ) :
        print ( string [ i ] , end = " " )

Index/key variables: i, j
Iterator variables: i, j
Python program:
NO_OF_CHARS = 256
def printDistinct ( str ) :
    count = [ 0 ] * NO_OF_CHARS
    for i in range ( len ( str ) ) :
        if ( str [ i ] != ' ▁ ' ) :
            count [ ord ( str [ i ] ) ] += 1
    n = i
    for i in range ( n ) :
        if ( count [ ord ( str [ i ] ) ] == 1 ) :
            print ( str [ i ] , end = " " )
if __name__ == " _ _ main _ _ " :
    str = " GeeksforGeeks "
    printDistinct ( str )

Index/key variables: i
Iterator variables: i
Python program:
MAX = 1005
def shortestSeq ( S , T , m , n ) :
    if m == 0 :
        return MAX
    if ( n <= 0 ) :
        return 1
    for k in range ( n ) :
        if ( T [ k ] == S [ 0 ] ) :
            break
    if ( k == n ) :
        return 1
    return min ( shortestSeq ( S [ 1 : ] , T , m - 1 , n ) , 1 + shortestSeq ( ( S [ 1 : ] ) , T [ k + 1 : ] , m - 1 , n - k - 1 ) )
S = " babab "
T = " babba "
m = len ( S )
n = len ( T )
ans = shortestSeq ( S , T , m , n )
if ( ans >= MAX ) :
    ans = - 1
print ( " Length ▁ of ▁ shortest ▁ subsequence ▁ is : " , ans )

Index/key variables: k
Iterator variables: k