dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
class Node :
    def __init__ ( self , key ) :
        self . data = key
        self . left = None
        self . right = None
def FindPath ( root , path , key ) :
    if root == None :
        return False
    path . append ( root . data )
    if root . data == key :
        return True
    if ( FindPath ( root . left , path , key ) or FindPath ( root . right , path , key ) ) :
        return True
    path . pop ( )
    return False
def minMaxNodeInPath ( root , a , b ) :
    Path1 = [ ]
    Path2 = [ ]
    min1 , max1 = float ( ' inf ' ) , float ( ' - inf ' )
    min2 , max2 = float ( ' inf ' ) , float ( ' - inf ' )
    i , j = 0 , 0
    if ( FindPath ( root , Path1 , a ) and FindPath ( root , Path2 , b ) ) :
        while i < len ( Path1 ) and i < len ( Path2 ) :
            if Path1 [ i ] != Path2 [ i ] :
                break
            i += 1
        i -= 1
        j = i
        while i < len ( Path1 ) :
            if min1 > Path1 [ i ] :
                min1 = Path1 [ i ]
            if max1 < Path1 [ i ] :
                max1 = Path1 [ i ]
            i += 1
        while j < len ( Path2 ) :
            if min2 > Path2 [ j ] :
                min2 = Path2 [ j ]
            if max2 < Path2 [ j ] :
                max2 = Path2 [ j ]
            j += 1
        print ( " Min ▁ = " , min ( min1 , min2 ) )
        print ( " Max ▁ = " , max ( max1 , max2 ) )
    else :
        print ( " Min = - 1 Max = - 1 " )
if __name__ == " _ _ main _ _ " :
    root = Node ( 20 )
    root . left = Node ( 8 )
    root . right = Node ( 22 )
    root . left . left = Node ( 5 )
    root . left . right = Node ( 3 )
    root . right . left = Node ( 4 )
    root . right . right = Node ( 25 )
    root . left . right . left = Node ( 10 )
    root . left . right . right = Node ( 14 )
    a , b = 5 , 14
    minMaxNodeInPath ( root , a , b )

Index/key variables: i, j
Class/struct names: Node
Python program:
class Node :
    def __init__ ( self ) :
        self . data = 0
        self . left = None
        self . right = None
def newNode ( data ) :
    node = Node ( )
    node . data = data
    node . left = None
    node . right = None
    return node
def getPath ( root , arr , x ) :
    if ( root == None ) :
        return False
    arr . append ( root . data )
    if ( root . data == x ) :
        return True
    if ( getPath ( root . left , arr , x ) or getPath ( root . right , arr , x ) ) :
        return True
    arr . pop ( )
    return False
def sumOddNodes ( root , n1 , n2 ) :
    path1 = [ ]
    path2 = [ ]
    getPath ( root , path1 , n1 )
    getPath ( root , path2 , n2 )
    intersection = - 1
    i = 0
    j = 0
    while ( i != len ( path1 ) or j != len ( path2 ) ) :
        if ( i == j and path1 [ i ] == path2 [ j ] ) :
            i = i + 1
            j = j + 1
        else :
            intersection = j - 1
            break
    sum = 0
    i = len ( path1 ) - 1
    while ( i > intersection ) :
        if ( path1 [ i ] % 2 != 0 ) :
            sum += path1 [ i ]
        i = i - 1
    i = intersection
    while ( i < len ( path2 ) ) :
        if ( path2 [ i ] % 2 != 0 ) :
            sum += path2 [ i ]
        i = i + 1
    return sum
root = newNode ( 1 )
root . left = newNode ( 2 )
root . right = newNode ( 3 )
root . left . left = newNode ( 4 )
root . left . right = newNode ( 5 )
root . right . right = newNode ( 6 )
node1 = 5
node2 = 6
print ( sumOddNodes ( root , node1 , node2 ) )

Index/key variables: i, j
Accumulator variables: sum
Class/struct names: Node
Python program:
MAX = 1000
def findLCA ( n1 , n2 , parent ) :
    visited = [ False for i in range ( MAX ) ]
    visited [ n1 ] = True
    while ( parent [ n1 ] != - 1 ) :
        visited [ n1 ] = True
        n1 = parent [ n1 ]
    visited [ n1 ] = True
    while ( visited [ n2 ] == False ) :
        n2 = parent [ n2 ]
    return n2
def insertAdj ( parent , i , j ) :
    parent [ i ] = j
if __name__ == ' _ _ main _ _ ' :
    parent = [ 0 for i in range ( MAX ) ]
    parent [ 20 ] = - 1
    insertAdj ( parent , 8 , 20 )
    insertAdj ( parent , 22 , 20 )
    insertAdj ( parent , 4 , 8 )
    insertAdj ( parent , 12 , 8 )
    insertAdj ( parent , 10 , 12 )
    insertAdj ( parent , 14 , 12 )
    print ( findLCA ( 10 , 14 , parent ) )

Index/key variables: i, n1, n2
Python program:
MAXN = 100001
tree = [ 0 ] * MAXN
for i in range ( MAXN ) :
    tree [ i ] = [ ]
path = [ 0 ] * 3
for i in range ( 3 ) :
    path [ i ] = [ 0 ] * MAXN
flag = False
def dfs ( cur : int , prev : int , pathNumber : int , ptr : int , node : int ) -> None :
    global tree , path , flag
    for i in range ( len ( tree [ cur ] ) ) :
        if ( tree [ cur ] [ i ] != prev and not flag ) :
            path [ pathNumber ] [ ptr ] = tree [ cur ] [ i ]
            if ( tree [ cur ] [ i ] == node ) :
                flag = True
                path [ pathNumber ] [ ptr + 1 ] = - 1
                return
            dfs ( tree [ cur ] [ i ] , cur , pathNumber , ptr + 1 , node )
def LCA ( a : int , b : int ) -> int :
    global flag
    if ( a == b ) :
        return a
    path [ 1 ] [ 0 ] = path [ 2 ] [ 0 ] = 1
    flag = False
    dfs ( 1 , 0 , 1 , 1 , a )
    flag = False
    dfs ( 1 , 0 , 2 , 1 , b )
    i = 0
    while ( path [ 1 ] [ i ] == path [ 2 ] [ i ] ) :
        i += 1
    return path [ 1 ] [ i - 1 ]
def addEdge ( a : int , b : int ) -> None :
    tree [ a ] . append ( b )
    tree [ b ] . append ( a )
if __name__ == " _ _ main _ _ " :
    n = 8
    addEdge ( 1 , 2 )
    addEdge ( 1 , 3 )
    addEdge ( 2 , 4 )
    addEdge ( 2 , 5 )
    addEdge ( 2 , 6 )
    addEdge ( 3 , 7 )
    addEdge ( 3 , 8 )
    print ( " LCA ( 4 , ▁ 7 ) ▁ = ▁ { } " . format ( LCA ( 4 , 7 ) ) )
    print ( " LCA ( 4 , ▁ 6 ) ▁ = ▁ { } " . format ( LCA ( 4 , 6 ) ) )

Index/key variables: a, b, cur, i, pathNumber, ptr
Iterator variables: i
Boolean variables: flag
Python program:
def findPair ( a , n , z ) :
    for i in range ( n ) :
        for j in range ( n ) :
            if ( i != j and a [ i ] + a [ j ] == z ) :
                return True
    return False
a = [ 1 , - 2 , 1 , 0 , 5 ]
z = 0
n = len ( a )
if ( findPair ( a , n , z ) ) :
    print ( " True " )
else :
    print ( " False " )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def printt ( a , n ) :
    for i in range ( n ) :
        for j in range ( n ) :
            if ( i != j ) :
                print ( a [ i ] , " " , a [ j ] )
a = [ 1 , 2 , 3 ]
n = len ( a )
printt ( a , n )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def maximumSum ( arr , N ) :
    Sum = 0 ;
    for i in range ( 1 , N ) :
        if ( arr [ i ] > arr [ i - 1 ] ) :
            Sum += ( arr [ i ] - arr [ i - 1 ] )
    return Sum ;
arr = [ 1 , 5 , 3 ] ;
N = len ( arr )
print ( maximumSum ( arr , N ) ) ;

Index/key variables: i
Accumulator variables: Sum
Iterator variables: i
Python program:
def stoogesort ( arr , l , h ) :
    if ( l >= h ) :
        return
    if ( arr [ l ] > arr [ h ] ) :
        temp = arr [ l ]
        arr [ l ] = arr [ h ]
        arr [ h ] = temp
    if ( h - l + 1 > 2 ) :
        t = ( h - l + 1 ) // 3
        stoogesort ( arr , l , h - t )
        stoogesort ( arr , l + t , h )
        stoogesort ( arr , l , h - t )
arr = [ 2 , 4 , 5 , 3 , 1 ]
N = len ( arr )
stoogesort ( arr , 0 , N - 1 )
for i in range ( N ) :
    print ( arr [ i ] , end = " ▁ " )

Index/key variables: h, i, l
Iterator variables: i
Python program:
def countSubarrays ( arr , n ) :
    count = 0
    for i in range ( n ) :
        sum = 0
        for j in range ( i , n ) :
            if ( ( j - i ) % 2 == 0 ) :
                sum += arr [ j ]
            else :
                sum -= arr [ j ]
            if ( sum == 0 ) :
                count += 1
    print ( count )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 4 , 6 , 4 , 2 ]
    n = len ( arr )
    countSubarrays ( arr , n )

Index/key variables: j
Accumulator variables: count, sum
Iterator variables: i, j
Python program:
def findCountRooks ( row , col , n , k ) :
    res = n - k
    print ( res )
    ri = 0
    ci = 0
    while ( res > 0 ) :
        while ( ri < k and row [ ri ] == 1 ) :
            ri += 1
        while ( ci < k and col [ ci ] == 1 ) :
            ci += 1
        print ( ( ri + 1 ) , " " , ( ci + 1 ) )
        ri += 1
        ci += 1
        res -= 1
n = 4
k = 2
row = [ 1 , 2 ]
col = [ 4 , 2 ]
findCountRooks ( row , col , n , k )

Index/key variables: ci, ri
Accumulator variables: res
Python program:
from math import log2
def checkIfDivisible ( string , num ) :
    powerOf2 = int ( log2 ( num ) ) ;
    if ( len ( string ) < powerOf2 ) :
        return False ;
    if ( powerOf2 == 0 ) :
        return True ;
    number = 0 ;
    length = len ( string ) ;
    for i in range ( length - powerOf2 , length ) :
        number += ( ( ord ( string [ i ] ) - ord ( '0' ) ) * ( 10 ** ( powerOf2 - 1 ) ) ) ;
        powerOf2 -= 1 ;
    if ( number % num ) :
        return False ;
    else :
        return True ;
if __name__ == " _ _ main _ _ " :
    string = "213467756564" ;
    num = 4 ;
    if ( checkIfDivisible ( string , num ) ) :
        print ( " Yes " ) ;
    else :
        print ( " No " ) ;

Index/key variables: i
Accumulator variables: number, powerOf2
Iterator variables: i
Python program:
def check_order ( arr ) :
    cnt = 0
    for i in range ( len ( arr ) - 1 ) :
        if ( abs ( arr [ i + 1 ] - arr [ i ] ) > 1 ) :
            cnt += 1
    if ( abs ( arr [ 0 ] - arr [ len ( arr ) - 1 ] ) > 1 ) :
        cnt += 1
    if ( cnt > 1 ) :
        return False
    return True
arr = [ 2 , 3 , 4 , 5 , 1 ]
if ( check_order ( arr ) ) :
    print ( " YES " )
else :
    print ( " NO " )

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
def maxProfit ( prices , n ) :
    if ( n <= 1 ) :
        return 0
    rest = [ 0 ] * n
    hold = [ 0 ] * n
    sold = [ 0 ] * n
    rest [ 0 ] = 0
    hold [ 0 ] = - prices [ 0 ]
    sold [ 0 ] = 0
    for i in range ( 1 , n ) :
        rest [ i ] = max ( rest [ i - 1 ] , sold [ i - 1 ] )
        hold [ i ] = max ( hold [ i - 1 ] , rest [ i - 1 ] - prices [ i ] )
        sold [ i ] = hold [ i - 1 ] + prices [ i ]
    return max ( rest [ n - 1 ] , sold [ n - 1 ] )
price = [ 2 , 4 , 5 , 0 , 2 ]
n = len ( price )
print ( maxProfit ( price , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def longest_subarray ( arr , d ) :
    ( i , j , e ) = ( 0 , 1 , 0 )
    for i in range ( d - 1 ) :
        if arr [ i ] == arr [ i + 1 ] :
            j += 1
        else :
            j = 1
        if e < j :
            e = j
    return e
arr = [ 1 , 2 , 3 , 4 ]
N = len ( arr )
print ( longest_subarray ( arr , N ) )

Index/key variables: i
Accumulator variables: j
Iterator variables: i
Python program:
def countPairs ( A , B ) :
    countY = 0
    countX = ( B - A ) + 1
    next_val = 9
    while ( next_val <= B ) :
        if ( next_val >= A ) :
            countY += 1
        next_val = next_val * 10 + 9
    return ( countX * countY )
if __name__ == ' _ _ main _ _ ' :
    A = 1
    B = 16
    print ( countPairs ( A , B ) )

Accumulator variables: countY
Python program:
max_len = 100005
cnt = [ 0 ] * max_len
def precompute ( s , K ) :
    n = len ( s )
    for i in range ( n - 1 ) :
        cnt [ i + 1 ] = cnt [ i ]
        if s [ i : len ( K ) + i ] == K :
            cnt [ i + 1 ] += 1
if __name__ == " _ _ main _ _ " :
    s = " ABCABCABABC "
    K = " ABC "
    precompute ( s , K )
    Q = [ [ 1 , 6 ] , [ 5 , 11 ] ]
    for it in Q :
        print ( cnt [ it [ 1 ] - 1 ] - cnt [ it [ 0 ] - 1 ] )

Index/key variables: i
Iterator variables: i, it
Python program:
def getXOR ( BITree , index ) :
    ans = 0
    index += 1
    while ( index > 0 ) :
        ans ^= BITree [ index ]
        index -= index & ( - index )
    return ans
def updateBIT ( BITree , n , index , val ) :
    index = index + 1
    while ( index <= n ) :
        BITree [ index ] ^= val
        index += index & ( - index )
def constructBITree ( arr , n ) :
    BITree = [ 0 ] * ( n + 1 )
    for i in range ( n ) :
        updateBIT ( BITree , n , i , arr [ i ] )
    return BITree
def rangeXor ( BITree , l , r ) :
    return ( getXOR ( BITree , r ) ^ getXOR ( BITree , l - 1 ) )
if __name__ == " _ _ main _ _ " :
    A = [ 2 , 1 , 1 , 3 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]
    n = len ( A )
    q = [ [ 1 , 0 , 9 ] , [ 2 , 3 , 6 ] , [ 2 , 5 , 5 ] , [ 2 , 8 , 1 ] , [ 1 , 0 , 9 ] ]
    BITree = constructBITree ( A , n )
    for i in range ( len ( q ) ) :
        id = q [ i ] [ 0 ]
        if ( id == 1 ) :
            L = q [ i ] [ 1 ]
            R = q [ i ] [ 2 ]
            print ( " XOR ▁ of ▁ elements ▁ in ▁ " " given ▁ range ▁ is ▁ " , rangeXor ( BITree , L , R ) )
        else :
            idx = q [ i ] [ 1 ]
            val = q [ i ] [ 2 ]
            A [ idx ] ^= val
            updateBIT ( BITree , n , idx , val )

Index/key variables: i, idx, index
Accumulator variables: ans
Iterator variables: i
Python program:
arr = [ 0 ] * 1000001
dp = [ 0 ] * 1000001
def count ( ) :
    maxN = 1000000
    for i in range ( 0 , maxN ) :
        arr [ i ] = 1
    arr [ 0 ] = 0
    arr [ 1 ] = 0
    i = 2
    while ( i * i <= maxN ) :
        if ( arr [ i ] == 1 ) :
            for j in range ( 2 * i , maxN + 1 , i ) :
                arr [ j ] = 0
        i += 1
    cnt = 0
    for i in range ( 0 , maxN + 1 ) :
        if ( arr [ i ] == 1 ) :
            cnt += 1
        if ( arr [ cnt ] == 1 ) :
            dp [ i ] = 1
        else :
            dp [ i ] = 0
    for i in range ( 0 , maxN + 1 ) :
        dp [ i ] += dp [ i - 1 ]
L = 4
R = 12
count ( )
print ( dp [ R ] - dp [ L - 1 ] )

Index/key variables: R, cnt, i, j
Iterator variables: i, j
Python program:
def findUngroupedElement ( s , k ) :
    n = len ( s ) ;
    b = [ 0 ] * 26
    for i in range ( n ) :
        p = s [ i ]
        b [ ord ( p ) - ord ( ' a ' ) ] += 1
    sum = 0 ;
    for i in range ( 26 ) :
        if ( b [ i ] > k ) :
            sum += b [ i ] - k
    print ( sum )
s = " stayinghomesaveslife "
k = 1
findUngroupedElement ( s , k )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def findSolution ( N ) :
    if ( N % 4 != 0 ) :
        print ( - 1 )
    else :
        temp = 0
        sum_odd = 0
        sum_even = 0
        result = [ 0 ] * N
        for i in range ( 0 , N , 2 ) :
            temp += 2
            result [ i + 1 ] = temp
            sum_even += result [ i + 1 ]
            result [ i ] = temp - 1
            sum_odd += result [ i ]
        diff = sum_even - sum_odd
        result [ N - 2 ] += diff
        for i in range ( N ) :
            print ( result [ i ] , end = " ▁ " )
        print ( )
N = 8 ;
findSolution ( N )

Index/key variables: i
Accumulator variables: sum_even, sum_odd, temp
Iterator variables: i
Python program:
def mutually_coprime ( n ) :
    if ( n <= 3 ) :
        for j in range ( 1 , n + 1 ) :
            print ( j , end = " ▁ " )
        print ( )
    else :
        print ( 1 , 2 , 3 )
        for j in range ( 4 , n , 2 ) :
            print ( j , ( j + 1 ) )
        if ( n % 2 == 0 ) :
            print ( n )
if __name__ == " _ _ main _ _ " :
    n = 9
    mutually_coprime ( n )

Iterator variables: j
Python program:
def findMaxSum ( arr , n ) :
    a = [ ]
    b = [ ]
    for i in range ( n ) :
        if ( arr [ i ] > 0 ) :
            a . append ( arr [ i ] )
        elif ( arr [ i ] < 0 ) :
            b . append ( arr [ i ] )
    a . sort ( )
    b . sort ( )
    p = len ( a ) - 1
    q = len ( b ) - 1
    s = 0
    while ( p >= 0 and q >= 0 ) :
        if ( a [ p ] + b [ q ] > 0 ) :
            s = s + a [ p ] + b [ q ]
        else :
            break
        p = p - 1
        q = q - 1
    return s
arr1 = [ 1 , - 2 , 3 , 4 , - 5 , 8 ]
n1 = len ( arr1 )
print ( findMaxSum ( arr1 , n1 ) )

Index/key variables: i, p, q
Accumulator variables: a, b
Iterator variables: i
Python program:
def SieveOfEratosthenes ( prime , p_size ) :
    prime [ 0 ] = False
    prime [ 1 ] = False
    p = 2
    while ( p * p <= p_size ) :
        if ( prime [ p ] ) :
            for i in range ( p * 2 , p_size + 1 , p ) :
                prime [ i ] = False
        p += 1
def PrimeDegreeNodes ( prufer , n ) :
    nodes = n + 2
    prime = [ True ] * ( nodes + 1 )
    SieveOfEratosthenes ( prime , nodes + 1 )
    degree = [ 0 ] * ( n + 2 + 1 ) ;
    for i in range ( 1 , nodes + 1 ) :
        degree [ i ] = 1 ;
    for i in range ( 0 , n ) :
        degree [ prufer [ i ] ] += 1
    for i in range ( 1 , nodes + 1 ) :
        if prime [ degree [ i ] ] :
            print ( i , end = ' ▁ ' )
if __name__ == ' _ _ main _ _ ' :
    a = [ 4 , 1 , 3 , 4 ]
    n = len ( a )
    PrimeDegreeNodes ( a , n )

Index/key variables: i, p
Iterator variables: i
Python program:
def kthSmallest ( a , k ) :
    res = 0
    j = 0
    for i in range ( 32 ) :
        while ( j < 32 and ( a & ( 1 << j ) ) ) :
            j += 1
        if ( k & ( 1 << i ) ) :
            res |= ( 1 << j )
        j += 1
    return res
a = 5
k = 3
print ( kthSmallest ( a , k ) )

Accumulator variables: j, res
Iterator variables: i
Python program:
n = 10005 ;
Prime = [ True for i in range ( n + 1 ) ]
def SieveOfEratosthenes ( ) :
    i = 2
    Prime [ 0 ] = Prime [ 1 ] = False ;
    while i * i <= 10005 :
        if ( Prime [ i ] ) :
            for j in range ( 2 * i , 10005 ) :
                Prime [ j ] = False
        i += 1
def primeDegreeNodes ( N , M , edges ) :
    Adj = [ [ ] for i in range ( N + 1 ) ] ;
    for i in range ( M ) :
        x = edges [ i ] [ 0 ] ;
        y = edges [ i ] [ 1 ] ;
        Adj [ x ] . append ( y ) ;
        Adj [ y ] . append ( x ) ;
    SieveOfEratosthenes ( ) ;
    for i in range ( N + 1 ) :
        x = len ( Adj [ i ] ) ;
        if ( Prime [ x ] ) :
            print ( i , end = ' ▁ ' )
if __name__ == " _ _ main _ _ " :
    N = 4
    M = 6
    edges = [ [ 1 , 2 ] , [ 1 , 3 ] , [ 1 , 4 ] , [ 2 , 3 ] , [ 2 , 4 ] , [ 3 , 4 ] ] ;
    primeDegreeNodes ( N , M , edges ) ;

Index/key variables: i, j, x, y
Iterator variables: i, j
Python program:
mod = 1000000007
def countWays ( colored , count , n ) :
    if ( count == n ) :
        return 1
    answer = 0
    for i in range ( 1 , n + 1 ) :
        if ( colored [ i ] == 0 ) :
            if ( colored [ i - 1 ] == 1 or colored [ i + 1 ] == 1 ) :
                colored [ i ] = 1
                answer = ( ( answer + countWays ( colored , count + 1 , n ) ) % mod )
                colored [ i ] = 0
    return answer
def waysToColor ( arr , n , k ) :
    colored = [ 0 ] * ( n + 2 )
    for i in range ( k ) :
        colored [ arr [ i ] ] = 1
    return countWays ( colored , k , n )
if __name__ == " _ _ main _ _ " :
    N = 6
    K = 3
    arr = [ 1 , 2 , 6 ]
    print ( waysToColor ( arr , N , K ) )

Index/key variables: i
Iterator variables: i
Python program:
def ShortestPalindrome ( s ) :
    n = len ( s )
    ans = s [ 0 ]
    for i in range ( 1 , n ) :
        ans = min ( ans , s [ i ] )
    return ans
s = " geeksforgeeks "
print ( ShortestPalindrome ( s ) )

Index/key variables: i
Iterator variables: i
Python program:
def findSubsequence ( arr , n ) :
    sign = [ 0 ] * n
    for i in range ( n ) :
        if ( arr [ i ] > 0 ) :
            sign [ i ] = 1
        else :
            sign [ i ] = - 1
    k = 0
    result = [ 0 ] * n
    i = 0
    while i < n :
        cur = arr [ i ]
        j = i
        while ( j < n and sign [ i ] == sign [ j ] ) :
            cur = max ( cur , arr [ j ] )
            j += 1
        result [ k ] = cur
        k += 1
        i = j - 1
        i += 1
    for i in range ( k ) :
        print ( result [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ - 4 , 9 , 4 , 11 , - 5 , - 17 , 9 , - 3 , - 5 , 2 ]
    n = len ( arr )
    findSubsequence ( arr , n )

Index/key variables: i, j, k
Iterator variables: i
Python program:
def isPalindrome ( r ) :
    p = r
    p = " " . join ( reversed ( p ) )
    return ( r == p )
def PrefixSuffixPalindrome ( st ) :
    n = len ( st )
    length = 0
    for i in range ( n // 2 ) :
        if ( st [ i ] != st [ n - i - 1 ] ) :
            length = i
            break
    prefix = " "
    suffix = " "
    midPal = " "
    prefix = st [ : length ]
    suffix = st [ n - length : ]
    st = st [ length : n - 2 * length + length ]
    for i in range ( 1 , len ( st ) + 1 ) :
        y = st [ 0 : i ]
        if ( isPalindrome ( y ) ) :
            if ( len ( midPal ) < len ( y ) ) :
                midPal = y
    for i in range ( 1 , len ( st ) + 1 ) :
        y = st [ len ( st ) - i ]
        if ( isPalindrome ( y ) ) :
            if ( len ( midPal ) < len ( y ) ) :
                midPal = y
    answer = prefix + midPal + suffix
    return answer
if __name__ == " _ _ main _ _ " :
    st = " abcdfdcecba " ;
    print ( PrefixSuffixPalindrome ( st ) )

Index/key variables: i
Iterator variables: i
Python program:
import sys
INT_MAX = sys . maxsize ;
INT_MIN = - ( sys . maxsize - 1 )
def minimumAdjacentDifference ( a , n , k ) :
    minDiff = INT_MAX ;
    for i in range ( 1 << n ) :
        cnt = bin ( i ) . count ( '1' ) ;
        if ( cnt == n - k ) :
            temp = [ ] ;
            for j in range ( n ) :
                if ( ( i & ( 1 << j ) ) != 0 ) :
                    temp . append ( a [ j ] ) ;
            maxDiff = INT_MIN ;
            for j in range ( len ( temp ) - 1 ) :
                maxDiff = max ( maxDiff , temp [ j + 1 ] - temp [ j ] ) ;
            minDiff = min ( minDiff , maxDiff ) ;
    return minDiff ;
if __name__ == " _ _ main _ _ " :
    n = 5 ;
    k = 2 ;
    a = [ 3 , 7 , 8 , 10 , 14 ] ;
    print ( minimumAdjacentDifference ( a , n , k ) ) ;

Index/key variables: j
Accumulator variables: temp
Iterator variables: i, j
Python program:
import sys
INT_MAX = sys . maxsize ;
INT_MIN = - ( sys . maxsize - 1 ) ;
def minimumAdjacentDifference ( a , n , k ) :
    minDiff = INT_MAX ;
    for i in range ( k + 1 ) :
        maxDiff = INT_MIN ;
        for j in range ( n - k - 1 ) :
            for p in range ( i , i + j + 1 ) :
                maxDiff = max ( maxDiff , a [ p + 1 ] - a [ p ] ) ;
        minDiff = min ( minDiff , maxDiff ) ;
    return minDiff ;
if __name__ == " _ _ main _ _ " :
    n = 5 ;
    k = 2 ;
    a = [ 3 , 7 , 8 , 10 , 14 ] ;
    print ( minimumAdjacentDifference ( a , n , k ) ) ;

Index/key variables: p
Iterator variables: i, j, p
Python program:
def gcdFunc ( a , b ) :
    if ( b == 0 ) :
        return a
    return gcdFunc ( b , a % b )
def findMinimumElements ( a , n ) :
    b = [ 0 ] * ( n - 1 )
    for i in range ( 1 , n ) :
        b [ i - 1 ] = a [ i ] - a [ i - 1 ]
    gcd = b [ 0 ]
    for i in range ( n - 1 ) :
        gcd = gcdFunc ( gcd , b [ i ] )
    ans = 0
    for i in range ( n - 1 ) :
        ans += ( b [ i ] // gcd ) - 1
    return ans
arr1 = [ 1 , 6 , 8 , 10 , 14 , 16 ]
n1 = len ( arr1 )
print ( findMinimumElements ( arr1 , n1 ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def checkPermutation ( arr , n ) :
    sum = 0 ;
    for i in range ( n ) :
        sum += arr [ i ] ;
    prefix = [ 0 ] * ( n + 1 ) ;
    prefix [ 0 ] = arr [ 0 ] ;
    for i in range ( n ) :
        prefix [ i ] = prefix [ i - 1 ] + arr [ i ] ;
    for i in range ( n - 1 ) :
        lsum = prefix [ i ] ;
        rsum = sum - prefix [ i ] ;
        l_len = i + 1
        r_len = n - i - 1 ;
        if ( ( ( 2 * lsum ) == ( l_len * ( l_len + 1 ) ) ) and ( ( 2 * rsum ) == ( r_len * ( r_len + 1 ) ) ) ) :
            return True ;
    return False ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 5 , 3 , 4 , 1 , 2 ]
    n = len ( arr )
    if ( checkPermutation ( arr , n ) ) :
        print ( " Yes " ) ;
    else :
        print ( " No " ) ;

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def findTheNumber ( n ) :
    if ( n == 1 ) :
        print ( " Impossible " )
        return
    for i in range ( n - 1 ) :
        print ( "5" , end = " " )
    print ( "4" )
if __name__ == ' _ _ main _ _ ' :
    n = 12
    findTheNumber ( n )

Iterator variables: i