dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
class Node :
    def __init__ ( self , x ) :
        self . data = x
        self . next = None
def printList ( node ) :
    while ( node != None ) :
        print ( node . data , end = " ▁ " )
        node = node . next
def mergeKLists ( arr , last ) :
    for i in range ( 1 , last + 1 ) :
        while ( True ) :
            head_0 = arr [ 0 ]
            head_i = arr [ i ]
            if ( head_i == None ) :
                break
            if ( head_0 . data >= head_i . data ) :
                arr [ i ] = head_i . next
                head_i . next = head_0
                arr [ 0 ] = head_i
            else :
                while ( head_0 . next != None ) :
                    if ( head_0 . next . data >= head_i . data ) :
                        arr [ i ] = head_i . next
                        head_i . next = head_0 . next
                        head_0 . next = head_i
                        break
                    head_0 = head_0 . next
                    if ( head_0 . next == None ) :
                        arr [ i ] = head_i . next
                        head_i . next = None
                        head_0 . next = head_i
                        head_0 . next . next = None
                        break
    return arr [ 0 ]
if __name__ == ' _ _ main _ _ ' :
    k = 3
    n = 4
    arr = [ None for i in range ( k ) ]
    arr [ 0 ] = Node ( 1 )
    arr [ 0 ] . next = Node ( 3 )
    arr [ 0 ] . next . next = Node ( 5 )
    arr [ 0 ] . next . next . next = Node ( 7 )
    arr [ 1 ] = Node ( 2 )
    arr [ 1 ] . next = Node ( 4 )
    arr [ 1 ] . next . next = Node ( 6 )
    arr [ 1 ] . next . next . next = Node ( 8 )
    arr [ 2 ] = Node ( 0 )
    arr [ 2 ] . next = Node ( 9 )
    arr [ 2 ] . next . next = Node ( 10 )
    arr [ 2 ] . next . next . next = Node ( 11 )
    head = mergeKLists ( arr , k - 1 )
    printList ( head )

Index/key variables: i
Iterator variables: i
Class/struct names: Node
Python program:
import math
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . next = None
def newNode ( key ) :
    temp = Node ( key )
    temp . data = key
    temp . next = None
    return temp
def printList ( node ) :
    while ( node != None ) :
        print ( node . data , end = " ▁ " )
        node = node . next
def merge ( h1 , h2 ) :
    if ( h1 == None ) :
        return h2
    if ( h2 == None ) :
        return h1
    if ( h1 . data < h2 . data ) :
        h1 . next = merge ( h1 . next , h2 )
        return h1
    else :
        h2 . next = merge ( h1 , h2 . next )
        return h2
if __name__ == ' _ _ main _ _ ' :
    head1 = newNode ( 1 )
    head1 . next = newNode ( 3 )
    head1 . next . next = newNode ( 5 )
    head2 = newNode ( 0 )
    head2 . next = newNode ( 2 )
    head2 . next . next = newNode ( 4 )
    mergedhead = merge ( head1 , head2 )
    printList ( mergedhead )

Class/struct names: Node
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . next = None
def newNode ( key ) :
    temp = Node ( 0 )
    temp . data = key
    temp . next = None
    return temp
def printList ( node ) :
    while ( node != None ) :
        print ( node . data , end = " ▁ " )
        node = node . next
def mergeUtil ( h1 , h2 ) :
    if ( h1 . next == None ) :
        h1 . next = h2
        return h1
    curr1 = h1
    next1 = h1 . next
    curr2 = h2
    next2 = h2 . next
    while ( next1 != None and curr2 != None ) :
        if ( ( curr2 . data ) >= ( curr1 . data ) and ( curr2 . data ) <= ( next1 . data ) ) :
            next2 = curr2 . next
            curr1 . next = curr2
            curr2 . next = next1
            curr1 = curr2
            curr2 = next2
        else :
            if ( next1 . next ) :
                next1 = next1 . next
                curr1 = curr1 . next
            else :
                next1 . next = curr2
                return h1
    return h1
def merge ( h1 , h2 ) :
    if ( h1 == None ) :
        return h2
    if ( h2 == None ) :
        return h1
    if ( h1 . data < h2 . data ) :
        return mergeUtil ( h1 , h2 )
    else :
        return mergeUtil ( h2 , h1 )
head1 = newNode ( 1 )
head1 . next = newNode ( 3 )
head1 . next . next = newNode ( 5 )
head2 = newNode ( 0 )
head2 . next = newNode ( 2 )
head2 . next . next = newNode ( 4 )
mergedhead = merge ( head1 , head2 )
printList ( mergedhead )

Class/struct names: Node
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . next = None
def swapNodes ( head_ref , currX , currY , prevY ) :
    head_ref = currY
    prevY . next = currX
    temp = currY . next
    currY . next = currX . next
    currX . next = temp
    return head_ref
def recurSelectionSort ( head ) :
    if ( head . next == None ) :
        return head
    min = head
    beforeMin = None
    ptr = head
    while ( ptr . next != None ) :
        if ( ptr . next . data < min . data ) :
            min = ptr . next
            beforeMin = ptr
        ptr = ptr . next
    if ( min != head ) :
        head = swapNodes ( head , head , min , beforeMin )
    head . next = recurSelectionSort ( head . next )
    return head
def sort ( head_ref ) :
    if ( ( head_ref ) == None ) :
        return None
    head_ref = recurSelectionSort ( head_ref )
    return head_ref
def push ( head_ref , new_data ) :
    new_node = Node ( 0 )
    new_node . data = new_data
    new_node . next = ( head_ref )
    ( head_ref ) = new_node
    return head_ref
def printList ( head ) :
    while ( head != None ) :
        print ( head . data , end = " ▁ " )
        head = head . next
head = None
head = push ( head , 6 )
head = push ( head , 4 )
head = push ( head , 8 )
head = push ( head , 12 )
head = push ( head , 10 )
print ( " Linked ▁ list ▁ before ▁ sorting : " )
printList ( head )
head = sort ( head )
print (   " Linked list after sorting : " )
printList ( head )

Class/struct names: Node
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . next = None
def getNode ( data ) :
    newNode = Node ( 0 )
    newNode . data = data
    newNode . next = None
    return newNode
def insertAfterNthNode ( head , n , x ) :
    if ( head == None ) :
        return
    newNode = getNode ( x )
    ptr = head
    len = 0
    i = 0
    while ( ptr != None ) :
        len = len + 1
        ptr = ptr . next
    ptr = head
    i = 1
    while ( i <= ( len - n ) ) :
        ptr = ptr . next
        i = i + 1
    newNode . next = ptr . next
    ptr . next = newNode
def printList ( head ) :
    while ( head != None ) :
        print ( head . data , end = " ▁ " )
        head = head . next
head = getNode ( 1 )
head . next = getNode ( 3 )
head . next . next = getNode ( 4 )
head . next . next . next = getNode ( 5 )
n = 4
x = 2
print ( " Original ▁ Linked ▁ List : ▁ " )
printList ( head )
insertAfterNthNode ( head , n , x )
print ( )
print ( " Linked ▁ List ▁ After ▁ Insertion : ▁ " )
printList ( head )

Class/struct names: Node
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . next = None
def getNode ( data ) :
    newNode = Node ( data )
    return newNode
def insertAfterNthNode ( head , n , x ) :
    if ( head == None ) :
        return
    newNode = getNode ( x )
    slow_ptr = head
    fast_ptr = head
    for i in range ( 1 , n ) :
        fast_ptr = fast_ptr . next
    while ( fast_ptr . next != None ) :
        slow_ptr = slow_ptr . next
        fast_ptr = fast_ptr . next
    newNode . next = slow_ptr . next
    slow_ptr . next = newNode
def printList ( head ) :
    while ( head != None ) :
        print ( head . data , end = ' ▁ ' )
        head = head . next
if __name__ == ' _ _ main _ _ ' :
    head = getNode ( 1 )
    head . next = getNode ( 3 )
    head . next . next = getNode ( 4 )
    head . next . next . next = getNode ( 5 )
    n = 4
    x = 2
    print ( " Original ▁ Linked ▁ List : ▁ " , end = ' ' )
    printList ( head )
    insertAfterNthNode ( head , n , x )
    print ( " Linked List After Insertion :   " , end = ' ' )
    printList ( head )

Iterator variables: i
Class/struct names: Node
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . next = None
def setMiddleHead ( head ) :
    if ( head == None ) :
        return None
    one_node = head
    two_node = head
    prev = None
    while ( two_node != None and two_node . next != None ) :
        prev = one_node
        one_node = one_node . next
        two_node = two_node . next . next
    prev . next = prev . next . next
    one_node . next = head
    head = one_node
    return head
def push ( head , new_data ) :
    new_node = Node ( new_data )
    new_node . next = head
    head = new_node
    return head
def printList ( head ) :
    temp = head
    while ( temp != None ) :
        print ( str ( temp . data ) , end = " ▁ " )
        temp = temp . next
    print ( " " )
head = None
for i in range ( 5 , 0 , - 1 ) :
    head = push ( head , i )
print ( " ▁ list ▁ before : ▁ " , end = " " )
printList ( head )
head = setMiddleHead ( head )
print ( " ▁ list ▁ After : ▁ " , end = " " )
printList ( head )

Iterator variables: i
Class/struct names: Node
Python program:
import math
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . next = None
        self . prev = None
def insert ( head_ref , data ) :
    new_node = Node ( data )
    new_node . data = data
    if ( head_ref == None ) :
        new_node . next = new_node
        new_node . prev = new_node
    else :
        last = head_ref . prev
        new_node . next = head_ref
        new_node . prev = last
        last . next = new_node
        head_ref . prev = new_node
    head_ref = new_node
    return head_ref
def merge ( first , second ) :
    if ( first == None ) :
        return second
    if ( second == None ) :
        return first
    if ( first . data < second . data ) :
        first . next = merge ( first . next , second )
        first . next . prev = first
        first . prev = None
        return first
    else :
        second . next = merge ( first , second . next )
        second . next . prev = second
        second . prev = None
        return second
def mergeUtil ( head1 , head2 ) :
    if ( head1 == None ) :
        return head2
    if ( head2 == None ) :
        return head1
    if ( head1 . prev . data < head2 . prev . data ) :
        last_node = head2 . prev
    else :
        last_node = head1 . prev
    head1 . prev . next = None
    head2 . prev . next = None
    finalHead = merge ( head1 , head2 )
    finalHead . prev = last_node
    last_node . next = finalHead
    return finalHead
def printList ( head ) :
    temp = head
    while ( temp . next != head ) :
        print ( temp . data , end = " ▁ " )
        temp = temp . next
    print ( temp . data , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    head1 = None
    head2 = None
    head1 = insert ( head1 , 8 )
    head1 = insert ( head1 , 5 )
    head1 = insert ( head1 , 3 )
    head1 = insert ( head1 , 1 )
    head2 = insert ( head2 , 11 )
    head2 = insert ( head2 , 9 )
    head2 = insert ( head2 , 7 )
    head2 = insert ( head2 , 2 )
    newHead = mergeUtil ( head1 , head2 )
    print ( " Final ▁ Sorted ▁ List : ▁ " , end = " " )
    printList ( newHead )

Class/struct names: Node
Python program:
import math
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . next = None
def newNode ( val ) :
    temp = Node ( val )
    temp . data = val
    temp . prev = None
    temp . next = None
    return temp
def printList ( head ) :
    while ( head . next != None ) :
        print ( head . data , end = " < - - > " )
        head = head . next
    print ( head . data )
def insert ( head , val ) :
    temp = newNode ( val )
    temp . next = head
    ( head ) . prev = temp
    ( head ) = temp
    return head
def reverseList ( head ) :
    left = head
    right = head
    while ( right . next != None ) :
        right = right . next
    while ( left != right and left . prev != right ) :
        t = left . data
        left . data = right . data
        right . data = t
        left = left . next
        right = right . prev
    return head
if __name__ == ' _ _ main _ _ ' :
    head = newNode ( 5 )
    head = insert ( head , 4 )
    head = insert ( head , 3 )
    head = insert ( head , 2 )
    head = insert ( head , 1 )
    printList ( head )
    print ( " List ▁ After ▁ Reversing " )
    head = reverseList ( head )
    printList ( head )

Class/struct names: Node
Python program:
class Node :
    def __init__ ( self , data , next , prev ) :
        self . data = data
        self . next = next
        self . prev = prev
def push ( head_ref , new_data ) :
    new_node = Node ( new_data , head_ref , None )
    if head_ref != None :
        head_ref . prev = new_node
        head_ref = new_node
    return head_ref
def isPalindrome ( left ) :
    if left == None :
        return True
    right = left
    while right . next != None :
        right = right . next
    while left != right :
        if left . data != right . data :
            return False
        left = left . next
        right = right . prev
    return True
if __name__ == " _ _ main _ _ " :
    head = None
    head = push ( head , ' l ' )
    head = push ( head , ' e ' )
    head = push ( head , ' v ' )
    head = push ( head , ' e ' )
    head = push ( head , ' l ' )
    if isPalindrome ( head ) :
        print ( " It ▁ is ▁ Palindrome " )
    else :
        print ( " Not ▁ Palindrome " )

Class/struct names: Node
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
def printKDistant ( root , klevel ) :
    q = [ ]
    level = 1
    flag = False
    q . append ( root )
    q . append ( None )
    while ( len ( q ) ) :
        temp = q [ 0 ]
        if ( level == klevel and temp != None ) :
            flag = True
            print ( temp . data , end = " ▁ " )
        q . pop ( 0 )
        if ( temp == None ) :
            if ( len ( q ) ) :
                q . append ( None )
            level += 1
            if ( level > klevel ) :
                break
        else :
            if ( temp . left ) :
                q . append ( temp . left )
            if ( temp . right ) :
                q . append ( temp . right )
    print ( )
    return flag
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 20 )
    root . left = newNode ( 10 )
    root . right = newNode ( 30 )
    root . left . left = newNode ( 5 )
    root . left . right = newNode ( 15 )
    root . left . right . left = newNode ( 12 )
    root . right . left = newNode ( 25 )
    root . right . right = newNode ( 40 )
    print ( " data ▁ at ▁ level ▁ 1 ▁ : ▁ " , end = " " )
    ret = printKDistant ( root , 1 )
    if ( ret == False ) :
        print ( " Number ▁ exceeds ▁ total " , " number ▁ of ▁ levels " )
    print ( " data ▁ at ▁ level ▁ 2 ▁ : ▁ " , end = " " )
    ret = printKDistant ( root , 2 )
    if ( ret == False ) :
        print ( " Number ▁ exceeds ▁ total " , " number ▁ of ▁ levels " )
    print ( " data ▁ at ▁ level ▁ 3 ▁ : ▁ " , end = " " )
    ret = printKDistant ( root , 3 )
    if ( ret == False ) :
        print ( " Number ▁ exceeds ▁ total " , " number ▁ of ▁ levels " )
    print ( " data ▁ at ▁ level ▁ 6 ▁ : ▁ " , end = " " )
    ret = printKDistant ( root , 6 )
    if ( ret == False ) :
        print ( " Number ▁ exceeds ▁ total ▁ number ▁ of ▁ levels " )

Accumulator variables: level, q
Boolean variables: flag
Class/struct names: newNode
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def printLeafNodes ( root : Node ) -> None :
    if ( not root ) :
        return
    if ( not root . left and not root . right ) :
        print ( root . data , end = " ▁ " )
        return
    if root . left :
        printLeafNodes ( root . left )
    if root . right :
        printLeafNodes ( root . right )
if __name__ == " _ _ main _ _ " :
    root = Node ( 1 )
    root . left = Node ( 2 )
    root . right = Node ( 3 )
    root . left . left = Node ( 4 )
    root . right . left = Node ( 5 )
    root . right . right = Node ( 8 )
    root . right . left . left = Node ( 6 )
    root . right . left . right = Node ( 7 )
    root . right . right . left = Node ( 9 )
    root . right . right . right = Node ( 10 )
    printLeafNodes ( root )

Class/struct names: Node
Python program:
class newNode :
    def __init__ ( self , key ) :
        self . key = key
        self . left = self . right = None
def kDistantFromLeafUtil ( node , path , visited , pathLen , k ) :
    if ( node == None ) :
        return
    path [ pathLen ] = node . key
    visited [ pathLen ] = False
    pathLen += 1
    if ( node . left == None and node . right == None and pathLen - k - 1 >= 0 and visited [ pathLen - k - 1 ] == False ) :
        print ( path [ pathLen - k - 1 ] , end = " ▁ " )
        visited [ pathLen - k - 1 ] = True
        return
    kDistantFromLeafUtil ( node . left , path , visited , pathLen , k )
    kDistantFromLeafUtil ( node . right , path , visited , pathLen , k )
def printKDistantfromLeaf ( node , k ) :
    global MAX_HEIGHT
    path = [ None ] * MAX_HEIGHT
    visited = [ False ] * MAX_HEIGHT
    kDistantFromLeafUtil ( node , path , visited , 0 , k )
MAX_HEIGHT = 10000
root = newNode ( 1 )
root . left = newNode ( 2 )
root . right = newNode ( 3 )
root . left . left = newNode ( 4 )
root . left . right = newNode ( 5 )
root . right . left = newNode ( 6 )
root . right . right = newNode ( 7 )
root . right . left . right = newNode ( 8 )
print ( " Nodes ▁ at ▁ distance ▁ 2 ▁ are : " , end = " ▁ " )
printKDistantfromLeaf ( root , 2 )

Index/key variables: pathLen
Class/struct names: newNode
Python program:
from collections import deque
class Node :
    def __init__ ( self , key ) :
        self . key = key
        self . left = None
        self . right = None
def printCorner ( root : Node ) :
    if root == None :
        return
    q = deque ( )
    q . append ( root )
    while q :
        n = len ( q )
        for i in range ( n ) :
            temp = q [ 0 ]
            q . popleft ( )
            if i == 0 or i == n - 1 :
                print ( temp . key , end = " ▁ " )
            if temp . left :
                q . append ( temp . left )
            if temp . right :
                q . append ( temp . right )
if __name__ == " _ _ main _ _ " :
    root = Node ( 15 )
    root . left = Node ( 10 )
    root . right = Node ( 20 )
    root . left . left = Node ( 8 )
    root . left . right = Node ( 12 )
    root . right . left = Node ( 16 )
    root . right . right = Node ( 25 )
    printCorner ( root )

Accumulator variables: q
Iterator variables: i
Class/struct names: Node
Python program:
COUNT = [ 10 ]
class newNode :
    def __init__ ( self , key ) :
        self . data = key
        self . left = None
        self . right = None
def print2DUtil ( root , space ) :
    if ( root == None ) :
        return
    space += COUNT [ 0 ]
    print2DUtil ( root . right , space )
    print ( )
    for i in range ( COUNT [ 0 ] , space ) :
        print ( end = " ▁ " )
    print ( root . data )
    print2DUtil ( root . left , space )
def print2D ( root ) :
    print2DUtil ( root , 0 )
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 1 )
    root . left = newNode ( 2 )
    root . right = newNode ( 3 )
    root . left . left = newNode ( 4 )
    root . left . right = newNode ( 5 )
    root . right . left = newNode ( 6 )
    root . right . right = newNode ( 7 )
    root . left . left . left = newNode ( 8 )
    root . left . left . right = newNode ( 9 )
    root . left . right . left = newNode ( 10 )
    root . left . right . right = newNode ( 11 )
    root . right . left . left = newNode ( 12 )
    root . right . left . right = newNode ( 13 )
    root . right . right . left = newNode ( 14 )
    root . right . right . right = newNode ( 15 )
    print2D ( root )

Iterator variables: i
Class/struct names: newNode
Python program:
class newNode :
    def __init__ ( self , key ) :
        self . data = key
        self . left = None
        self . right = None
        self . hd = 0
def printRightView ( root ) :
    if ( not root ) :
        return
    q = [ ]
    q . append ( root )
    while ( len ( q ) ) :
        n = len ( q )
        for i in range ( 1 , n + 1 ) :
            temp = q [ 0 ]
            q . pop ( 0 )
            if ( i == 1 ) :
                print ( temp . data , end = " ▁ " )
            if ( temp . left != None ) :
                q . append ( temp . left )
            if ( temp . right != None ) :
                q . append ( temp . right )
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 10 )
    root . left = newNode ( 2 )
    root . right = newNode ( 3 )
    root . left . left = newNode ( 7 )
    root . left . right = newNode ( 8 )
    root . right . right = newNode ( 15 )
    root . right . left = newNode ( 12 )
    root . right . right . left = newNode ( 14 )
    printRightView ( root )

Accumulator variables: q
Iterator variables: i
Class/struct names: newNode
Python program:
def rotate ( arr , N , X ) :
    nextPower = 1
    while ( nextPower <= N ) :
        nextPower *= 2
    if ( X == 1 ) :
        ans = nextPower - N
        return ans
    prevPower = nextPower // 2
    return 2 * ( N - prevPower ) + 1
arr = [ 1 , 2 , 3 , 4 , 5 ]
X = 1
N = len ( arr )
print ( rotate ( arr , N , X ) )

Accumulator variables: nextPower
Python program:
def findMaximumZeros ( st , n ) :
    c0 = 0
    for i in range ( n ) :
        if ( st [ i ] == '0' ) :
            c0 += 1
    if ( c0 == n ) :
        print ( n )
        return
    s = st + st
    mx = 0
    for i in range ( n ) :
        cs = 0
        ce = 0
        for j in range ( i , i + n ) :
            if ( s [ j ] == '0' ) :
                cs += 1
            else :
                break
        for j in range ( i + n - 1 , i - 1 , - 1 ) :
            if ( s [ j ] == '0' ) :
                ce += 1
            else :
                break
        val = cs + ce
        mx = max ( val , mx )
    print ( mx )
if __name__ == " _ _ main _ _ " :
    s = "1001"
    n = len ( s )
    findMaximumZeros ( s , n )

Index/key variables: i, j
Accumulator variables: c0, ce, cs
Iterator variables: i, j
Python program:
def findMaximumZeros ( string , n ) :
    c0 = 0
    for i in range ( n ) :
        if ( string [ i ] == '0' ) :
            c0 += 1
    if ( c0 == n ) :
        print ( n , end = " " )
        return
    mx = 0
    cnt = 0
    for i in range ( n ) :
        if ( string [ i ] == '0' ) :
            cnt += 1
        else :
            mx = max ( mx , cnt )
            cnt = 0
    mx = max ( mx , cnt )
    start = 0
    end = n - 1
    cnt = 0
    while ( string [ start ] != '1' and start < n ) :
        cnt += 1
        start += 1
    while ( string [ end ] != '1' and end >= 0 ) :
        cnt += 1
        end -= 1
    mx = max ( mx , cnt )
    print ( mx , end = " " )
if __name__ == " _ _ main _ _ " :
    s = "1001"
    n = len ( s )
    findMaximumZeros ( s , n )

Index/key variables: end, i, start
Accumulator variables: c0, cnt
Iterator variables: i
Python program:
def rotateMatrix ( mat ) :
    i = 0
    mat1 = [ ]
    for it in mat :
        it . reverse ( )
        it1 = it [ : i ]
        it1 . reverse ( )
        it2 = it [ i : ]
        it2 . reverse ( )
        i += 1
        mat1 . append ( it1 + it2 )
    for rows in mat1 :
        for cols in rows :
            print ( cols , end = " ▁ " )
        print ( )
if __name__ == " _ _ main _ _ " :
    mat = [ [ 1 , 2 , 3 ] , [ 4 , 5 , 6 ] , [ 7 , 8 , 9 ] ]
    rotateMatrix ( mat )

Accumulator variables: i, mat1
Iterator variables: cols, it, rows