dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def longestSubWithMaxSum ( arr , N ) :
    Max = max ( arr )
    if ( Max < 0 ) :
        print ( Max )
        return
    for i in range ( N ) :
        if ( arr [ i ] >= 0 ) :
            print ( arr [ i ] , end = " ▁ " )
arr = [ 1 , 2 , - 4 , - 2 , 3 , 0 ]
N = len ( arr )
longestSubWithMaxSum ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
from bisect import bisect , bisect_left , bisect_right
def findMinimumOperations ( s , s1 ) :
    n = len ( s )
    m = len ( s1 )
    frequency = [ 0 ] * 26
    for i in range ( n ) :
        frequency [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1
    for i in range ( m ) :
        if ( frequency [ ord ( s1 [ i ] ) - ord ( ' a ' ) ] == 0 ) :
            return - 1
    indices = [ [ ] for i in range ( 26 ) ]
    for i in range ( n ) :
        indices [ ord ( s [ i ] ) - ord ( ' a ' ) ] . append ( i )
    ans = 2
    last = len ( indices [ ord ( s1 [ 0 ] ) - ord ( ' a ' ) ] ) - 1
    for i in range ( 1 , m ) :
        ch = ord ( s1 [ i ] ) - ord ( ' a ' )
        it = bisect_right ( indices [ ch ] , last )
        if ( it != len ( indices [ ch ] ) ) :
            last = it
        else :
            ans += 1
            last = len ( indices [ ch ] )
    return ans
if __name__ == ' _ _ main _ _ ' :
    S1 = " acebcd "
    S2 = " acbcde "
    ans = findMinimumOperations ( S1 , S2 )
    if ( ans == - 1 ) :
        print ( " NO " )
    else :
        print ( " YES " )
        print ( ans )

Index/key variables: ch, i
Accumulator variables: ans
Iterator variables: i
Python program:
class newnode :
    def __init__ ( self , key ) :
        self . data = key
        self . left = None
        self . right = None
def isLeaf ( root ) :
    return ( root . left == None and root . right == None )
def sink ( root ) :
    if ( root == None or isLeaf ( root ) ) :
        return
    if ( root . left and not ( root . left . data & 1 ) ) :
        root . data , root . left . data = root . left . data , root . data
        sink ( root . left )
    elif ( root . right and not ( root . right . data & 1 ) ) :
        root . data , root . right . data = root . right . data , root . data
        sink ( root . right )
def sinkOddNodes ( root ) :
    if ( root == None or isLeaf ( root ) ) :
        return
    sinkOddNodes ( root . left )
    sinkOddNodes ( root . right )
    if ( root . data & 1 ) :
        sink ( root )
def printLevelOrder ( root ) :
    q = [ ]
    q . append ( root )
    while ( len ( q ) ) :
        nodeCount = len ( q )
        while ( nodeCount ) :
            node = q [ 0 ]
            print ( node . data , end = " ▁ " )
            q . pop ( 0 )
            if ( node . left != None ) :
                q . append ( node . left )
            if ( node . right != None ) :
                q . append ( node . right )
            nodeCount -= 1
        print ( )
root = newnode ( 1 )
root . left = newnode ( 5 )
root . right = newnode ( 8 )
root . left . left = newnode ( 2 )
root . left . right = newnode ( 4 )
root . right . left = newnode ( 9 )
root . right . right = newnode ( 10 )
sinkOddNodes ( root )
print ( " Level ▁ order ▁ traversal ▁ of ▁ modified ▁ tree " )
printLevelOrder ( root )

Accumulator variables: nodeCount, q
Class/struct names: newnode
Python program:
import math
def digiSum ( a ) :
    sums = 0
    while ( a != 0 ) :
        sums += a % 10
        a = a // 10
    return sums
def isPrime ( r ) :
    s = True
    for i in range ( 2 , int ( math . sqrt ( r ) ) + 1 ) :
        if ( r % i == 0 ) :
            s = False
            break
    return s
def isMorannumber ( n ) :
    dup = n
    sums = digiSum ( dup )
    if ( n % sums == 0 ) :
        c = n // sums
        if isPrime ( c ) :
            return True
    return False
def FirstKMorannumber ( a , n , k ) :
    X = k
    a . sort ( )
    s = set ( )
    for i in range ( n - 1 , - 1 , - 1 ) :
        if ( k <= 0 ) :
            break
        if ( isMorannumber ( a [ i ] ) ) :
            s . add ( a [ i ] )
            k -= 1
    if ( k > 0 ) :
        print ( X , end = ' ▁ Moran ▁ numbers ▁ are ▁ not ▁ ' ' present ▁ in ▁ the ▁ array ' )
        return
    lists = sorted ( s )
    for i in lists :
        print ( i , end = ' , ▁ ' )
if __name__ == ' _ _ main _ _ ' :
    A = [ 34 , 198 , 21 , 42 , 63 , 45 , 22 , 44 , 43 ]
    K = 4
    N = len ( A )
    FirstKMorannumber ( A , N , K )

Index/key variables: i
Accumulator variables: k, s, sums
Iterator variables: i
Boolean variables: s
Python program:
from math import pow
def countPair ( arr , n ) :
    m = { }
    for i in range ( n ) :
        m [ arr [ i ] ] = m . get ( arr [ i ] , 0 ) + 1
    ans = 0
    for i in range ( 31 ) :
        key = int ( pow ( 2 , i ) )
        for j in range ( n ) :
            k = key - arr [ j ]
            if k not in m :
                continue
            else :
                ans += m . get ( k , 0 )
            if ( k == arr [ j ] ) :
                ans += 1
    return ans // 2
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 8 , 2 , 10 , 6 ]
    n = len ( arr )
    print ( countPair ( arr , n ) )

Index/key variables: i, j
Accumulator variables: ans
Iterator variables: i, j
Python program:
def findRockSample ( ranges , n , r , arr ) :
    a = [ ]
    for i in range ( r ) :
        c = 0
        l , h = ranges [ i ] [ 0 ] , ranges [ i ] [ 1 ]
        for val in arr :
            if l <= val <= h :
                c += 1
        a . append ( c )
    return a
if __name__ == " _ _ main _ _ " :
    n = 5
    r = 2
    arr = [ 400 , 567 , 890 , 765 , 987 ]
    ranges = [ [ 300 , 380 ] , [ 800 , 1000 ] ]
    print ( * findRockSample ( ranges , n , r , arr ) )

Index/key variables: i
Accumulator variables: a, c
Iterator variables: i, val
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def isleaf ( curr_node ) :
    return ( curr_node . left == None and curr_node . right == None )
def deepestOddLevelDepthUtil ( curr_node , curr_level ) :
    if ( curr_node == None ) :
        return 0
    curr_level += 1
    if ( curr_level % 2 != 0 and isleaf ( curr_node ) ) :
        return curr_level
    return max ( deepestOddLevelDepthUtil ( curr_node . left , curr_level ) , deepestOddLevelDepthUtil ( curr_node . right , curr_level ) )
def deepestOddLevelDepth ( curr_node ) :
    return deepestOddLevelDepthUtil ( curr_node , 0 )
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 10 )
    root . left = newNode ( 28 )
    root . right = newNode ( 13 )
    root . right . left = newNode ( 14 )
    root . right . right = newNode ( 15 )
    root . right . right . left = newNode ( 23 )
    root . right . right . right = newNode ( 24 )
    print ( deepestOddLevelDepth ( root ) )

Class/struct names: newNode
Python program:
result = [ ]
def findNumbers ( st , prev , n , K ) :
    global result
    if ( len ( st ) == n ) :
        result . append ( int ( st ) )
        return
    if ( len ( st ) == n - 1 ) :
        if ( prev - K >= 0 ) :
            pt = " "
            pt += prev - K + 48
            findNumbers ( st + pt , prev - K , n , K )
        if ( K != 0 and prev + K < 10 ) :
            pt = " "
            pt += prev + K + 48
            findNumbers ( st + pt , prev + K , n , K )
    else :
        for j in range ( 1 , 10 , 1 ) :
            pt = " "
            pt += j + 48
            findNumbers ( st + pt , prev , n , K )
def numDifference ( N , K ) :
    global result
    st = " "
    if ( N == 1 and K == 0 ) :
        result . append ( 0 )
    elif ( N == 1 and K > 0 ) :
        return result
    for i in range ( 1 , 10 , 1 ) :
        temp = " "
        temp += str ( 48 + i )
        findNumbers ( st + temp , i , N , K )
        st = " "
    return result
def numDifferenceUtil ( N , K ) :
    res = [ ]
    res = numDifference ( N , K )
    for i in range ( 1 , len ( res ) ) :
        print ( res [ i ] + 40 , end = " ▁ " )
        break
if __name__ == ' _ _ main _ _ ' :
    N = 2
    K = 9
    numDifferenceUtil ( N , K )

Index/key variables: i
Accumulator variables: pt, temp
Iterator variables: i, j
Python program:
def findMinBulletShots ( points ) :
    for i in range ( len ( points ) ) :
        points [ i ] = points [ i ] [ : : - 1 ]
    points = sorted ( points )
    for i in range ( len ( points ) ) :
        points [ i ] = points [ i ] [ : : - 1 ]
    if ( len ( points ) == 0 ) :
        return 0
    cnt = 1
    curr = points [ 0 ] [ 1 ]
    for j in range ( 1 , len ( points ) ) :
        if ( curr < points [ j ] [ 0 ] ) :
            cnt += 1
            curr = points [ j ] [ 1 ]
    return cnt
if __name__ == ' _ _ main _ _ ' :
    bricks = [ [ 5000 , 900000 ] , [ 1 , 100 ] , [ 150 , 499 ] ]
    print ( findMinBulletShots ( bricks ) )

Index/key variables: i, j
Accumulator variables: cnt
Iterator variables: i, j
Python program:
def countMaximum ( a , n ) :
    a . sort ( reverse = True ) ;
    count = 0 ;
    mark = 0 ;
    for i in range ( n ) :
        if ( ( a [ i ] + n >= mark ) ) :
            count += 1 ;
        mark = max ( mark , a [ i ] + i + 1 ) ;
    print ( count ) ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 8 , 9 , 6 ] ;
    N = len ( arr ) ;
    countMaximum ( arr , N ) ;

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def findKthChar ( n , k ) :
    prev = " A "
    cur = " "
    if ( n == 1 ) :
        return ' A '
    for i in range ( 2 , n + 1 ) :
        cur = prev + " B "
        temp1 = [ y for y in prev ]
        for i in range ( len ( prev ) ) :
            if ( temp1 [ i ] == ' A ' ) :
                temp1 [ i ] = ' B '
            else :
                temp1 [ i ] = ' A '
        temp1 = temp1 [ : : - 1 ]
        prev = " " . join ( temp1 )
        cur += prev
        prev = cur
    return cur [ k - 1 ]
if __name__ == ' _ _ main _ _ ' :
    N = 4
    K = 3
    print ( findKthChar ( N , K ) )

Index/key variables: i
Accumulator variables: cur
Iterator variables: i
Python program:
from collections import deque
def maxSubarray ( a , k ) :
    n = len ( a )
    answer = 0
    start = 0
    s = 0
    dq = deque ( )
    for i in range ( n ) :
        x = a [ i ]
        while ( len ( dq ) > 0 and a [ dq [ - 1 ] ] <= x ) :
            dq . popleft ( )
        dq . append ( i )
        s += x
        cost = a [ dq [ 0 ] ] * ( answer + 1 ) - s
        if ( cost <= k ) :
            answer += 1
        else :
            if ( dq [ 0 ] == start ) :
                dq . popleft ( )
            s -= a [ start ]
            start += 1
    return answer
if __name__ == ' _ _ main _ _ ' :
    a = [ 2 , 2 , 4 ]
    k = 10
    print ( maxSubarray ( a , k ) )

Index/key variables: i, start
Accumulator variables: answer, dq, s
Iterator variables: i
Python program:
def canSplitArray ( arr , n , k ) :
    for i in range ( n ) :
        if ( arr [ i ] <= k ) :
            return " No "
    return " Yes "
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 4 , 6 , 1 , 8 , 16 ]
    N = len ( arr )
    K = 3
    print ( canSplitArray ( arr , N , K ) )

Index/key variables: i
Iterator variables: i
Python program:
def uniqueElement ( arr ) :
    x = arr [ 0 ]
    flag = 1
    for i in range ( len ( arr ) ) :
        if ( arr [ i ] != x ) :
            flag = 0
            break
    if ( flag == 1 ) :
        print ( " Yes " )
    else :
        print ( " No " )
arr = [ 9 , 9 , 9 , 9 , 9 , 9 , 9 ]
uniqueElement ( arr )

Index/key variables: i
Iterator variables: i
Python program:
def maxCount ( freq , maxi , mini ) :
    n = len ( freq ) - 1
    ans = 0
    sum = 2 * mini
    while sum <= 2 * maxi :
        possiblePair = 0
        for firElement in range ( 1 , ( sum + 1 ) // 2 ) :
            if ( sum - firElement <= maxi ) :
                possiblePair += min ( freq [ firElement ] , freq [ sum - firElement ] )
        sum += 1
        if ( sum % 2 == 0 ) :
            possiblePair += freq [ sum // 2 ] // 2
        ans = max ( ans , possiblePair )
    return ans
def countofPairs ( a ) :
    n = len ( a )
    freq = [ 0 ] * ( n + 1 )
    maxi = - 1
    mini = n + 1
    for i in range ( len ( a ) ) :
        maxi = max ( maxi , a [ i ] )
        mini = min ( mini , a [ i ] )
    for i in range ( n ) :
        freq [ a [ i ] ] += 1
    return maxCount ( freq , maxi , mini )
if __name__ == " _ _ main _ _ " :
    a = [ 1 , 2 , 4 , 3 , 3 , 5 , 6 ]
    print ( countofPairs ( a ) )

Index/key variables: firElement, i
Accumulator variables: possiblePair, sum
Iterator variables: firElement, i
Python program:
def getMaxSum ( a , n ) :
    dp = [ [ 0 for x in range ( 2 ) ] for y in range ( n ) ]
    dp [ 0 ] [ 0 ] = a [ 0 ]
    dp [ 0 ] [ 1 ] = a [ 0 ] * a [ 0 ]
    max_sum = max ( dp [ 0 ] [ 0 ] , dp [ 0 ] [ 1 ] )
    for i in range ( 1 , n ) :
        dp [ i ] [ 0 ] = max ( a [ i ] , dp [ i - 1 ] [ 0 ] + a [ i ] )
        dp [ i ] [ 1 ] = max ( dp [ i - 1 ] [ 1 ] + a [ i ] , a [ i ] * a [ i ] )
        dp [ i ] [ 1 ] = max ( dp [ i ] [ 1 ] , dp [ i - 1 ] [ 0 ] + a [ i ] * a [ i ] )
        max_sum = max ( max_sum , dp [ i ] [ 1 ] )
        max_sum = max ( max_sum , dp [ i ] [ 0 ] )
    return max_sum
n = 5
a = [ 1 , - 5 , 8 , 12 , - 8 ]
print ( getMaxSum ( a , n ) )

Index/key variables: i
Iterator variables: i
Python program:
from collections import defaultdict
import sys
def subArraylen ( arr , n , K ) :
    mp = defaultdict ( lambda : 0 )
    mp [ arr [ 0 ] ] = 0
    for i in range ( 1 , n ) :
        arr [ i ] = arr [ i ] + arr [ i - 1 ]
        mp [ arr [ i ] ] = i
    ln = sys . maxsize
    for i in range ( n ) :
        if ( arr [ i ] < K ) :
            continue
        else :
            x = K - arr [ i ]
            if ( x == 0 ) :
                ln = min ( ln , i )
            if ( x in mp . keys ( ) ) :
                continue
            else :
                ln = min ( ln , i - mp [ x ] )
    return ln
arr = [ 1 , 2 , 4 , 3 , 2 , 4 , 1 ]
n = len ( arr )
K = 7
ln = subArraylen ( arr , n , K )
if ( ln == sys . maxsize ) :
    print ( " - 1" )
else :
    print ( ln )

Index/key variables: i, x
Iterator variables: i
Python program:
INT_MAX = 2 ** 31
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
def maxOddLevelDepth ( root ) :
    if ( not root ) :
        return 0
    q = [ ]
    q . append ( root )
    result = INT_MAX
    level = 0
    while ( len ( q ) ) :
        size = len ( q )
        level += 1
        while ( size > 0 ) :
            temp = q [ 0 ]
            q . pop ( 0 )
            if ( not temp . left and not temp . right and ( level % 2 != 0 ) ) :
                result = level
            if ( temp . left ) :
                q . append ( temp . left )
            if ( temp . right ) :
                q . append ( temp . right )
            size -= 1
    return result
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 1 )
    root . left = newNode ( 2 )
    root . right = newNode ( 3 )
    root . left . left = newNode ( 4 )
    root . right . left = newNode ( 5 )
    root . right . right = newNode ( 6 )
    root . right . left . right = newNode ( 7 )
    root . right . right . right = newNode ( 8 )
    root . right . left . right . left = newNode ( 9 )
    root . right . right . right . right = newNode ( 10 )
    root . right . right . right . right . left = newNode ( 11 )
    result = maxOddLevelDepth ( root )
    if ( result == INT_MAX ) :
        print ( " No ▁ leaf ▁ node ▁ at ▁ odd ▁ level " )
    else :
        print ( result , end = " " )
        print ( " ▁ is ▁ the ▁ required ▁ depth ▁ " )

Accumulator variables: level, q, size
Class/struct names: newNode
Python program:
prime = [ True for i in range ( 100001 ) ]
def SieveOfEratosthenes ( ) :
    p = 2
    while ( p * p <= 100000 ) :
        if ( prime [ p ] == True ) :
            for i in range ( p * p , 100001 , p ) :
                prime [ i ] = False
        p += 1
def fibonacciOfPrime ( n1 , n2 ) :
    SieveOfEratosthenes ( )
    initial = [ ]
    for i in range ( n1 , n2 ) :
        if prime [ i ] :
            initial . append ( i )
    now = [ ]
    for a in initial :
        for b in initial :
            if a != b :
                c = str ( a ) + str ( b )
                now . append ( int ( c ) )
    current = [ ]
    for x in now :
        if prime [ x ] :
            current . append ( x )
    current = set ( current )
    first = min ( current )
    second = max ( current )
    count = len ( current ) - 1
    curr = 1
    while curr < count :
        c = first + second
        first = second
        second = c
        curr += 1
    print ( c )
if __name__ == " _ _ main _ _ " :
    x = 2
    y = 40
    fibonacciOfPrime ( x , y )

Index/key variables: i, p, x
Accumulator variables: curr, current, initial, now
Iterator variables: a, b, i, x
Python program:
import sys
def countElements ( arr , n , k ) :
    s = [ ]
    next_greater = [ n ] * ( n + 1 )
    for i in range ( n ) :
        if ( len ( s ) == 0 ) :
            s . append ( i )
            continue
        while ( len ( s ) != 0 and arr [ s [ - 1 ] ] < arr [ i ] ) :
            next_greater [ s [ - 1 ] ] = i
            s . pop ( - 1 )
        s . append ( i )
    count = 0
    maxi = - sys . maxsize - 1
    for i in range ( n ) :
        if ( next_greater [ i ] - i > k and maxi < arr [ i ] ) :
            maxi = max ( maxi , arr [ i ] )
            count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 2 , 3 , 6 , 4 , 3 , 2 ]
    K = 2
    n = len ( arr )
    print ( countElements ( arr , n , K ) )

Index/key variables: i
Accumulator variables: count, s
Iterator variables: i
Python program:
def maxLengthOf1s ( arr , n ) :
    prefix = [ 0 for i in range ( n ) ]
    for i in range ( 2 , n ) :
        if ( arr [ i - 2 ] == 1 ) :
            prefix [ i ] = prefix [ i - 1 ] + 1
        else :
            prefix [ i ] = 0
    suffix = [ 0 for i in range ( n ) ]
    for i in range ( n - 3 , - 1 , - 1 ) :
        if ( arr [ i + 2 ] == 1 ) :
            suffix [ i ] = suffix [ i + 1 ] + 1
        else :
            suffix [ i ] = 0
    ans = 0
    for i in range ( n - 1 ) :
        ans = max ( ans , prefix [ i + 1 ] + suffix [ i ] )
    print ( ans )
n = 6
arr = [ 1 , 1 , 1 , 0 , 1 , 1 ]
maxLengthOf1s ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
def minOperations ( s ) :
    n = len ( s )
    pos = - 1
    for i in range ( len ( s ) ) :
        if ( s [ i ] == '1' ) :
            pos = i
            break
    if ( pos == - 1 ) :
        return 0
    last = 1
    ans = 1
    for i in range ( pos + 1 , n ) :
        if ( s [ i ] == '0' ) :
            if ( last == 1 ) :
                ans += 1
                last = 0
        else :
            if ( last == 0 ) :
                ans += 1
                last = 1
    return ans
if __name__ == " _ _ main _ _ " :
    s = "10111"
    print ( minOperations ( s ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
        self . visited = False
def find ( root , level , maxLevel , res ) :
    if ( root != None ) :
        level += 1
        find ( root . left , level , maxLevel , res )
        if ( level > maxLevel [ 0 ] ) :
            res [ 0 ] = root . data
            maxLevel [ 0 ] = level
        find ( root . right , level , maxLevel , res )
def deepestNode ( root ) :
    res = [ - 1 ]
    maxLevel = [ - 1 ]
    find ( root , 0 , maxLevel , res )
    return res [ 0 ]
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 1 )
    root . left = newNode ( 2 )
    root . right = newNode ( 3 )
    root . left . left = newNode ( 4 )
    root . right . left = newNode ( 5 )
    root . right . right = newNode ( 6 )
    root . right . left . right = newNode ( 7 )
    root . right . right . right = newNode ( 8 )
    root . right . left . right . left = newNode ( 9 )
    print ( deepestNode ( root ) )

Class/struct names: newNode
Python program:
def countClumps ( arr , N ) :
    clumps = 0
    i = 0
    while ( i < N - 1 ) :
        flag = 0
        while ( i + 1 < N and arr [ i ] == arr [ i + 1 ] ) :
            flag = 1
            i += 1
        if ( flag ) :
            clumps += 1
        i += 1
    return clumps
arr = [ 13 , 15 , 66 , 66 , 66 , 37 , 37 , 8 , 8 , 11 , 11 ]
N = len ( arr )
print ( countClumps ( arr , N ) )

Index/key variables: i
Accumulator variables: clumps
Python program:
def iskPalindromesPossible ( s , k ) :
    if ( len ( s ) < k ) :
        print ( " Not ▁ Possible " )
        return
    if ( len ( s ) == k ) :
        print ( " Possible " )
        return
    freq = dict . fromkeys ( s , 0 )
    for i in range ( len ( s ) ) :
        freq [ s [ i ] ] += 1
    count = 0
    for value in freq . values ( ) :
        if ( value % 2 == 1 ) :
            count += 1
    if ( count > k ) :
        print ( " No " )
    else :
        print ( " Yes " )
if __name__ == ' _ _ main _ _ ' :
    str1 = " poor "
    K = 3
    iskPalindromesPossible ( str1 , K )
    str = " geeksforgeeks "
    K = 10
    iskPalindromesPossible ( str , K )

Index/key variables: i
Accumulator variables: count
Iterator variables: i, value
Python program:
class new_Node :
    def __init__ ( self , key ) :
        self . data = key
        self . left = self . right = None
def height ( root ) :
    if ( not root ) :
        return 0
    leftHt = height ( root . left )
    rightHt = height ( root . right )
    return max ( leftHt , rightHt ) + 1
def deepestNode ( root , levels ) :
    if ( not root ) :
        return
    if ( levels == 1 ) :
        print ( root . data )
    elif ( levels > 1 ) :
        deepestNode ( root . left , levels - 1 )
        deepestNode ( root . right , levels - 1 )
if __name__ == ' _ _ main _ _ ' :
    root = new_Node ( 1 )
    root . left = new_Node ( 2 )
    root . right = new_Node ( 3 )
    root . left . left = new_Node ( 4 )
    root . right . left = new_Node ( 5 )
    root . right . right = new_Node ( 6 )
    root . right . left . right = new_Node ( 7 )
    root . right . right . right = new_Node ( 8 )
    root . right . left . right . left = new_Node ( 9 )
    levels = height ( root )
    deepestNode ( root , levels )

Class/struct names: new_Node
Python program:
def findPivot ( arr , low , high ) :
    if ( high < low ) :
        return - 1 ;
    if ( high == low ) :
        return low ;
    mid = ( low + high ) // 2 ;
    if ( mid < high and arr [ mid + 1 ] < arr [ mid ] ) :
        return mid ;
    if ( mid > low and arr [ mid ] < arr [ mid - 1 ] ) :
        return mid - 1 ;
    if ( arr [ low ] > arr [ mid ] ) :
        return findPivot ( arr , low , mid - 1 ) ;
    else :
        return findPivot ( arr , mid + 1 , high ) ;
def isRotated ( arr , n ) :
    l = 0 ;
    r = n - 1 ;
    pivot = - 1 ;
    if ( arr [ l ] > arr [ r ] ) :
        pivot = findPivot ( arr , l , r ) ;
        temp = pivot
        if ( l < pivot ) :
            while ( pivot > l ) :
                if ( arr [ pivot ] < arr [ pivot - 1 ] ) :
                    return False ;
                pivot -= 1 ;
        else :
            pivot = temp
            pivot += 1 ;
            while ( pivot < r ) :
                if ( arr [ pivot ] > arr [ pivot + 1 ] ) :
                    return False ;
                pivot + + 1 ;
        return True ;
    else :
        return False ;
if __name__ == " _ _ main _ _ " :
    arr = [ 3 , 4 , 5 , 1 , 2 ] ;
    if ( isRotated ( arr , 5 ) ) :
        print ( " True " ) ;
    else :
        print ( " False " ) ;

Index/key variables: l, low, mid, pivot, r