dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
LIMIT = 1000000000
def F ( N : int ) -> int :
    string = str ( N )
    sum = 0
    for i in range ( len ( string ) ) :
        val = int ( ord ( string [ i ] ) - ord ( '0' ) )
        sum += val * val * val
    return sum
def findDestination ( N : int ) -> int :
    s = set ( )
    prev = N
    next = 0
    s . add ( N )
    while ( N <= LIMIT ) :
        next = F ( N )
        if next in s :
            return next
        prev = next
        s . add ( prev )
        N = next
    return next
def digitCubeLimit ( N : int ) -> int :
    if ( N < 0 ) :
        print ( " N ▁ cannot ▁ be ▁ negative " )
    else :
        ans = findDestination ( N )
        if ( ans > LIMIT ) :
            print ( " Limit ▁ exceeded " )
        elif ( ans == F ( ans ) ) :
            print ( " { } ▁ reaches ▁ to ▁ a ▁ fixed ▁ point : ▁ { } " . format ( N , ans ) )
        else :
            print ( " { } ▁ reaches ▁ to ▁ a ▁ limit ▁ cycle : ▁ { } " . format ( N , ans ) )
if __name__ == " _ _ main _ _ " :
    N = 3
    digitCubeLimit ( N )

Index/key variables: i
Accumulator variables: s, sum
Iterator variables: i
Python program:
def countTuples ( arr , N ) :
    ans = 0
    val = 0
    freq = { }
    for j in range ( N - 2 ) :
        val = 0
        for l in range ( j + 1 , N ) :
            if ( arr [ j ] == arr [ l ] ) :
                ans += val
            if arr [ l ] in freq :
                val += freq [ arr [ l ] ]
        freq [ arr [ j ] ] = freq . get ( arr [ j ] , 0 ) + 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 1 , 2 , 2 , 2 ]
    N = len ( arr )
    print ( countTuples ( arr , N ) )

Index/key variables: j, l
Accumulator variables: ans, val
Iterator variables: j, l
Python program:
import sys
def minOperation ( arr ) :
    minOp = sys . maxsize
    minNeg = 0
    maxPos = 0
    for i in range ( len ( arr ) ) :
        if ( arr [ i ] < 0 ) :
            if ( arr [ i ] < minNeg ) :
                minNeg = arr [ i ]
        else :
            if arr [ i ] > maxPos :
                maxPos = arr [ i ]
    return abs ( minNeg ) + maxPos
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 3 , 4 , 1 ]
    print ( minOperation ( arr ) )

Index/key variables: i
Iterator variables: i
Python program:
def GCD ( a , b ) :
    if ( b == 0 ) :
        return a
    return GCD ( b , a % b )
def GcdPair ( arr , k ) :
    lo = 0
    hi = len ( arr ) - 1
    ans = [ - 1 , 0 ]
    while ( lo <= hi ) :
        mid = lo + ( hi - lo ) // 2
        if ( GCD ( arr [ mid ] [ 0 ] , arr [ mid ] [ 1 ] ) > k ) :
            ans = arr [ mid ]
            hi = mid - 1
        else :
            lo = mid + 1
    if ( len ( ans ) == - 1 ) :
        print ( " - 1" )
    else :
        print ( " ( " , ans [ 0 ] , " , " , ans [ 1 ] , " ) " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 3 , 6 ] , [ 15 , 30 ] , [ 25 , 75 ] , [ 30 , 120 ] ]
    K = 16
    GcdPair ( arr , K )

Index/key variables: mid
Python program:
import sys
def isPossible ( arr , N ) :
    mn = sys . maxsize ;
    B = [ 0 ] * N ;
    for i in range ( N ) :
        mn = min ( mn , arr [ i ] ) ;
        B [ i ] = arr [ i ] ;
    arr . sort ( ) ;
    for i in range ( N ) :
        if ( arr [ i ] != B [ i ] ) :
            if ( B [ i ] % mn != 0 ) :
                print ( " No " ) ;
                return ;
    print ( " Yes " ) ;
    return ;
if __name__ == ' _ _ main _ _ ' :
    N = 6 ;
    arr = [ 4 , 3 , 6 , 6 , 2 , 9 ] ;
    isPossible ( arr , N ) ;

Index/key variables: i
Iterator variables: i
Python program:
def addEdge ( adj , u , v ) :
    adj [ u ] . append ( v )
    adj [ v ] . append ( u )
    return adj
def DFSUtil ( u , adj , visited , componentMin , componentMax ) :
    visited [ u ] = True
    componentMax = max ( componentMax , u )
    componentMin = min ( componentMin , u )
    for i in range ( len ( adj [ u ] ) ) :
        if ( visited [ adj [ u ] [ i ] ] == False ) :
            visited , componentMax , componentMin = DFSUtil ( adj [ u ] [ i ] , adj , visited , componentMin , componentMax )
    return visited , componentMax , componentMin
def isValid ( v ) :
    MAX = - 1
    ans = False
    for i in v :
        if len ( i ) != 2 :
            continue
        if ( i [ 0 ] <= MAX ) :
            ans = True
        MAX = max ( MAX , i [ 1 ] )
    return ( True if ans == False else False )
def DFS ( adj , V ) :
    v = [ [ ] ]
    visited = [ False for i in range ( V + 1 ) ]
    for u in range ( 1 , V + 1 ) :
        if ( visited [ u ] == False ) :
            componentMax = u
            componentMin = u
            visited , componentMax , componentMin = DFSUtil ( u , adj , visited , componentMin , componentMax )
            v . append ( [ componentMin , componentMax ] )
    check = isValid ( v )
    if ( check ) :
        print ( ' Yes ' )
    else :
        print ( ' No ' )
    return
if __name__ == " _ _ main _ _ " :
    N = 4
    K = 3
    adj = [ [ ] for i in range ( N + 1 ) ]
    adj = addEdge ( adj , 1 , 2 )
    adj = addEdge ( adj , 2 , 3 )
    adj = addEdge ( adj , 3 , 4 )
    DFS ( adj , N )

Index/key variables: i, u, v
Iterator variables: i, u
Boolean variables: ans
Python program:
def longDelSub ( str1 , str2 ) :
    N = len ( str1 )
    M = len ( str2 )
    prev_pos = 0
    pos = [ 0 ] * M
    for i in range ( M ) :
        index = prev_pos
        while ( index < N and str1 [ index ] != str2 [ i ] ) :
            index += 1
        pos [ i ] = index
        prev_pos = index + 1
    res = N - prev_pos
    prev_pos = N - 1
    for i in range ( M - 1 , - 1 , - 1 ) :
        index = prev_pos
        while ( index >= 0 and str1 [ index ] != str2 [ i ] ) :
            index -= 1
        if ( i != 0 ) :
            res = max ( res , index - pos [ i - 1 ] - 1 )
        prev_pos = index - 1
    res = max ( res , prev_pos + 1 )
    return res
str1 = " GeeksforGeeks "
str2 = " forks "
print ( longDelSub ( str1 , str2 ) )

Index/key variables: i, index
Iterator variables: i
Python program:
def print_substring ( s ) :
    n = len ( s )
    str = " "
    ans = [ ]
    if ( n == 0 ) :
        print ( " - 1" )
        return
    last_pos = [ - 1 ] * 26
    for i in range ( n - 1 , - 1 , - 1 ) :
        if ( last_pos [ ord ( s [ i ] ) - ord ( ' a ' ) ] == - 1 ) :
            last_pos [ ord ( s [ i ] ) - ord ( ' a ' ) ] = i
    minp = - 1
    for i in range ( n ) :
        lp = last_pos [ ord ( s [ i ] ) - ord ( ' a ' ) ]
        minp = max ( minp , lp )
        if ( i == minp ) :
            str += s [ i ]
            print ( str , end = " ▁ " )
            minp = - 1
            str = " "
        else :
            str += s [ i ]
S = " ababcbacadefegdehijhklij "
print_substring ( S )

Index/key variables: i
Accumulator variables: str
Iterator variables: i
Python program:
def partitionString ( s ) :
    n = len ( s )
    ans = [ ]
    if ( n == 0 ) :
        print ( " - 1" )
        return
    last_pos = [ - 1 ] * 26
    for i in range ( n - 1 , - 1 , - 1 ) :
        if ( last_pos [ ord ( s [ i ] ) - ord ( ' a ' ) ] == - 1 ) :
            last_pos [ ord ( s [ i ] ) - ord ( ' a ' ) ] = i
    minp = - 1
    plen = 0
    for i in range ( n ) :
        lp = last_pos [ ord ( s [ i ] ) - ord ( ' a ' ) ]
        minp = max ( minp , lp )
        plen += 1
        if ( i == minp ) :
            ans . append ( plen )
            minp = - 1
            plen = 0
    for i in range ( len ( ans ) ) :
        print ( ans [ i ] , end = " ▁ " )
str = " acbbcc "
partitionString ( str )

Index/key variables: i
Accumulator variables: ans, plen
Iterator variables: i
Python program:
def solve ( S ) :
    count_0 = 0
    count_1 = 0
    prev = - 1
    for i in range ( len ( S ) ) :
        if ( S [ i ] == '0' ) :
            count_0 += 1
        elif ( S [ i ] == '1' ) :
            count_1 += 1
    for i in range ( len ( S ) ) :
        if ( S [ i ] == ' * ' ) :
            continue
        elif ( S [ i ] == '0' and prev == - 1 ) :
            count_0 = count_0 + i
            prev = i
        elif ( S [ i ] == '1' and prev == - 1 ) :
            prev = i
        elif ( S [ prev ] == '1' and S [ i ] == '0' ) :
            count_0 = count_0 + ( i - prev - 1 ) / 2
            count_1 = count_1 + ( i - prev - 1 ) // 2
            prev = i
        elif ( S [ prev ] == '1' and S [ i ] == '1' ) :
            count_1 = count_1 + ( i - prev - 1 )
            prev = i
        elif ( S [ prev ] == '0' and S [ i ] == '1' ) :
            prev = i
        elif ( S [ prev ] == '0' and S [ i ] == '0' ) :
            count_0 = count_0 + ( i - prev - 1 )
            prev = i
    if ( count_0 > count_1 ) :
        print ( "0" )
    elif ( count_1 > count_0 ) :
        print ( "1" )
    else :
        print ( " - 1" )
str = " * *0 * * 1 * * *0"
solve ( str )

Index/key variables: i, prev
Accumulator variables: count_0, count_1
Iterator variables: i
Python program:
import sys
def minFirstTerm ( X , diff , N ) :
    first_term_1 = sys . maxsize
    low = 0
    high = N
    while ( low <= high ) :
        mid = ( low + high ) // 2
        if ( X - mid * diff > 0 ) :
            first_term_1 = X - mid * diff
            low = mid + 1
        else :
            high = mid - 1
    return first_term_1
def printAP ( N , X , Y ) :
    if ( X > Y ) :
        X = X + Y
        Y = X - Y
        X = X - Y
    maxDiff = Y - X
    first_term = sys . maxsize
    diff = 0
    for i in range ( 1 , maxDiff + 1 ) :
        if i * i > maxDiff :
            break
        if ( maxDiff % i == 0 ) :
            diff1 = i
            diff2 = maxDiff // diff1
            terms1 = diff2 + 1
            terms2 = diff1 + 1
            first_term1 = minFirstTerm ( X , diff1 , N - terms1 )
            first_term2 = minFirstTerm ( X , diff2 , N - terms2 )
            if ( first_term1 < first_term ) :
                first_term = first_term1
                diff = diff1
            if ( first_term2 < first_term ) :
                first_term = first_term2
                diff = diff2
    for i in range ( N ) :
        print ( first_term , end = " ▁ " )
        first_term += diff
if __name__ == ' _ _ main _ _ ' :
    N = 5
    X = 10
    Y = 15
    printAP ( N , X , Y )

Accumulator variables: first_term
Iterator variables: i
Python program:
def isCubeSum ( n ) :
    for i in range ( 1 , int ( pow ( n , 1 / 3 ) ) + 1 ) :
        if ( i * i * i + ( i + 1 ) * ( i + 1 ) * ( i + 1 ) == n ) :
            return True ;
    return False ;
if __name__ == ' _ _ main _ _ ' :
    n = 35 ;
    if ( isCubeSum ( n ) ) :
        print ( " Yes " ) ;
    else :
        print ( " No " ) ;

Iterator variables: i
Python program:
def maxweight ( s , e , pre ) :
    if s == e :
        return 0
    ans = 0
    for i in range ( s , e ) :
        left = pre [ i ] - pre [ s - 1 ]
        right = pre [ e ] - pre [ i ]
        if left < right :
            ans = max ( ans , left + maxweight ( s , i , pre ) )
        if left == right :
            ans = max ( ans , left + maxweight ( s , i , pre ) , right + maxweight ( i + 1 , e , pre ) )
        if left > right :
            ans = max ( ans , right + maxweight ( i + 1 , e , pre ) )
    return ans
def maxSum ( arr ) :
    pre = { - 1 : 0 , 0 : arr [ 0 ] }
    for i in range ( 1 , len ( arr ) ) :
        pre [ i ] = pre [ i - 1 ] + arr [ i ]
    print ( maxweight ( 0 , len ( arr ) - 1 , pre ) )
arr = [ 6 , 2 , 3 , 4 , 5 , 5 ]
maxSum ( arr )

Index/key variables: e, i
Iterator variables: i
Python program:
def largestTimeFromDigits ( A ) :
    mp1 = { }
    mp2 = { }
    for x in A :
        mp1 [ x ] = mp1 . get ( x , 0 ) + 1
    mp2 = mp1 . copy ( )
    hr = 23
    m = 59
    s = 59
    while ( hr >= 0 ) :
        h0 = hr // 10
        h1 = hr % 10
        m0 = m // 10
        m1 = m % 10
        s0 = s // 10
        s1 = s % 10
        p = 0
        arr = [ h0 , h1 , m0 , m1 , s0 , s1 ]
        for it in arr :
            if ( it in mp1 and mp1 . get ( it ) > 0 ) :
                mp1 [ it ] = mp1 . get ( it ) - 1
            else :
                p = 1
        if ( p == 0 ) :
            s = " "
            s = ( str ( h0 ) + str ( h1 ) )
            s += ( ' : ' + str ( m0 ) + str ( m1 ) )
            s += ( ' : ' + str ( s0 ) + str ( s1 ) )
            return s
        mp1 = mp2 . copy ( )
        if ( s == 0 ) :
            s = 59
            m -= 1
        elif ( m < 0 ) :
            m = 59
            hr -= 1
        if ( s > 0 ) :
            s -= 1
    return " - 1"
if __name__ == ' _ _ main _ _ ' :
    v = [ 0 , 2 , 1 , 9 , 3 , 2 ]
    print ( largestTimeFromDigits ( v ) )

Index/key variables: it, x
Accumulator variables: hr, m, s
Iterator variables: it, x
Python program:
def palindromePrefix ( S ) :
    n = len ( S )
    for i in range ( n - 1 , - 1 , - 1 ) :
        curr = S [ 0 : i + 1 ]
        l = 0
        r = len ( curr ) - 1
        is_palindrome = 1
        while ( l < r ) :
            if ( curr [ l ] != curr [ r ] ) :
                is_palindrome = 0
                break
            l += 1
            r -= 1
        if ( is_palindrome ) :
            return curr
    return " "
def maxPalindrome ( S ) :
    n = len ( S )
    if ( n <= 1 ) :
        return S
    pre = " "
    suff = " "
    i = 0
    j = n - 1
    while ( S [ i ] == S [ j ] and i < j ) :
        i += 1
        j -= 1
    i -= 1
    j += 1
    pre = S [ 0 : i + 1 ]
    suff = S [ j : ]
    if ( j - i == 1 ) :
        return pre + suff
    if ( j - i == 2 ) :
        mid_char = S [ i + 1 : i + 2 ]
        return pre + mid_char + suff
    rem_str = S [ i + 1 : j ]
    pre_of_rem_str = palindromePrefix ( rem_str )
    list1 = list ( rem_str )
    list1 . reverse ( )
    rem_str = ' ' . join ( list1 )
    suff_of_rem_str = palindromePrefix ( rem_str )
    if ( len ( pre_of_rem_str ) >= len ( suff_of_rem_str ) ) :
        return ( pre + pre_of_rem_str + suff )
    else :
        return ( pre + suff_of_rem_str + suff )
if __name__ == " _ _ main _ _ " :
    S = " geeksforskeeg "
    print ( maxPalindrome ( S ) )

Index/key variables: i, j, l, r
Iterator variables: i
Python program:
from math import log10
def countNumEnds ( A , L , R ) :
    count = 0
    digits = int ( log10 ( A ) + 1 )
    temp = int ( pow ( 10 , digits ) )
    cycle = temp
    while ( temp <= R ) :
        if ( temp >= L ) :
            count += 1
        temp += cycle
    print ( count )
A = 2
L = 2
R = 20
countNumEnds ( A , L , R )

Accumulator variables: count, temp
Python program:
def minOperations ( s ) :
    length = len ( s )
    result = 0
    for i in range ( length // 2 ) :
        D1 = ( ord ( max ( s [ i ] , s [ length - 1 - i ] ) ) - ord ( min ( s [ i ] , s [ length - 1 - i ] ) ) )
        D2 = 26 - D1
        result += min ( D1 , D2 )
    return result
s = " abccdb "
print ( minOperations ( s ) )

Index/key variables: i
Accumulator variables: result
Iterator variables: i
Python program:
def transformSubsequence ( n , m , A , B ) :
    if B is None or len ( B ) == 0 :
        return n
    dp = [ [ 0 for col in range ( m + 1 ) ] for row in range ( n + 1 ) ]
    for i in range ( n + 1 ) :
        for j in range ( m + 1 ) :
            if i == 0 or j == 0 :
                dp [ i ] [ j ] = 0
            elif A [ i - 1 ] == B [ j - 1 ] :
                dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]
            else :
                dp [ i ] [ j ] = max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] )
    return n - dp [ n ] [ m ]
if __name__ == " _ _ main _ _ " :
    N = 5
    M = 6
    A = [ 1 , 2 , 3 , 4 , 5 ]
    B = [ 2 , 5 , 6 , 4 , 9 , 12 ]
    print ( transformSubsequence ( N , M , A , B ) )

Index/key variables: i, j, m, n
Iterator variables: i, j
Python program:
def checkForPerfectSquare ( arr , i , j ) :
    mid , sum = 0 , 0
    for m in range ( i , j + 1 ) :
        sum += arr [ m ]
    low = 0
    high = sum // 2
    while ( low <= high ) :
        mid = low + ( high - low ) // 2
        if ( mid * mid == sum ) :
            return mid
        elif ( mid * mid > sum ) :
            high = mid - 1
        else :
            low = mid + 1
    return - 1
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 19 , 33 , 48 , 90 , 100 ]
    L = 1
    R = 3
    print ( checkForPerfectSquare ( arr , L , R ) )

Index/key variables: m
Accumulator variables: sum
Iterator variables: m
Python program:
def calcSubarray ( A , N ) :
    count = 0
    for i in range ( N ) :
        for j in range ( i + 1 , N ) :
            flag = True
            comm_diff = A [ i + 1 ] - A [ i ]
            for k in range ( i , j ) :
                if ( A [ k + 1 ] - A [ k ] == comm_diff ) :
                    continue
                else :
                    flag = False
                    break
            if ( flag ) :
                count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    A = [ 8 , 7 , 4 , 1 , 0 ]
    N = len ( A )
    print ( calcSubarray ( A , N ) )

Index/key variables: i, k
Accumulator variables: count
Iterator variables: i, j, k
Boolean variables: flag
Python program:
def maxSumSubarray ( arr ) :
    i = 0
    j = 1
    set = { }
    set [ arr [ 0 ] ] = 1
    sum = arr [ 0 ]
    maxsum = sum
    while ( i < len ( arr ) - 1 and j < len ( arr ) ) :
        if arr [ j ] not in set :
            sum = sum + arr [ j ]
            maxsum = max ( sum , maxsum )
            set [ arr [ j ] ] = 1
            j += 1
        else :
            sum -= arr [ i ]
            del set [ arr [ i ] ]
            i += 1
    return maxsum
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 1 , 5 ]
    ans = maxSumSubarray ( arr )
    print ( ans )

Index/key variables: i, j
Accumulator variables: sum
Python program:
from math import log2
def count_numbers ( L , R ) :
    ans = 0
    for n in range ( L , R + 1 ) :
        no_of_bits = int ( log2 ( n ) + 1 )
        no_of_set_bits = bin ( n ) . count ( '1' )
        if ( no_of_bits - no_of_set_bits == 1 ) :
            ans += 1
    return ans
if __name__ == ' _ _ main _ _ ' :
    L = 4
    R = 9
    print ( count_numbers ( L , R ) )

Accumulator variables: ans
Iterator variables: n
Python program:
import math
def count_numbers ( L , R ) :
    ans = 0 ;
    LogR = ( int ) ( math . log ( R ) + 1 ) ;
    for zero_bit in range ( LogR ) :
        cur = 0 ;
        for j in range ( zero_bit ) :
            cur |= ( 1 << j ) ;
        for j in range ( zero_bit + 1 , LogR ) :
            cur |= ( 1 << j ) ;
            if ( cur >= L and cur <= R ) :
                ans += 1 ;
    return ans ;
if __name__ == ' _ _ main _ _ ' :
    L = 4 ;
    R = 9 ;
    print ( count_numbers ( L , R ) ) ;

Accumulator variables: ans, cur
Iterator variables: j, zero_bit
Python program:
def findSum ( s ) :
    sum = 0
    for i in range ( len ( s ) ) :
        for j in range ( i + 1 , len ( s ) ) :
            if ( s [ i ] == s [ j ] ) :
                sum += ( j - i )
    return sum
s = " ttt "
print ( findSum ( s ) )

Index/key variables: i, j
Accumulator variables: sum
Iterator variables: i, j
Python program:
def countElements ( a , n ) :
    cnt = [ 0 ] * ( n + 1 )
    ans = 0
    for k in a :
        cnt [ k ] += 1
    for l in range ( n ) :
        sum = 0
        for r in range ( l , n ) :
            sum += a [ r ]
            if ( l == r ) :
                continue
            if ( sum <= n ) :
                ans += cnt [ sum ]
                cnt [ sum ] = 0
    return ans
if __name__ == ' _ _ main _ _ ' :
    a = [ 1 , 1 , 1 , 1 , 1 ]
    print ( countElements ( a , len ( a ) ) )

Index/key variables: k, r, sum
Accumulator variables: ans
Iterator variables: k, l, r
Python program:
def __gcd ( a , b ) :
    if ( b == 0 ) :
        return a ;
    else :
        return __gcd ( b , a % b ) ;
def maxGCD ( n ) :
    maxHcf = - 2391734235435 ;
    for i in range ( 1 , n + 1 ) :
        for j in range ( i + 1 , n + 1 ) :
            maxHcf = max ( maxHcf , __gcd ( i , j ) ) ;
    return maxHcf ;
if __name__ == ' _ _ main _ _ ' :
    n = 4 ;
    print ( maxGCD ( n ) ) ;

Iterator variables: i, j
Python program:
def removeOddIndexCharacters ( s ) :
    new_s = " "
    i = 0
    while i < len ( s ) :
        if ( i % 2 == 1 ) :
            i += 1
            continue
        new_s += s [ i ]
        i += 1
    return new_s
if __name__ == ' _ _ main _ _ ' :
    str = " abcdef "
    str = removeOddIndexCharacters ( str )
    print ( str )

Index/key variables: i
Accumulator variables: new_s
Python program:
def longestGP ( A , N ) :
    if ( N < 2 ) :
        return N
    length = 1
    common_ratio = 1
    maxlength = 1
    for i in range ( N - 1 ) :
        if ( A [ i + 1 ] % A [ i ] == 0 ) :
            if ( A [ i + 1 ] // A [ i ] == common_ratio ) :
                length = length + 1
                maxlength = max ( maxlength , length )
            else :
                common_ratio = A [ i + 1 ] // A [ i ]
                length = 2
        else :
            maxlength = max ( maxlength , length )
            length = 1
    maxlength = max ( maxlength , length )
    return maxlength
arr = [ 1 , 2 , 4 , 7 , 14 , 28 , 56 , 89 ]
N = len ( arr )
print ( longestGP ( arr , N ) )

Index/key variables: i
Iterator variables: i
Python program:
def uncrossedLines ( a , b , n , m ) :
    dp = [ [ 0 for x in range ( m + 1 ) ] for y in range ( n + 1 ) ]
    for i in range ( n + 1 ) :
        for j in range ( m + 1 ) :
            if ( i == 0 or j == 0 ) :
                dp [ i ] [ j ] = 0
            elif ( a [ i - 1 ] == b [ j - 1 ] ) :
                dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ]
            else :
                dp [ i ] [ j ] = max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] )
    return dp [ n ] [ m ]
if __name__ == " _ _ main _ _ " :
    A = [ 3 , 9 , 2 ]
    B = [ 3 , 2 , 9 ]
    N = len ( A )
    M = len ( B )
    print ( uncrossedLines ( A , B , N , M ) )

Index/key variables: i, j, m, n
Iterator variables: i, j
Python program:
def minFlips ( mat , s ) :
    N = len ( mat )
    M = len ( mat [ 0 ] )
    count = 0
    for i in range ( N ) :
        for j in range ( M ) :
            if ( mat [ i ] [ j ] != ord ( s [ i + j ] ) - ord ( '0' ) ) :
                count += 1
    return count
mat = [ [ 1 , 0 , 1 ] , [ 0 , 1 , 1 ] , [ 0 , 0 , 0 ] ]
s = "10001"
print ( minFlips ( mat , s ) )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
def revNum ( N ) :
    x = 0
    while ( N ) :
        x = x * 10 + N % 10
        N = N // 10
    return x
def ctNonPalin ( arr , N ) :
    Res = 0
    for i in range ( N ) :
        x = revNum ( arr [ i ] )
        if ( x == arr [ i ] ) :
            continue
        else :
            Res += ( arr [ i ] % 10 == N % 10 )
    return Res
if __name__ == ' _ _ main _ _ ' :
    arr = [ 121 , 134 , 2342 , 4514 ]
    N = len ( arr )
    print ( ctNonPalin ( arr , N ) )

Index/key variables: i
Accumulator variables: Res
Iterator variables: i
Python program:
def minServerLoads ( n , servers ) :
    totalLoad = sum ( servers )
    requiredLoad = totalLoad // 2
    dp = [ [ 0 for col in range ( requiredLoad + 1 ) ] for row in range ( n + 1 ) ]
    for i in range ( 1 , n + 1 ) :
        for j in range ( 1 , requiredLoad + 1 ) :
            if servers [ i - 1 ] > j :
                dp [ i ] [ j ] = dp [ i - 1 ] [ j ]
            else :
                dp [ i ] [ j ] = max ( dp [ i - 1 ] [ j ] , servers [ i - 1 ] + dp [ i - 1 ] [ j - servers [ i - 1 ] ] )
    return totalLoad - 2 * dp [ n ] [ requiredLoad ]
N = 5 ;
servers = [ 1 , 2 , 3 , 4 , 5 ]
print ( minServerLoads ( N , servers ) )

Index/key variables: i, j, n, requiredLoad
Iterator variables: i, j
Python program:
def maxLenSub ( arr , N ) :
    Pos = 0
    Neg = 0
    res = 0
    for i in range ( N ) :
        if ( arr [ i ] == 0 ) :
            Pos = Neg = 0
        elif ( arr [ i ] > 0 ) :
            Pos += 1
            if ( Neg != 0 ) :
                Neg += 1
            res = max ( res , Pos )
        else :
            Pos , Neg = Neg , Pos
            Neg += 1
            if ( Pos != 0 ) :
                Pos += 1
            res = max ( res , Pos )
    return res
if __name__ == ' _ _ main _ _ ' :
    arr = [ - 1 , - 2 , - 3 , 0 , 1 ]
    N = len ( arr )
    print ( maxLenSub ( arr , N ) )

Index/key variables: i
Accumulator variables: Neg, Pos
Iterator variables: i