dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def findOperations ( A , B , N ) :
    operations = 0
    ops = [ ]
    invert = False
    for i in range ( N - 1 , - 1 , - 1 ) :
        if ( A [ i ] != B [ i ] ) :
            if ( not invert ) :
                operations += 1
                ops . append ( i + 1 )
                invert = True
        else :
            if ( invert ) :
                operations += 1
                ops . append ( i + 1 )
                invert = False
    print ( operations )
    if ( operations != 0 ) :
        for x in ops :
            print ( x , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    A , B = "001" , "000"
    N = len ( A )
    findOperations ( A , B , N )

Index/key variables: i
Accumulator variables: operations, ops
Iterator variables: i, x
Boolean variables: invert
Python program:
def maxScoreWords ( words , letters , score ) :
    letterCounts = [ 0 ] * ( 26 )
    for letter in letters :
        letterCounts [ ord ( letter ) - ord ( ' a ' ) ] += 1
    return helper ( words , 0 , letterCounts , score )
def helper ( words , start , letterCounts , score ) :
    if ( start == len ( words ) ) :
        return 0
    currScore = 0
    wordScore = 1
    nextCounts = letterCounts
    for i in range ( len ( words [ start ] ) ) :
        idx = ord ( words [ start ] [ i ] ) - ord ( ' a ' )
        if ( nextCounts [ idx ] == 0 ) :
            wordScore = - 1
            break
        wordScore += score [ idx ]
        nextCounts [ idx ] -= 1
    if ( wordScore > 0 ) :
        currScore = helper ( words , start + 1 , nextCounts , score ) + wordScore
    currScore = max ( currScore , helper ( words , start + 1 , letterCounts , score ) )
    return currScore
words = [ " dog " , " cat " , " dad " , " good " ]
letters = [ ' a ' , ' a ' , ' c ' , ' d ' , ' d ' , ' d ' , ' g ' , ' o ' , ' o ' ]
score = [ 1 , 0 , 9 , 5 , 0 , 0 , 3 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 2 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ]
print ( maxScoreWords ( words , letters , score ) )

Index/key variables: i, idx, start
Accumulator variables: wordScore
Iterator variables: i, letter
Python program:
from math import log2
def countFrequency ( S , N ) :
    freq = [ 0 ] * 26
    for i in range ( N ) :
        freq [ ord ( S [ i ] ) - ord ( ' a ' ) ] += 1
    for i in range ( 26 ) :
        if ( freq [ i ] == 0 ) :
            continue
        lg = int ( log2 ( freq [ i ] ) )
        a = pow ( 2 , lg )
        if ( a == freq [ i ] ) :
            while ( freq [ i ] ) :
                print ( chr ( i + ord ( ' a ' ) ) , end = " " )
                freq [ i ] -= 1
if __name__ == ' _ _ main _ _ ' :
    S = " aaacbb "
    N = len ( S )
    countFrequency ( S , N )

Index/key variables: i
Iterator variables: i
Python program:
class treeNode :
    def __init__ ( self , x ) :
        self . square_sum = x
def buildTree ( s , tree , start , end , treeNode ) :
    if ( start == end ) :
        tree [ treeNode ] . square_sum = pow ( ord ( s [ start ] ) - ord ( ' a ' ) + 1 , 2 )
        return
    mid = start + ( ( end - start ) // 2 )
    buildTree ( s , tree , start , mid , 2 * treeNode )
    buildTree ( s , tree , mid + 1 , end , 1 + 2 * treeNode )
    tree [ treeNode ] . square_sum = ( tree [ ( 2 * treeNode ) ] . square_sum + tree [ ( 2 * treeNode ) + 1 ] . square_sum )
def querySquareSum ( tree , start , end , treeNode , l , r ) :
    if ( ( l > end ) or ( r < start ) ) :
        return 0
    if ( ( l <= start ) and ( r >= end ) ) :
        return tree [ treeNode ] . square_sum
    mid = start + ( ( end - start ) // 2 )
    X = querySquareSum ( tree , start , mid , 2 * treeNode , l , r )
    Y = + querySquareSum ( tree , mid + 1 , end , 1 + 2 * treeNode , l , r )
    return X + Y
def updateTree ( s , tree , start , end , treeNode , idx , X ) :
    if ( ( start == end ) and ( idx == start ) ) :
        s [ idx ] = X
        tree [ treeNode ] . square_sum = pow ( ord ( X ) - ord ( ' a ' ) + 1 , 2 )
        return
    mid = start + ( ( end - start ) // 2 )
    if ( idx <= mid ) :
        updateTree ( s , tree , start , mid , ( 2 * treeNode ) , idx , X )
    else :
        updateTree ( s , tree , mid + 1 , end , ( 2 * treeNode ) + 1 , idx , X )
    tree [ treeNode ] . square_sum = ( tree [ ( 2 * treeNode ) ] . square_sum + tree [ ( 2 * treeNode ) + 1 ] . square_sum )
def PerformQuery ( S , Q ) :
    n = len ( S )
    tree = [ treeNode ( 0 ) for i in range ( ( 4 * n ) + 1 ) ]
    for i in range ( 4 * n + 1 ) :
        tree [ i ] . square_sum = 0
    buildTree ( S , tree , 0 , n - 1 , 1 )
    for i in range ( len ( Q ) ) :
        if ( Q [ i ] [ 0 ] == " S " ) :
            L = int ( Q [ i ] [ 1 ] )
            R = int ( Q [ i ] [ 2 ] )
            print ( querySquareSum ( tree , 0 , n - 1 , 1 , L , R ) )
        elif ( Q [ i ] [ 0 ] == " U " ) :
            I = int ( Q [ i ] [ 1 ] )
            updateTree ( S , tree , 0 , n - 1 , 1 , I , Q [ i ] [ 2 ] [ 0 ] )
if __name__ == ' _ _ main _ _ ' :
    S = " geeksforgeeks "
    Q = [ [ " S " , "0" , "2" ] , [ " S " , "1" , "2" ] , [ " U " , "1" , " a " ] , [ " S " , "0" , "2" ] , [ " S " , "4" , "5" ] ]
    PerformQuery ( [ i for i in S ] , Q )

Index/key variables: i, idx, start, treeNode
Iterator variables: i
Class/struct names: treeNode
Python program:
def lcsBySwapping ( A , B ) :
    N = len ( A )
    M = len ( B )
    freq = [ 0 ] * 26
    for i in range ( len ( A ) ) :
        freq [ ord ( A [ i ] ) - ord ( ' a ' ) ] += 1
    for i in range ( len ( B ) ) :
        freq [ ord ( B [ i ] ) - ord ( ' a ' ) ] += 1
    cnt = 0
    for i in range ( 26 ) :
        cnt += freq [ i ] // 2
    print ( min ( cnt , min ( N , M ) ) )
if __name__ == ' _ _ main _ _ ' :
    A = " abdeff "
    B = " abbet "
    lcsBySwapping ( A , B )

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
def maximumLengthSubsequence ( str ) :
    mp = { }
    for ch in str :
        if ch in mp . keys ( ) :
            mp [ ch ] += 1
        else :
            mp [ ch ] = 1
    ans = 0
    for ch in str :
        if chr ( ord ( ch ) - 1 ) in mp . keys ( ) :
            curr_max = mp [ ch ]
            if chr ( ord ( ch ) - 1 ) in mp . keys ( ) :
                curr_max += mp [ chr ( ord ( ch ) - 1 ) ]
            ans = max ( ans , curr_max )
    print ( ans )
S = " acbbebcg "
maximumLengthSubsequence ( S )

Index/key variables: ch
Accumulator variables: curr_max
Iterator variables: ch
Python program:
def countOperations ( X , Y , K ) :
    count = 0
    for i in range ( len ( X ) ) :
        c = 0
        if ( X [ i ] == Y [ i ] ) :
            continue
        elif ( X [ i ] < Y [ i ] ) :
            if ( ( ord ( Y [ i ] ) - ord ( X [ i ] ) ) >= K ) :
                c = ( ord ( Y [ i ] ) - ord ( X [ i ] ) ) // K
            c += ( ord ( Y [ i ] ) - ord ( X [ i ] ) ) % K
        else :
            t = 90 - ord ( X [ i ] )
            t += ord ( Y [ i ] ) - 65 + 1
            if ( t >= K ) :
                c = t // K
            c += ( t % K )
        count += c
    print ( count )
X = " ABCT "
Y = " PBDI "
K = 6
countOperations ( X , Y , K )

Index/key variables: i
Accumulator variables: c, count, t
Iterator variables: i
Python program:
def minimumSwaps ( s , l , r , k ) :
    n = len ( s )
    tot_ones , tot_zeros = 0 , 0
    for i in range ( 0 , len ( s ) ) :
        if ( s [ i ] == '1' ) :
            tot_ones += 1
        else :
            tot_zeros += 1
    ones , zeros , Sum = 0 , 0 , 0
    for i in range ( l - 1 , r ) :
        if ( s [ i ] == '1' ) :
            ones += 1
            Sum += 1
        else :
            zeros += 1
    rem_ones = tot_ones - ones
    rem_zeros = tot_zeros - zeros
    if ( k >= Sum ) :
        rem = k - Sum
        if ( zeros >= rem and rem_ones >= rem ) :
            return rem
    elif ( k < Sum ) :
        rem = Sum - k
        if ( ones >= rem and rem_zeros >= rem ) :
            return rem
    return - 1
S = "110011111000101"
L , R , K = 5 , 8 , 2
print ( minimumSwaps ( S , L , R , K ) )

Index/key variables: i
Accumulator variables: Sum, ones, tot_ones, tot_zeros, zeros
Iterator variables: i
Python program:
Ans = [ ]
def populateNumber ( ) :
    Ans . append ( 2 )
    Ans . append ( 5 )
    x = 5
    while ( x < 1000000000001 ) :
        x *= 2
        Ans . append ( x )
        x = x * 2 + 1
        Ans . append ( x )
def checkString ( N ) :
    populateNumber ( )
    for it in Ans :
        if ( it == N ) :
            return " Yes "
    return " No "
N = 5
print ( checkString ( N ) )

Accumulator variables: Ans, x
Iterator variables: it
Python program:
import sys ;
INT_MAX = sys . maxsize ;
def minimumOperations ( s , n ) :
    mp = { } ;
    for i in range ( n ) :
        if s [ i ] in mp :
            mp [ s [ i ] ] . append ( i ) ;
        else :
            mp [ s [ i ] ] = [ i ] ;
    ans = INT_MAX ;
    for x in mp :
        curr = 0 ;
        prev = 0 ;
        first = True ;
        for index in mp [ x ] :
            if ( first ) :
                if ( index > 0 ) :
                    curr += 1 ;
                prev = index ;
                first = False ;
            else :
                if ( index != prev + 1 ) :
                    curr += 1 ;
                prev = index ;
        if ( prev != n - 1 ) :
            curr += 1 ;
        ans = min ( ans , curr ) ;
    print ( ans ) ;
if __name__ == " _ _ main _ _ " :
    s = " YYXYZYXYZXY " ;
    N = len ( s ) ;
    minimumOperations ( s , N ) ;

Index/key variables: i, x
Accumulator variables: curr
Iterator variables: i, index, x
Boolean variables: first
Python program:
def checkValidDFA ( s ) :
    initial_state = 0
    final_state = 0
    previous_state = 0
    for i in range ( len ( s ) ) :
        if ( ( s [ i ] == '0' and previous_state == 0 ) or ( s [ i ] == '1' and previous_state == 3 ) ) :
            final_state = 1
        elif ( ( s [ i ] == '0' and previous_state == 3 ) or ( s [ i ] == '1' and previous_state == 0 ) ) :
            final_state = 2
        elif ( ( s [ i ] == '0' and previous_state == 1 ) or ( s [ i ] == '1' and previous_state == 2 ) ) :
            final_state = 0
        elif ( ( s [ i ] == '0' and previous_state == 2 ) or ( s [ i ] == '1' and previous_state == 1 ) ) :
            final_state = 3
        previous_state = final_state
    if ( final_state == 3 ) :
        print ( " Accepted " )
    else :
        print ( " Not ▁ Accepted " )
if __name__ == ' _ _ main _ _ ' :
    s = "010011"
    checkValidDFA ( s )

Index/key variables: i
Iterator variables: i
Python program:
class newNode :
    def __init__ ( self , key ) :
        self . data = key
        self . left = None
        self . right = None
def evenOddLevelDifference ( root ) :
    if ( not root ) :
        return 0
    q = [ ]
    q . append ( root )
    level = 0
    evenSum = 0
    oddSum = 0
    while ( len ( q ) ) :
        size = len ( q )
        level += 1
        while ( size > 0 ) :
            temp = q [ 0 ]
            q . pop ( 0 )
            if ( level % 2 == 0 ) :
                evenSum += temp . data
            else :
                oddSum += temp . data
            if ( temp . left ) :
                q . append ( temp . left )
            if ( temp . right ) :
                q . append ( temp . right )
            size -= 1
    return ( oddSum - evenSum )
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 5 )
    root . left = newNode ( 2 )
    root . right = newNode ( 6 )
    root . left . left = newNode ( 1 )
    root . left . right = newNode ( 4 )
    root . left . right . left = newNode ( 3 )
    root . right . right = newNode ( 8 )
    root . right . right . right = newNode ( 9 )
    root . right . right . left = newNode ( 7 )
    result = evenOddLevelDifference ( root )
    print ( " Diffence ▁ between ▁ sums ▁ is " , result )

Accumulator variables: evenSum, level, oddSum, q, size
Class/struct names: newNode
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def leafSum ( root ) :
    global total
    if root is None :
        return
    if ( root . left is None and root . right is None ) :
        total += root . data
    leafSum ( root . left )
    leafSum ( root . right )
if __name__ == ' _ _ main _ _ ' :
    root = Node ( 1 )
    root . left = Node ( 2 )
    root . left . left = Node ( 4 )
    root . left . right = Node ( 5 )
    root . right = Node ( 3 )
    root . right . right = Node ( 7 )
    root . right . left = Node ( 6 )
    root . right . left . right = Node ( 8 )
    total = 0
    leafSum ( root )
    print ( total )

Class/struct names: Node
Python program:
class Node :
    def __init__ ( self , data , left = None , right = None ) :
        self . data = data
        self . left = left
        self . right = right
def morris_traversal ( root ) :
    current = root
    while current is not None :
        if current . left is None :
            yield current . data
            current = current . right
        else :
            pre = current . left
            while pre . right is not None and pre . right is not current :
                pre = pre . right
            if pre . right is None :
                pre . right = current
                current = current . left
            else :
                pre . right = None
                yield current . data
                current = current . right
root = Node ( 1 , right = Node ( 3 ) , left = Node ( 2 , left = Node ( 4 ) , right = Node ( 5 ) ) )
for v in morris_traversal ( root ) :
    print ( v , end = ' ▁ ' )

Iterator variables: v
Class/struct names: Node
Python program:
from collections import deque
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def sumOfLeafNodesAtLeafLevel ( root ) :
    if not root :
        return 0
    if not root . left and not root . right :
        return root . data
    Queue = deque ( )
    sum = f = 0
    Queue . append ( root )
    while not f :
        nc = len ( Queue )
        while nc :
            top = Queue . popleft ( )
            if not top . left and not top . right :
                sum += top . data
                f = 1
            else :
                if top . left :
                    Queue . append ( top . left )
                if top . right :
                    Queue . append ( top . right )
            nc -= 1
    return sum
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 . right . left = Node ( 8 )
    root . right . left . right = Node ( 9 )
    print ( " Sum ▁ = ▁ " , sumOfLeafNodesAtLeafLevel ( root ) )

Accumulator variables: Queue, nc, sum
Class/struct names: Node
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
def inorder ( node ) :
    if ( not node ) :
        return
    inorder ( node . left )
    print ( node . data , end = " ▁ " )
    inorder ( node . right )
def MergeTrees ( t1 , t2 ) :
    if ( not t1 ) :
        return t2
    if ( not t2 ) :
        return t1
    t1 . data += t2 . data
    t1 . left = MergeTrees ( t1 . left , t2 . left )
    t1 . right = MergeTrees ( t1 . right , t2 . right )
    return t1
if __name__ == ' _ _ main _ _ ' :
    root1 = newNode ( 1 )
    root1 . left = newNode ( 2 )
    root1 . right = newNode ( 3 )
    root1 . left . left = newNode ( 4 )
    root1 . left . right = newNode ( 5 )
    root1 . right . right = newNode ( 6 )
    root2 = newNode ( 4 )
    root2 . left = newNode ( 1 )
    root2 . right = newNode ( 7 )
    root2 . left . left = newNode ( 3 )
    root2 . right . left = newNode ( 2 )
    root2 . right . right = newNode ( 6 )
    root3 = MergeTrees ( root1 , root2 )
    print ( " The ▁ Merged ▁ Binary ▁ Tree ▁ is : " )
    inorder ( root3 )

Class/struct names: newNode
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
class snode :
    def __init__ ( self , l , r ) :
        self . l = l
        self . r = r
def newNode ( data ) :
    new_node = Node ( data )
    return new_node
def inorder ( node ) :
    if ( not node ) :
        return ;
    inorder ( node . left ) ;
    print ( node . data , end = ' ▁ ' ) ;
    inorder ( node . right ) ;
def MergeTrees ( t1 , t2 ) :
    if ( not t1 ) :
        return t2 ;
    if ( not t2 ) :
        return t1 ;
    s = [ ]
    temp = snode ( t1 , t2 )
    s . append ( temp ) ;
    n = None
    while ( len ( s ) != 0 ) :
        n = s [ - 1 ]
        s . pop ( ) ;
        if ( n . l == None or n . r == None ) :
            continue ;
        n . l . data += n . r . data ;
        if ( n . l . left == None ) :
            n . l . left = n . r . left ;
        else :
            t = snode ( n . l . left , n . r . left )
            s . append ( t ) ;
        if ( n . l . right == None ) :
            n . l . right = n . r . right ;
        else :
            t = snode ( n . l . right , n . r . right )
            s . append ( t ) ;
    return t1 ;
if __name__ == ' _ _ main _ _ ' :
    root1 = newNode ( 1 ) ;
    root1 . left = newNode ( 2 ) ;
    root1 . right = newNode ( 3 ) ;
    root1 . left . left = newNode ( 4 ) ;
    root1 . left . right = newNode ( 5 ) ;
    root1 . right . right = newNode ( 6 ) ;
    root2 = newNode ( 4 ) ;
    root2 . left = newNode ( 1 ) ;
    root2 . right = newNode ( 7 ) ;
    root2 . left . left = newNode ( 3 ) ;
    root2 . right . left = newNode ( 2 ) ;
    root2 . right . right = newNode ( 6 ) ;
    root3 = MergeTrees ( root1 , root2 ) ;
    print ( " The ▁ Merged ▁ Binary ▁ Tree ▁ is : " ) ;
    inorder ( root3 ) ;

Accumulator variables: s
Class/struct names: Node, snode
Python program:
def findRoot ( arr , n ) :
    root = 0
    for i in range ( n ) :
        root += ( arr [ i ] [ 0 ] - arr [ i ] [ 1 ] )
    return root
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 1 , 5 ] , [ 2 , 0 ] , [ 3 , 0 ] , [ 4 , 0 ] , [ 5 , 5 ] , [ 6 , 5 ] ]
    n = len ( arr )
    print ( findRoot ( arr , n ) )

Index/key variables: i
Accumulator variables: root
Iterator variables: i
Python program:
def search ( arr , x , n ) :
    for i in range ( n ) :
        if ( arr [ i ] == x ) :
            return i
    return - 1
def printPostOrder ( In , pre , n ) :
    root = search ( In , pre [ 0 ] , n )
    if ( root != 0 ) :
        printPostOrder ( In , pre [ 1 : n ] , root )
    if ( root != n - 1 ) :
        printPostOrder ( In [ root + 1 : n ] , pre [ root + 1 : n ] , n - root - 1 )
    print ( pre [ 0 ] , end = " ▁ " )
In = [ 4 , 2 , 5 , 1 , 3 , 6 ]
pre = [ 1 , 2 , 4 , 5 , 3 , 6 ]
n = len ( In )
print ( " Postorder ▁ traversal ▁ " )
printPostOrder ( In , pre , n )

Index/key variables: i
Iterator variables: i
Python program:
maxn = 100005
g = [ [ ] for i in range ( maxn ) ]
level = [ 0 ] * maxn
e = [ ]
l = [ ]
h = [ 0 ] * maxn
st = [ 0 ] * ( 5 * maxn )
def add_edge ( u : int , v : int ) :
    g [ u ] . append ( v )
    g [ v ] . append ( u )
def leveling ( src : int ) :
    for i in range ( len ( g [ src ] ) ) :
        des = g [ src ] [ i ]
        if not level [ des ] :
            level [ des ] = level [ src ] + 1
            leveling ( des )
visited = [ False ] * maxn
def dfs ( src : int ) :
    e . append ( src )
    visited [ src ] = True
    for i in range ( len ( g [ src ] ) ) :
        des = g [ src ] [ i ]
        if not visited [ des ] :
            dfs ( des )
            e . append ( src )
def setting_l ( n : int ) :
    for i in range ( len ( e ) ) :
        l . append ( level [ e [ i ] ] )
def setting_h ( n : int ) :
    for i in range ( n + 1 ) :
        h [ i ] = - 1
    for i in range ( len ( e ) ) :
        if h [ e [ i ] ] == - 1 :
            h [ e [ i ] ] = i
def RMQ ( ss : int , se : int , qs : int , qe : int , i : int ) -> int :
    global st
    if ss > se :
        return - 1
    if se < qs or qe < ss :
        return - 1
    if qs <= ss and se <= qe :
        return st [ i ]
    mid = ( se + ss ) >> 1
    stt = RMQ ( ss , mid , qs , qe , 2 * i + 1 )
    en = RMQ ( mid + 1 , se , qs , qe , 2 * i + 2 )
    if stt != - 1 and en != - 1 :
        if l [ stt ] < l [ en ] :
            return stt
        return en
    elif stt != - 1 :
        return stt
    elif en != - 1 :
        return en
def segmentTreeConstruction ( ss : int , se : int , i : int ) :
    if ss > se :
        return
    if ss == se :
        st [ i ] = ss
        return
    mid = ( ss + se ) >> 1
    segmentTreeConstruction ( ss , mid , 2 * i + 1 )
    segmentTreeConstruction ( mid + 1 , se , 2 * i + 2 )
    if l [ st [ 2 * i + 1 ] ] < l [ st [ 2 * i + 2 ] ] :
        st [ i ] = st [ 2 * i + 1 ]
    else :
        st [ i ] = st [ 2 * i + 2 ]
def LCA ( x : int , y : int ) -> int :
    if h [ x ] > h [ y ] :
        x , y = y , x
    return e [ RMQ ( 0 , len ( l ) - 1 , h [ x ] , h [ y ] , 0 ) ]
if __name__ == " _ _ main _ _ " :
    n = 15
    q = 5
    add_edge ( 1 , 2 )
    add_edge ( 1 , 3 )
    add_edge ( 1 , 4 )
    add_edge ( 3 , 5 )
    add_edge ( 4 , 6 )
    add_edge ( 5 , 7 )
    add_edge ( 5 , 8 )
    add_edge ( 5 , 9 )
    add_edge ( 7 , 10 )
    add_edge ( 7 , 11 )
    add_edge ( 7 , 12 )
    add_edge ( 9 , 13 )
    add_edge ( 9 , 14 )
    add_edge ( 12 , 15 )
    level [ 1 ] = 1
    leveling ( 1 )
    dfs ( 1 )
    setting_l ( n )
    setting_h ( n )
    segmentTreeConstruction ( 0 , len ( l ) - 1 , 0 )
    print ( LCA ( 10 , 15 ) )
    print ( LCA ( 11 , 14 ) )

Index/key variables: des, en, i, src, stt, u, v, x, y
Accumulator variables: e, l
Iterator variables: i
Python program:
class newNode :
    def __init__ ( self , key ) :
        self . key = key
        self . left = self . right = None
def findLCA ( root , n1 , n2 ) :
    if ( root == None ) :
        return None
    if ( root . key == n1 or root . key == n2 ) :
        return root
    left_lca = findLCA ( root . left , n1 , n2 )
    right_lca = findLCA ( root . right , n1 , n2 )
    if ( left_lca and right_lca ) :
        return root
    if ( left_lca != None ) :
        return left_lca
    else :
        return right_lca
def printAncestors ( root , target ) :
    if ( root == None ) :
        return False
    if ( root . key == target ) :
        print ( root . key , end = " ▁ " )
        return True
    if ( printAncestors ( root . left , target ) or printAncestors ( root . right , target ) ) :
        print ( root . key , end = " ▁ " )
        return True
    return False
def findCommonNodes ( root , first , second ) :
    LCA = findLCA ( root , first , second )
    if ( LCA == None ) :
        return False
    printAncestors ( root , LCA . key )
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 . right . left . left = newNode ( 9 )
    root . right . left . right = newNode ( 10 )
    if ( findCommonNodes ( root , 9 , 7 ) == False ) :
        print ( " No ▁ Common ▁ nodes " )

Class/struct names: newNode
Python program:
class Node :
    def __init__ ( self , key ) :
        self . left = None
        self . right = None
        self . val = key

Class/struct names: Node