dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
MAX = 256
def minimumOperation ( s ) :
    n = len ( s )
    first_occ = [ - 1 ] * MAX
    res = float ( ' inf ' )
    for i in range ( 0 , n ) :
        x = s [ i ]
        if first_occ [ ord ( x ) ] == - 1 :
            first_occ [ ord ( x ) ] = i
        else :
            last_occ = n - i - 1
            res = min ( res , first_occ [ ord ( x ) ] + last_occ )
    return res
if __name__ == " _ _ main _ _ " :
    s = " bacdefghipalop "
    print ( minimumOperation ( s ) )

Index/key variables: i
Iterator variables: i
Python program:
def getSmallestAndLargest ( s , k ) :
    currStr = s [ : k ]
    lexMin = currStr
    lexMax = currStr
    for i in range ( k , len ( s ) ) :
        currStr = currStr [ 1 : k ] + s [ i ]
        if ( lexMax < currStr ) :
            lexMax = currStr
        if ( lexMin > currStr ) :
            lexMin = currStr
    print ( lexMin )
    print ( lexMax )
if __name__ == ' _ _ main _ _ ' :
    str1 = " GeeksForGeeks "
    k = 3
    getSmallestAndLargest ( str1 , k )

Index/key variables: i
Iterator variables: i
Python program:
def printInitials ( string : str ) :
    length = len ( string )
    string . strip ( )
    t = " "
    for i in range ( length ) :
        ch = string [ i ]
        if ch != ' ▁ ' :
            t += ch
        else :
            print ( t [ 0 ] . upper ( ) + " . ▁ " , end = " " )
            t = " "
    temp = " "
    for j in range ( len ( t ) ) :
        if j == 0 :
            temp += t [ 0 ] . upper ( )
        else :
            temp += t [ j ] . lower ( )
    print ( temp )
if __name__ == " _ _ main _ _ " :
    string = " ishita ▁ bhuiya "
    printInitials ( string )

Index/key variables: i, j
Accumulator variables: t, temp
Iterator variables: i, j
Python program:
def findSubstrings ( s , k ) :
    ans = 0
    n = len ( s )
    for i in range ( n ) :
        cnt = [ 0 ] * 26
        for j in range ( i , n ) :
            cnt [ ord ( s [ j ] ) - ord ( ' a ' ) ] += 1
            if ( cnt [ ord ( s [ j ] ) - ord ( ' a ' ) ] <= k ) :
                ans += 1
            else :
                break
    return ans
if __name__ == " _ _ main _ _ " :
    S = " aaabb "
    k = 2
    print ( findSubstrings ( S , k ) )

Index/key variables: j
Accumulator variables: ans
Iterator variables: i, j
Python program:
MAX = 26
def targetstring ( str1 , str2 ) :
    l1 = len ( str1 )
    l2 = len ( str2 )
    if ( l1 != l2 ) :
        return False
    map = [ 0 ] * MAX
    for i in range ( l1 ) :
        map [ ord ( str1 [ i ] ) - ord ( ' a ' ) ] += 1
    for i in range ( l2 ) :
        map [ ord ( str2 [ i ] ) - ord ( ' a ' ) ] -= 1
        if ( map [ ord ( str2 [ i ] ) - ord ( ' a ' ) ] < 0 ) :
            return False
    return True
if __name__ == " _ _ main _ _ " :
    str1 = " geeksforgeeks "
    str2 = " geegeeksksfor "
    if ( targetstring ( str1 , str2 ) ) :
        print ( " YES " )
    else :
        print ( " NO " )

Index/key variables: i
Iterator variables: i
Python program:
def isDigitPresent ( x , d ) :
    while ( x > 0 ) :
        if ( x % 10 == d ) :
            break
        x = x / 10
    return ( x > 0 )
def printNumbers ( n , d ) :
    for i in range ( 0 , n + 1 ) :
        if ( i == d or isDigitPresent ( i , d ) ) :
            print ( i , end = " ▁ " )
n = 47
d = 7
print ( " The ▁ number ▁ of ▁ values ▁ are " )
printNumbers ( n , d )

Iterator variables: i
Python program:
def findExtraCharacter ( strA , strB ) :
    m1 = { }
    for i in strB :
        if i in m1 :
            m1 [ i ] += 1
        else :
            m1 [ i ] = 1
    for i in strA :
        m1 [ i ] -= 1
    for h1 in m1 :
        if m1 [ h1 ] == 1 :
            return h1
if __name__ == " _ _ main _ _ " :
    strA = ' abcd '
    strB = ' cbdad '
    print ( findExtraCharacter ( strA , strB ) )

Index/key variables: h1, i
Iterator variables: h1, i
Python program:
def findExtraCharcter ( strA , strB ) :
    res = 0
    for i in range ( 0 , len ( strA ) ) :
        res = res ^ ( ord ) ( strA [ i ] )
    for i in range ( 0 , len ( strB ) ) :
        res = res ^ ( ord ) ( strB [ i ] )
    return ( ( chr ) ( res ) ) ;
strA = " abcd "
strB = " cbdad "
print ( findExtraCharcter ( strA , strB ) )

Index/key variables: i
Iterator variables: i
Python program:
def findExtraCharacter ( s1 , s2 ) :
    smallStr = " "
    largeStr = " "
    if ( len ( s1 ) > len ( s2 ) ) :
        smallStr = s2
        largeStr = s1
    else :
        smallStr = s1
        largeStr = s2
    smallStrCodeTotal = 0
    largeStrCodeTotal = 0
    i = 0
    while ( i < len ( smallStr ) ) :
        smallStrCodeTotal += ord ( smallStr [ i ] )
        largeStrCodeTotal += ord ( largeStr [ i ] )
        i += 1
    largeStrCodeTotal += ord ( largeStr [ i ] )
    intChar = largeStrCodeTotal - smallStrCodeTotal
    return chr ( intChar )
s1 = " abcd "
s2 = " cbdae "
extraChar = findExtraCharacter ( s1 , s2 )
print ( " Extra ▁ Character : " , extraChar )

Index/key variables: i
Accumulator variables: largeStrCodeTotal, smallStrCodeTotal
Python program:
def calculateSum ( arr , n ) :
    if ( n == 0 ) :
        return 0
    s = arr [ 0 ]
    value = int ( s )
    sum = value
    for i in range ( 2 , n , 2 ) :
        s = arr [ i ]
        value = int ( s )
        operation = arr [ i - 1 ] [ 0 ]
        if ( operation == ' + ' ) :
            sum += value
        else :
            sum -= value
    return sum
arr = [ "3" , " + " , "4" , " - " , "7" , " + " , "13" ]
n = len ( arr )
print ( calculateSum ( arr , n ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def LargestString ( na ) :
    N = len ( na )
    c = [ 0 ] * N
    m = 0
    for j in range ( N ) :
        character = [ False ] * 26
        for k in range ( len ( na [ j ] ) ) :
            x = ord ( na [ j ] [ k ] ) - ord ( ' A ' )
            if ( ( na [ j ] [ k ] != ' ▁ ' ) and ( character [ x ] == False ) ) :
                c [ j ] += 1
                character [ x ] = True
            if ( c [ j ] > c [ m ] ) :
                m = j
    print ( na [ m ] )
na = [ " BOB " , " A ▁ AB ▁ C ▁ JOHNSON " , " ANJALI " , " ASKRIT " , " ARMAN ▁ MALLIK " ]
LargestString ( na )

Index/key variables: j, k, m, x
Iterator variables: j, k
Python program:
def longestWordLength ( string ) :
    length = 0
    for word in string . split ( ) :
        if ( len ( word ) > length ) :
            length = len ( word )
    return length
string = " I ▁ am ▁ an ▁ intern ▁ at ▁ geeksforgeeks "
print ( longestWordLength ( string ) )

Iterator variables: word
Python program:
def morseEncode ( x ) :
    if x is ' a ' :
        return " . - "
    elif x is ' b ' :
        return " - . . . "
    elif x is ' c ' :
        return " - . - . "
    elif x is ' d ' :
        return " - . . "
    elif x is ' e ' :
        return " . "
    elif x is ' f ' :
        return " . . - . "
    elif x is ' g ' :
        return " - - . "
    elif x is ' h ' :
        return " . . . . "
    elif x is ' i ' :
        return " . . "
    elif x is ' j ' :
        return " . - - - "
    elif x is ' k ' :
        return " - . - "
    elif x is ' l ' :
        return " . - . . "
    elif x is ' m ' :
        return " - - "
    elif x is ' n ' :
        return " - . "
    elif x is ' o ' :
        return " - - - "
    elif x is ' p ' :
        return " . - - . "
    elif x is ' q ' :
        return " - - . - "
    elif x is ' r ' :
        return " . - . "
    elif x is ' s ' :
        return " . . . "
    elif x is ' t ' :
        return " - "
    elif x is ' u ' :
        return " . . - "
    elif x is ' v ' :
        return " . . . - "
    elif x is ' w ' :
        return " . - - "
    elif x is ' x ' :
        return " - . . - "
    elif x is ' y ' :
        return " - . - - "
    elif x is ' z ' :
        return " - - . . "
    elif x is '1' :
        return " . - - - - " ;
    elif x is '2' :
        return " . . - - - " ;
    elif x is '3' :
        return " . . . - - " ;
    elif x is '4' :
        return " . . . . - " ;
    elif x is '5' :
        return " . . . . . " ;
    elif x is '6' :
        return " - . . . . " ;
    elif x is '7' :
        return " - - . . . " ;
    elif x is '8' :
        return " - - - . . " ;
    elif x is '9' :
        return " - - - - . " ;
    elif x is '0' :
        return " - - - - - " ;
def morseCode ( s ) :
    for character in s :
        print ( morseEncode ( character ) , end = " " )
if __name__ == " _ _ main _ _ " :
    s = " geeksforgeeks "
    morseCode ( s )

Iterator variables: character
Python program:
def minRemoval ( strr ) :
    hash = [ 0 ] * 26
    for char in strr :
        hash [ ord ( char ) - ord ( ' a ' ) ] = hash [ ord ( char ) - ord ( ' a ' ) ] + 1
    count = 0
    for i in range ( 26 ) :
        if hash [ i ] % 2 :
            count = count + 1
    return 0 if count == 0 else count - 1
if __name__ == " _ _ main _ _ " :
    strr = " geeksforgeeks " ;

Index/key variables: i
Iterator variables: char, i
Python program:
MAX_LEN , MAX_CHAR = 1005 , 26
cnt = [ [ 0 for i in range ( MAX_CHAR ) ] for j in range ( MAX_LEN ) ]
def preProcess ( s ) :
    n = len ( s )
    for i in range ( 0 , n ) :
        cnt [ i ] [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1
    for i in range ( 1 , n ) :
        for j in range ( 0 , 26 ) :
            cnt [ i ] [ j ] += cnt [ i - 1 ] [ j ]
def findCharFreq ( l , r , c ) :
    return ( cnt [ r ] [ ord ( c ) - 97 ] - cnt [ l - 1 ] [ ord ( c ) - 97 ] )
if __name__ == " _ _ main _ _ " :
    s = " geeksforgeeks "
    Q = 4
    preProcess ( s )
    print ( findCharFreq ( 0 , 5 , ' e ' ) )
    print ( findCharFreq ( 2 , 6 , ' f ' ) )
    print ( findCharFreq ( 4 , 7 , ' m ' ) )
    print ( findCharFreq ( 0 , 12 , ' e ' ) )

Index/key variables: i, j, r
Iterator variables: i, j
Python program:
def DFS ( graph , src , prev_len , max_len , visited ) :
    visited [ src ] = 1
    curr_len = 0
    adjacent = None
    for i in range ( len ( graph [ src ] ) ) :
        adjacent = graph [ src ] [ i ]
        if ( not visited [ adjacent [ 0 ] ] ) :
            curr_len = prev_len + adjacent [ 1 ]
            DFS ( graph , adjacent [ 0 ] , curr_len , max_len , visited )
        if ( max_len [ 0 ] < curr_len ) :
            max_len [ 0 ] = curr_len
        curr_len = 0
def longestCable ( graph , n ) :
    max_len = [ - 999999999999 ]
    for i in range ( 1 , n + 1 ) :
        visited = [ False ] * ( n + 1 )
        DFS ( graph , i , 0 , max_len , visited )
    return max_len [ 0 ]
if __name__ == ' _ _ main _ _ ' :
    n = 6
    graph = [ [ ] for i in range ( n + 1 ) ]
    graph [ 1 ] . append ( [ 2 , 3 ] )
    graph [ 2 ] . append ( [ 1 , 3 ] )
    graph [ 2 ] . append ( [ 3 , 4 ] )
    graph [ 3 ] . append ( [ 2 , 4 ] )
    graph [ 2 ] . append ( [ 6 , 2 ] )
    graph [ 6 ] . append ( [ 2 , 2 ] )
    graph [ 4 ] . append ( [ 6 , 6 ] )
    graph [ 6 ] . append ( [ 4 , 6 ] )
    graph [ 5 ] . append ( [ 6 , 5 ] )
    graph [ 6 ] . append ( [ 5 , 5 ] )
    print ( " Maximum ▁ length ▁ of ▁ cable ▁ = " , longestCable ( graph , n ) )

Index/key variables: i, src
Iterator variables: i
Python program:
from collections import deque
class Node :
    def __init__ ( self , x ) :
        self . data = x
        self . left = None
        self . right = None
def modifiedLevelOrder ( node ) :
    if ( node == None ) :
        return
    if ( node . left == None and node . right == None ) :
        print ( node . data , end = " ▁ " )
        return
    myQueue = deque ( )
    myStack = [ ]
    temp = None
    sz = 0
    ct = 0
    rightToLeft = False
    myQueue . append ( node )
    while ( len ( myQueue ) > 0 ) :
        ct += 1
        sz = len ( myQueue )
        for i in range ( sz ) :
            temp = myQueue . popleft ( )
            if ( rightToLeft == False ) :
                print ( temp . data , end = " ▁ " )
            else :
                myStack . append ( temp )
            if ( temp . left ) :
                myQueue . append ( temp . left )
            if ( temp . right ) :
                myQueue . append ( temp . right )
        if ( rightToLeft == True ) :
            while ( len ( myStack ) > 0 ) :
                temp = myStack [ - 1 ]
                del myStack [ - 1 ]
                print ( temp . data , end = " ▁ " )
        if ( ct == 2 ) :
            rightToLeft = not rightToLeft
            ct = 0
        print ( )
if __name__ == ' _ _ main _ _ ' :
    root = Node ( 1 )
    root . left = Node ( 2 )
    root . right = Node ( 3 )
    root . left . left = Node ( 4 )
    root . left . right = Node ( 5 )
    root . right . left = Node ( 6 )
    root . right . right = Node ( 7 )
    root . left . left . left = Node ( 8 )
    root . left . left . right = Node ( 9 )
    root . left . right . left = Node ( 3 )
    root . left . right . right = Node ( 1 )
    root . right . left . left = Node ( 4 )
    root . right . left . right = Node ( 2 )
    root . right . right . left = Node ( 7 )
    root . right . right . right = Node ( 2 )
    root . left . right . left . left = Node ( 16 )
    root . left . right . left . right = Node ( 17 )
    root . right . left . right . left = Node ( 18 )
    root . right . right . left . right = Node ( 19 )
    modifiedLevelOrder ( root )

Accumulator variables: ct, myQueue, myStack
Iterator variables: i
Boolean variables: rightToLeft
Class/struct names: Node
Python program:
def minnode ( n , keyval , mstset ) :
    mini = 999999999999
    mini_index = None
    for i in range ( n ) :
        if ( mstset [ i ] == False and keyval [ i ] < mini ) :
            mini = keyval [ i ]
            mini_index = i
    return mini_index
def findcost ( n , city ) :
    parent = [ None ] * n
    keyval = [ None ] * n
    mstset = [ None ] * n
    for i in range ( n ) :
        keyval [ i ] = 9999999999999
        mstset [ i ] = False
    parent [ 0 ] = - 1
    keyval [ 0 ] = 0
    for i in range ( n - 1 ) :
        u = minnode ( n , keyval , mstset )
        mstset [ u ] = True
        for v in range ( n ) :
            if ( city [ u ] [ v ] and mstset [ v ] == False and city [ u ] [ v ] < keyval [ v ] ) :
                keyval [ v ] = city [ u ] [ v ]
                parent [ v ] = u
    cost = 0
    for i in range ( 1 , n ) :
        cost += city [ parent [ i ] ] [ i ]
    print ( cost )
if __name__ == ' _ _ main _ _ ' :
    n1 = 5
    city1 = [ [ 0 , 1 , 2 , 3 , 4 ] , [ 1 , 0 , 5 , 0 , 7 ] , [ 2 , 5 , 0 , 6 , 0 ] , [ 3 , 0 , 6 , 0 , 0 ] , [ 4 , 7 , 0 , 0 , 0 ] ]
    findcost ( n1 , city1 )
    n2 = 6
    city2 = [ [ 0 , 1 , 1 , 100 , 0 , 0 ] , [ 1 , 0 , 1 , 0 , 0 , 0 ] , [ 1 , 1 , 0 , 0 , 0 , 0 ] , [ 100 , 0 , 0 , 0 , 2 , 2 ] , [ 0 , 0 , 0 , 2 , 0 , 2 ] , [ 0 , 0 , 0 , 2 , 2 , 0 ] ]
    findcost ( n2 , city2 )

Index/key variables: i, u, v
Accumulator variables: cost
Iterator variables: i, v
Python program:
import math
V = 5
def minKey ( key , mstSet ) :
    min = 10000000
    min_index = 0
    for v in range ( V ) :
        if ( mstSet [ v ] == False and key [ v ] < min ) :
            min = key [ v ]
            min_index = v
    return min_index
def printMST ( parent , n , graph ) :
    print ( " Edge ▁ Weight " )
    minProduct = 1
    for i in range ( 1 , V ) :
        print ( " { } ▁ - ▁ { } ▁ { } ▁ " . format ( parent [ i ] , i , graph [ i ] [ parent [ i ] ] ) )
        minProduct *= graph [ i ] [ parent [ i ] ]
    print ( " Minimum ▁ Obtainable ▁ product ▁ is ▁ { } " . format ( minProduct ) )
def primMST ( inputGraph , logGraph ) :
    parent = [ 0 for i in range ( V ) ]
    key = [ 10000000 for i in range ( V ) ]
    mstSet = [ False for i in range ( V ) ]
    key [ 0 ] = 0
    parent [ 0 ] = - 1
    for count in range ( 0 , V - 1 ) :
        u = minKey ( key , mstSet )
        mstSet [ u ] = True
        for v in range ( V ) :
            if ( logGraph [ u ] [ v ] > 0 and mstSet [ v ] == False and logGraph [ u ] [ v ] < key [ v ] ) :
                parent [ v ] = u
                key [ v ] = logGraph [ u ] [ v ]
    printMST ( parent , V , inputGraph )
def minimumProductMST ( graph ) :
    logGraph = [ [ 0 for j in range ( V ) ] for i in range ( V ) ]
    for i in range ( V ) :
        for j in range ( V ) :
            if ( graph [ i ] [ j ] > 0 ) :
                logGraph [ i ] [ j ] = math . log ( graph [ i ] [ j ] )
            else :
                logGraph [ i ] [ j ] = 0
    primMST ( graph , logGraph )
if __name__ == ' _ _ main _ _ ' :
    graph = [ [ 0 , 2 , 0 , 6 , 0 ] , [ 2 , 0 , 3 , 8 , 5 ] , [ 0 , 3 , 0 , 0 , 7 ] , [ 6 , 8 , 0 , 0 , 9 ] , [ 0 , 5 , 7 , 9 , 0 ] , ]
    minimumProductMST ( graph )

Index/key variables: i, j, u, v
Accumulator variables: minProduct
Iterator variables: count, i, j, v
Python program:
class newNode ( ) :
    def __init__ ( self , data ) :
        self . key = data
        self . left = None
        self . right = None
def inorder ( temp ) :
    if ( not temp ) :
        return
    inorder ( temp . left )
    print ( temp . key , end = " ▁ " )
    inorder ( temp . right )
def insert ( temp , key ) :
    if not temp :
        root = newNode ( key )
        return
    q = [ ]
    q . append ( temp )
    while ( len ( q ) ) :
        temp = q [ 0 ]
        q . pop ( 0 )
        if ( not temp . left ) :
            temp . left = newNode ( key )
            break
        else :
            q . append ( temp . left )
        if ( not temp . right ) :
            temp . right = newNode ( key )
            break
        else :
            q . append ( temp . right )
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 10 )
    root . left = newNode ( 11 )
    root . left . left = newNode ( 7 )
    root . right = newNode ( 9 )
    root . right . left = newNode ( 15 )
    root . right . right = newNode ( 8 )
    print ( " Inorder ▁ traversal ▁ before ▁ insertion : " , end = " ▁ " )
    inorder ( root )
    key = 12
    insert ( root , key )
    print ( )
    print ( " Inorder ▁ traversal ▁ after ▁ insertion : " , end = " ▁ " )
    inorder ( root )

Accumulator variables: q
Class/struct names: newNode
Python program:
def TOWUtil ( arr , n , curr_elements , no_of_selected_elements , soln , min_diff , Sum , curr_sum , curr_position ) :
    if ( curr_position == n ) :
        return
    if ( ( int ( n / 2 ) - no_of_selected_elements ) > ( n - curr_position ) ) :
        return
    TOWUtil ( arr , n , curr_elements , no_of_selected_elements , soln , min_diff , Sum , curr_sum , curr_position + 1 )
    no_of_selected_elements += 1
    curr_sum = curr_sum + arr [ curr_position ]
    curr_elements [ curr_position ] = True
    if ( no_of_selected_elements == int ( n / 2 ) ) :
        if ( abs ( int ( Sum / 2 ) - curr_sum ) < min_diff [ 0 ] ) :
            min_diff [ 0 ] = abs ( int ( Sum / 2 ) - curr_sum )
            for i in range ( n ) :
                soln [ i ] = curr_elements [ i ]
    else :
        TOWUtil ( arr , n , curr_elements , no_of_selected_elements , soln , min_diff , Sum , curr_sum , curr_position + 1 )
    curr_elements [ curr_position ] = False
def tugOfWar ( arr , n ) :
    curr_elements = [ None ] * n
    soln = [ None ] * n
    min_diff = [ 999999999999 ]
    Sum = 0
    for i in range ( n ) :
        Sum += arr [ i ]
        curr_elements [ i ] = soln [ i ] = False
    TOWUtil ( arr , n , curr_elements , 0 , soln , min_diff , Sum , 0 , 0 )
    print ( " The ▁ first ▁ subset ▁ is : ▁ " )
    for i in range ( n ) :
        if ( soln [ i ] == True ) :
            print ( arr [ i ] , end = " ▁ " )
    print ( )
    print ( " The ▁ second ▁ subset ▁ is : ▁ " )
    for i in range ( n ) :
        if ( soln [ i ] == False ) :
            print ( arr [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 23 , 45 , - 34 , 12 , 0 , 98 , - 99 , 4 , 189 , - 1 , 4 ]
    n = len ( arr )
    tugOfWar ( arr , n )

Index/key variables: curr_position, i
Accumulator variables: Sum
Iterator variables: i
Python program:
n = 8
def isSafe ( x , y , board ) :
    if ( x >= 0 and y >= 0 and x < n and y < n and board [ x ] [ y ] == - 1 ) :
        return True
    return False
def printSolution ( n , board ) :
    for i in range ( n ) :
        for j in range ( n ) :
            print ( board [ i ] [ j ] , end = ' ▁ ' )
        print ( )
def solveKT ( n ) :
    board = [ [ - 1 for i in range ( n ) ] for i in range ( n ) ]
    move_x = [ 2 , 1 , - 1 , - 2 , - 2 , - 1 , 1 , 2 ]
    move_y = [ 1 , 2 , 2 , 1 , - 1 , - 2 , - 2 , - 1 ]
    board [ 0 ] [ 0 ] = 0
    pos = 1
    if ( not solveKTUtil ( n , board , 0 , 0 , move_x , move_y , pos ) ) :
        print ( " Solution ▁ does ▁ not ▁ exist " )
    else :
        printSolution ( n , board )
def solveKTUtil ( n , board , curr_x , curr_y , move_x , move_y , pos ) :
    if ( pos == n ** 2 ) :
        return True
    for i in range ( 8 ) :
        new_x = curr_x + move_x [ i ]
        new_y = curr_y + move_y [ i ]
        if ( isSafe ( new_x , new_y , board ) ) :
            board [ new_x ] [ new_y ] = pos
            if ( solveKTUtil ( n , board , new_x , new_y , move_x , move_y , pos + 1 ) ) :
                return True
            board [ new_x ] [ new_y ] = - 1
    return False
if __name__ == " _ _ main _ _ " :
    solveKT ( n )

Index/key variables: i, j, new_x, new_y, x, y
Iterator variables: i, j
Python program:
N = 4
def printSolution ( sol ) :
    for i in sol :
        for j in i :
            print ( str ( j ) + " ▁ " , end = " " )
        print ( " " )
def isSafe ( maze , x , y ) :
    if x >= 0 and x < N and y >= 0 and y < N and maze [ x ] [ y ] == 1 :
        return True
    return False
def solveMaze ( maze ) :
    sol = [ [ 0 for j in range ( 4 ) ] for i in range ( 4 ) ]
    if solveMazeUtil ( maze , 0 , 0 , sol ) == False :
        print ( " Solution ▁ doesn ' t ▁ exist " ) ;
        return False
    printSolution ( sol )
    return True
def solveMazeUtil ( maze , x , y , sol ) :
    if x == N - 1 and y == N - 1 and maze [ x ] [ y ] == 1 :
        sol [ x ] [ y ] = 1
        return True
    if isSafe ( maze , x , y ) == True :
        if sol [ x ] [ y ] == 1 :
            return False
        sol [ x ] [ y ] = 1
        if solveMazeUtil ( maze , x + 1 , y , sol ) == True :
            return True
        if solveMazeUtil ( maze , x , y + 1 , sol ) == True :
            return True
        if solveMazeUtil ( maze , x - 1 , y , sol ) == True :
            return True
        if solveMazeUtil ( maze , x , y - 1 , sol ) == True :
            return True
        sol [ x ] [ y ] = 0
        return False
if __name__ == " _ _ main _ _ " :
    maze = [ [ 1 , 0 , 0 , 0 ] , [ 1 , 1 , 0 , 1 ] , [ 0 , 1 , 0 , 0 ] , [ 1 , 1 , 1 , 1 ] ]
    solveMaze ( maze )

Index/key variables: x, y
Iterator variables: i, j
Python program:
def printSolution ( color ) :
    print ( " Solution ▁ Exists : " " ▁ Following ▁ are ▁ the ▁ assigned ▁ colors ▁ " )
    for i in range ( 4 ) :
        print ( color [ i ] , end = " ▁ " )
def isSafe ( graph , color ) :
    for i in range ( 4 ) :
        for j in range ( i + 1 , 4 ) :
            if ( graph [ i ] [ j ] and color [ j ] == color [ i ] ) :
                return False
    return True
def graphColoring ( graph , m , i , color ) :
    if ( i == 4 ) :
        if ( isSafe ( graph , color ) ) :
            printSolution ( color )
            return True
        return False
    for j in range ( 1 , m + 1 ) :
        color [ i ] = j
        if ( graphColoring ( graph , m , i + 1 , color ) ) :
            return True
        color [ i ] = 0
    return False
if __name__ == ' _ _ main _ _ ' :
    graph = [ [ 0 , 1 , 1 , 1 ] , [ 1 , 0 , 1 , 0 ] , [ 1 , 1 , 0 , 1 ] , [ 1 , 0 , 1 , 0 ] , ]
    m = 3
    color = [ 0 for i in range ( 4 ) ]
    if ( not graphColoring ( graph , m , 0 , color ) ) :
        print ( " Solution ▁ does ▁ not ▁ exist " )

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