dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
import sys
N = 3
def search ( mat , n , m ) :
    a = sys . maxsize
    for i in range ( n ) :
        low = 0
        high = m - 1
        ans = sys . maxsize
        while ( low <= high ) :
            mid = ( low + high ) // 2
            if ( mat [ i ] [ mid ] == 1 ) :
                if ( mid == 0 ) :
                    ans = 0
                    break
                elif ( mat [ i ] [ mid - 1 ] == 0 ) :
                    ans = mid
                    break
            if ( mat [ i ] [ mid ] == 1 ) :
                high = mid - 1
            else :
                low = mid + 1
        if ( ans < a ) :
            a = ans
    if ( a == sys . maxsize ) :
        return - 1
    return a + 1
if __name__ == " _ _ main _ _ " :
    mat = [ [ 0 , 0 , 0 ] , [ 0 , 0 , 1 ] , [ 0 , 1 , 1 ] ]
    print ( search ( mat , 3 , 3 ) )

Index/key variables: i, mid
Iterator variables: i
Python program:
def maxSubstring ( S , K , N ) :
    def maxSubstring ( S , K , N ) :
        freq = [ 0 for i in range ( 26 ) ]
        for i in range ( N ) :
            freq [ ord ( S [ i ] ) - 97 ] = 1
        answer = [ ]
        for i in range ( 26 ) :
            if ( freq [ i ] == 0 ) :
                continue
            ch = chr ( i + 97 )
            count = 0
            index = - 1
            for j in range ( N ) :
                if ( S [ j ] == ch ) :
                    count += 1
                if ( count == K ) :
                    index = j
            answer . append ( [ ch , index ] )
        flag = 0
        for i in range ( len ( answer ) ) :
            if ( answer [ i ] [ 1 ] > - 1 ) :
                flag = 1
                print ( answer [ i ] [ 0 ] , answer [ i ] [ 1 ] )
        if ( flag == 0 ) :
            print ( " - 1" )
if __name__ == ' _ _ main _ _ ' :
    S = " cbaabaacbcd "
    K = 2
    N = len ( S )
    maxSubstring ( S , K , N )

Index/key variables: i, j
Accumulator variables: answer, count
Iterator variables: i, j
Python program:
def greaterK ( n , k ) :
    index = 0
    p = [ 0 for i in range ( n + 2 ) ]
    x = n
    while ( x > 0 ) :
        p [ index ] = x % k
        x //= k
        index += 1
    idx = 0
    for i in range ( 0 , len ( p ) - 1 , 1 ) :
        if ( p [ i ] >= 2 ) :
            p [ i ] = 0
            p [ i + 1 ] += 1
            for j in range ( idx , i , 1 ) :
                p [ j ] = 0
            idx = i + 1
        if ( p [ i ] == k ) :
            p [ i ] = 0
            p [ i + 1 ] += 1
    j = len ( p ) - 1
    if ( p [ j ] >= 2 ) :
        p [ index ] = 1
        index += 1
    ans = 0
    i = len ( p ) - 1
    while ( i >= 0 ) :
        ans = ans * k + p [ i ]
        i -= 1
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    n = 29
    k = 7
    greaterK ( n , k )

Index/key variables: i, index, j
Accumulator variables: x
Iterator variables: i, j
Python program:
def canBeBalanced ( s , n ) :
    count = 0
    count_1 = 0
    for i in range ( n ) :
        if ( s [ i ] == ' ( ' ) :
            count += 1
        else :
            count -= 1
        count_1 = min ( count_1 , count )
    if ( count_1 >= - 1 and count == 0 ) :
        return True
    return False
s = " ( ) ) ( ) ( "
n = len ( s )
if ( canBeBalanced ( s , n ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def calculateDifference ( arr , n ) :
    max_val = max ( arr )
    prime = [ True for i in range ( max_val + 1 ) ]
    prime [ 0 ] = False
    prime [ 1 ] = False
    for p in range ( 2 , max_val + 1 ) :
        if p * p > max_val + 1 :
            break
        if ( prime [ p ] == True ) :
            for i in range ( 2 * p , max_val + 1 , p ) :
                prime [ i ] = False
    X1 = 1
    X2 = 1
    for i in range ( n ) :
        if ( prime [ arr [ i ] ] ) :
            X1 ^= arr [ i ]
        elif ( arr [ i ] != 1 ) :
            X2 ^= arr [ i ]
    return abs ( X1 - X2 )
arr = [ 1 , 3 , 5 , 10 , 15 , 7 ]
n = len ( arr )
print ( calculateDifference ( arr , n ) )

Index/key variables: i, p
Accumulator variables: X1, X2
Iterator variables: i, p
Python program:
CHILDREN = 26
MAX = 100
class trie :
    def __init__ ( self ) :
        self . child = [ None for i in range ( CHILDREN ) ]
        self . endOfWord = False
def createNode ( ) :
    temp = trie ( )
    return temp
def insertRecursively ( itr , str , i ) :
    if ( i < len ( str ) ) :
        index = ord ( str [ i ] ) - ord ( ' a ' )
        if ( itr . child [ index ] == None ) :
            itr . child [ index ] = createNode ( ) ;
        insertRecursively ( itr . child [ index ] , str , i + 1 ) ;
    else :
        itr . endOfWord = True ;
def insert ( itr , str ) :
    insertRecursively ( itr , str , 0 ) ;
def searchRecursively ( itr , str , i , len ) :
    if ( itr == None ) :
        return False
    if ( itr . endOfWord == True and i == len - 1 ) :
        return True
    index = ord ( str [ i ] ) - ord ( ' a ' )
    return searchRecursively ( itr . child [ index ] , str , i + 1 , len )
def search ( root , str ) :
    arr = [ ' ' for i in range ( len ( str ) + 1 ) ]
    arr = str
    if ( searchRecursively ( root , arr , 0 , len ( str ) + 1 ) ) :
        print ( " found " )
    else :
        print ( " not ▁ found " )
if __name__ == ' _ _ main _ _ ' :
    root = createNode ( ) ;
    insert ( root , " thier " ) ;
    insert ( root , " there " ) ;
    insert ( root , " answer " ) ;
    insert ( root , " any " ) ;
    search ( root , " anywhere " )
    search ( root , " answer " )

Index/key variables: i, index
Class/struct names: trie
Python program:
import math
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . next = None
def push ( head , item ) :
    temp = Node ( item ) ;
    temp . data = item ;
    temp . next = head ;
    head = temp ;
    return head ;
def countNode ( head ) :
    count = 0
    while ( head . next != None ) :
        ptr = head . next
        while ( ptr != None ) :
            if ( head . data == ptr . data ) :
                count = count + 1
                break
            ptr = ptr . next
        head = head . next
    return count
if __name__ == ' _ _ main _ _ ' :
    head = None ;
    head = push ( head , 5 )
    head = push ( head , 7 )
    head = push ( head , 5 )
    head = push ( head , 1 )
    head = push ( head , 7 )
    print ( countNode ( head ) )

Class/struct names: Node
Python program:
from sys import maxsize
def maxSumArray ( arr , n ) :
    sum1 = 0
    mp = { i : 0 for i in range ( 4 ) }
    for i in range ( n ) :
        sum1 += arr [ i ]
        mp [ arr [ i ] ] += 1
    minimum = maxsize
    for key , value in mp . items ( ) :
        if ( key == 0 ) :
            continue
        minimum = min ( minimum , value * key )
    return ( sum1 - minimum )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 1 , 3 , 3 , 2 , 2 , 1 , 1 , 1 ]
    n = len ( arr )
    print ( maxSumArray ( arr , n ) )

Index/key variables: i
Accumulator variables: sum1
Iterator variables: i, key, value
Python program:
MAX = 1001
prefix = [ [ 0 for i in range ( MAX ) ] for j in range ( MAX ) ]
ar = [ 0 for i in range ( MAX ) ]
def cal_prefix ( n , arr ) :
    for i in range ( n ) :
        ar [ i + 1 ] = arr [ i ]
    for i in range ( 1 , 1001 , 1 ) :
        for j in range ( n + 1 ) :
            prefix [ i ] [ j ] = 0
        for j in range ( 1 , n + 1 ) :
            if ar [ j ] <= i :
                k = 1
            else :
                k = 0
            prefix [ i ] [ j ] = prefix [ i ] [ j - 1 ] + k
def ksub ( l , r , n , k ) :
    lo = 1
    hi = 1000
    while ( lo + 1 < hi ) :
        mid = int ( ( lo + hi ) / 2 )
        if ( prefix [ mid ] [ r ] - prefix [ mid ] [ l - 1 ] >= k ) :
            hi = mid
        else :
            lo = mid + 1
    if ( prefix [ lo ] [ r ] - prefix [ lo ] [ l - 1 ] >= k ) :
        hi = lo
    return hi
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 4 , 2 , 3 , 5 , 7 , 6 ]
    n = len ( arr )
    k = 4
    cal_prefix ( n , arr )
    queries = [ [ 1 , n , 1 ] , [ 2 , n - 2 , 2 ] , [ 3 , n - 1 , 3 ] ]
    q = len ( queries )
    for i in range ( q ) :
        print ( ksub ( queries [ i ] [ 0 ] , queries [ i ] [ 1 ] , n , queries [ i ] [ 2 ] ) )

Index/key variables: i, j, lo, mid, r
Iterator variables: i, j
Python program:
class DisjointUnionSets :
    def __init__ ( self , n ) :
        self . rank = [ 0 ] * n
        self . parent = [ 0 ] * n
        self . n = n
        self . makeSet ( )
    def makeSet ( self ) :
        for i in range ( self . n ) :
            self . parent [ i ] = i
    def find ( self , x ) :
        if ( self . parent [ x ] != x ) :
            return self . find ( self . parent [ x ] )
        return x
    def Union ( self , x , y ) :
        xRoot = self . find ( x )
        yRoot = self . find ( y )
        if xRoot == yRoot :
            return
        if self . rank [ xRoot ] < self . rank [ yRoot ] :
            parent [ xRoot ] = yRoot
        elif self . rank [ yRoot ] < self . rank [ xRoot ] :
            self . parent [ yRoot ] = xRoot
        else :
            self . parent [ yRoot ] = xRoot
            self . rank [ xRoot ] = self . rank [ xRoot ] + 1
def countIslands ( a ) :
    n = len ( a )
    m = len ( a [ 0 ] )
    dus = DisjointUnionSets ( n * m )
    for j in range ( 0 , n ) :
        for k in range ( 0 , m ) :
            if a [ j ] [ k ] == 0 :
                continue
            if j + 1 < n and a [ j + 1 ] [ k ] == 1 :
                dus . Union ( j * ( m ) + k , ( j + 1 ) * ( m ) + k )
            if j - 1 >= 0 and a [ j - 1 ] [ k ] == 1 :
                dus . Union ( j * ( m ) + k , ( j - 1 ) * ( m ) + k )
            if k + 1 < m and a [ j ] [ k + 1 ] == 1 :
                dus . Union ( j * ( m ) + k , ( j ) * ( m ) + k + 1 )
            if k - 1 >= 0 and a [ j ] [ k - 1 ] == 1 :
                dus . Union ( j * ( m ) + k , ( j ) * ( m ) + k - 1 )
            if ( j + 1 < n and k + 1 < m and a [ j + 1 ] [ k + 1 ] == 1 ) :
                dus . Union ( j * ( m ) + k , ( j + 1 ) * ( m ) + k + 1 )
            if ( j + 1 < n and k - 1 >= 0 and a [ j + 1 ] [ k - 1 ] == 1 ) :
                dus . Union ( j * m + k , ( j + 1 ) * ( m ) + k - 1 )
            if ( j - 1 >= 0 and k + 1 < m and a [ j - 1 ] [ k + 1 ] == 1 ) :
                dus . Union ( j * m + k , ( j - 1 ) * m + k + 1 )
            if ( j - 1 >= 0 and k - 1 >= 0 and a [ j - 1 ] [ k - 1 ] == 1 ) :
                dus . Union ( j * m + k , ( j - 1 ) * m + k - 1 )
    c = [ 0 ] * ( n * m )
    numberOfIslands = 0
    for j in range ( n ) :
        for k in range ( n ) :
            if a [ j ] [ k ] == 1 :
                x = dus . find ( j * m + k )
                if c [ x ] == 0 :
                    numberOfIslands += 1
                    c [ x ] += 1
                else :
                    c [ x ] += 1
    return numberOfIslands
a = [ [ 1 , 1 , 0 , 0 , 0 ] , [ 0 , 1 , 0 , 0 , 1 ] , [ 1 , 0 , 0 , 1 , 1 ] , [ 0 , 0 , 0 , 0 , 0 ] , [ 1 , 0 , 1 , 0 , 1 ] ]
print ( " Number ▁ of ▁ Islands ▁ is : " , countIslands ( a ) )

Index/key variables: i, j, k, x, xRoot, yRoot
Accumulator variables: numberOfIslands
Iterator variables: i, j, k
Class/struct names: DisjointUnionSets
Python program:
import math
def squareSum ( N ) :
    sum = ( N * ( N + 1 ) * ( 2 * N + 1 ) ) // 6
    return sum
def findMaxN ( X ) :
    N = ( int ) ( math . sqrt ( X ) )
    for i in range ( 1 , N + 1 ) :
        if ( squareSum ( i ) > X ) :
            return i - 1
    return - 1
X = 25
print ( findMaxN ( X ) )

Iterator variables: i
Python program:
import sys
def max_min ( a , n ) :
    if ( n <= 1 ) :
        return sys . maxsize
    f_min = a [ 0 ]
    s_min = sys . maxsize
    f_max = a [ 0 ]
    s_max = - ( sys . maxsize - 1 )
    for i in range ( n ) :
        if ( a [ i ] <= f_min ) :
            s_min = f_min
            f_min = a [ i ]
        elif ( a [ i ] < s_min ) :
            s_min = a [ i ]
        if ( a [ i ] >= f_max ) :
            s_max = f_max
            f_max = a [ i ]
        elif ( a [ i ] > s_max ) :
            s_max = a [ i ]
    return min ( ( f_max - s_min ) , ( s_max - f_min ) )
if __name__ == " _ _ main _ _ " :
    a = [ 1 , 3 , 3 , 7 ]
    n = len ( a )
    print ( max_min ( a , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def minimal ( a , n ) :
    lo , hi = 0 , n - 1
    while lo < hi :
        mid = ( lo + hi ) // 2
        if a [ mid ] < a [ mid + 1 ] :
            hi = mid
        else :
            lo = mid + 1
        return lo
        return lo
a = [ 8 , 5 , 4 , 3 , 4 , 10 ]
n = len ( a )
ind = minimal ( a , n )
print ( a [ ind ] )

Index/key variables: ind, mid
Python program:
def findIndices ( arr , n ) :
    leftMin , rightMin = 0 , 0
    leftMax , rightMax = 0 , 0
    min_element = arr [ 0 ]
    max_element = arr [ 0 ]
    for i in range ( n ) :
        if ( arr [ i ] < min_element ) :
            leftMin = rightMin = i
            min_element = arr [ i ]
        elif ( arr [ i ] == min_element ) :
            rightMin = i
        if ( arr [ i ] > max_element ) :
            leftMax = rightMax = i
            max_element = arr [ i ]
        elif ( arr [ i ] == max_element ) :
            rightMax = i
    print ( " Minimum ▁ left ▁ : ▁ " , leftMin )
    print ( " Minimum ▁ right ▁ : ▁ " , rightMin )
    print ( " Maximum ▁ left ▁ : ▁ " , leftMax )
    print ( " Maximum ▁ right ▁ : ▁ " , rightMax )
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 1 , 1 , 2 , 1 , 5 , 6 , 5 ]
    n = len ( arr )
    findIndices ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
def diagonalsMinMax ( mat ) :
    n = len ( mat )
    if ( n == 0 ) :
        return
    principalMin = mat [ 0 ] [ 0 ]
    principalMax = mat [ 0 ] [ 0 ]
    secondaryMin = mat [ 0 ] [ n - 1 ]
    secondaryMax = mat [ 0 ] [ n - 1 ]
    for i in range ( 1 , n ) :
        for j in range ( 1 , n ) :
            if ( i == j ) :
                if ( mat [ i ] [ j ] < principalMin ) :
                    principalMin = mat [ i ] [ j ]
                if ( mat [ i ] [ j ] > principalMax ) :
                    principalMax = mat [ i ] [ j ]
            if ( ( i + j ) == ( n - 1 ) ) :
                if ( mat [ i ] [ j ] < secondaryMin ) :
                    secondaryMin = mat [ i ] [ j ]
                if ( mat [ i ] [ j ] > secondaryMax ) :
                    secondaryMax = mat [ i ] [ j ]
    print ( " Principal ▁ Diagonal ▁ Smallest ▁ Element : ▁ " , principalMin )
    print ( " Principal ▁ Diagonal ▁ Greatest ▁ Element ▁ : ▁ " , principalMax )
    print ( " Secondary ▁ Diagonal ▁ Smallest ▁ Element : ▁ " , secondaryMin )
    print ( " Secondary ▁ Diagonal ▁ Greatest ▁ Element : ▁ " , secondaryMax )
matrix = [ [ 1 , 2 , 3 , 4 , - 10 ] , [ 5 , 6 , 7 , 8 , 6 ] , [ 1 , 2 , 11 , 3 , 4 ] , [ 5 , 6 , 70 , 5 , 8 ] , [ 4 , 9 , 7 , 1 , - 5 ] ]
diagonalsMinMax ( matrix )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def indexedSequentialSearch ( arr , n , k ) :
    elements = [ 0 ] * 20
    indices = [ 0 ] * 20
    j , ind , start , end = 0 , 0 , 0 , 0
    set_flag = 0
    for i in range ( 0 , n , 3 ) :
        elements [ ind ] = arr [ i ]
        indices [ ind ] = i
        ind += 1
    if k < elements [ 0 ] :
        print ( " Not ▁ found " )
        exit ( 0 )
    else :
        for i in range ( 1 , ind + 1 ) :
            if k <= elements [ i ] :
                start = indices [ i - 1 ]
                end = indices [ i ]
                set_flag = 1
                break
    if set_flag == 0 :
        start = indices [ i - 1 ]
        end = n
    for i in range ( start , end + 1 ) :
        if k == arr [ i ] :
            j = 1
            break
    if j == 1 :
        print ( " Found ▁ at ▁ index " , i )
    else :
        print ( " Not ▁ found " )
if __name__ == " _ _ main _ _ " :
    arr = [ 6 , 7 , 8 , 9 , 10 ]
    n = len ( arr )
    k = 8
    indexedSequentialSearch ( arr , n , k )

Index/key variables: i, ind
Iterator variables: i
Python program:
from bisect import bisect as upper_bound
def getCount ( v , n ) :
    v = sorted ( v )
    cnt = 0
    for i in range ( n ) :
        tmp = n - 1 - upper_bound ( v , v [ i ] - 1 )
        if ( tmp == v [ i ] ) :
            cnt += 1
    return cnt
n = 4
v = [ ]
v . append ( 1 )
v . append ( 2 )
v . append ( 3 )
v . append ( 4 )
print ( getCount ( v , n ) )

Index/key variables: i
Accumulator variables: cnt
Iterator variables: i
Python program:
def countSegments ( a , n , x ) :
    flag = False
    count = 0
    for i in range ( n ) :
        if ( a [ i ] > x ) :
            flag = True
        else :
            if ( flag ) :
                count += 1
            flag = False
    if ( flag ) :
        count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    a = [ 8 , 25 , 10 , 19 , 19 , 18 , 20 , 11 , 18 ]
    n = len ( a )
    x = 13
    print ( countSegments ( a , n , x ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Boolean variables: flag
Python program:
def findElements ( arr , n , l , r ) :
    mp = { i : 0 for i in range ( len ( arr ) ) }
    for i in range ( n ) :
        mp [ arr [ i ] ] += 1
    for i in range ( n ) :
        if ( l <= mp [ arr [ i ] ] and mp [ arr [ i ] <= r ] ) :
            print ( arr [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 3 , 3 , 2 , 2 , 5 ]
    n = len ( arr )
    l = 2
    r = 3
    findElements ( arr , n , l , r )

Index/key variables: i
Iterator variables: i
Python program:
def count_triples ( n , k ) :
    count , i , j , l = 0 , 0 , 0 , 0
    for i in range ( 1 , n + 1 ) :
        for j in range ( 1 , n + 1 ) :
            for l in range ( 1 , n + 1 ) :
                if ( ( i + j ) % k == 0 and ( i + l ) % k == 0 and ( j + l ) % k == 0 ) :
                    count += 1
    return count
if __name__ == " _ _ main _ _ " :
    n , k = 3 , 2
    ans = count_triples ( n , k )
    print ( ans )

Accumulator variables: count
Iterator variables: i, j, l
Python program:
def kthSmallestLargest ( arr , n , k ) :
    max_val = arr [ 0 ]
    for i in range ( len ( arr ) ) :
        if ( arr [ i ] > max_val ) :
            max_val = arr [ i ]
    hash = [ 0 for i in range ( max_val + 1 ) ]
    for i in range ( n ) :
        hash [ arr [ i ] ] += 1
    count = 0
    for i in range ( max_val + 1 ) :
        while ( hash [ i ] > 0 ) :
            count += 1
            if ( count == k ) :
                return i
            hash [ i ] -= 1
    return - 1
if __name__ == ' _ _ main _ _ ' :
    arr = [ 11 , 6 , 2 , 9 , 4 , 3 , 16 ]
    n = len ( arr )
    k = 3
    print ( " kth ▁ smallest ▁ number ▁ is : " , kthSmallestLargest ( arr , n , k ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
import math
def bsearch ( A , key_to_search ) :
    n = len ( A )
    lg = int ( math . log2 ( n - 1 ) ) + 1 ;
    pos = 0
    for i in range ( lg - 1 , - 1 , - 1 ) :
        if ( A [ pos ] == key_to_search ) :
            return pos
        new_pos = pos | ( 1 << i )
        if ( ( new_pos < n ) and ( A [ new_pos ] <= key_to_search ) ) :
            pos = new_pos
    return ( pos if ( A [ pos ] == key_to_search ) else - 1 )
if __name__ == " _ _ main _ _ " :
    A = [ - 2 , 10 , 100 , 250 , 32315 ]
    print ( bsearch ( A , 10 ) )

Index/key variables: new_pos, pos
Iterator variables: i
Python program:
from bisect import bisect_left as lower_bound
def answerQueries ( a : list , n , queries : list , q ) :
    v = list ( )
    mpp = dict ( )
    for i in range ( n ) :
        v . append ( a [ i ] [ 0 ] )
        mpp [ a [ i ] [ 0 ] ] = 1
        v . append ( a [ i ] [ 1 ] )
        mpp [ a [ i ] [ 1 ] ] = 2
    v . sort ( )
    for i in range ( q ) :
        num = queries [ i ]
        ind = lower_bound ( v , num )
        if v [ ind ] == num :
            print ( " Yes " )
        else :
            if mpp [ v [ ind ] ] == 2 :
                print ( " Yes " )
            else :
                print ( " No " )
if __name__ == " _ _ main _ _ " :
    a = [ [ 5 , 6 ] , [ 1 , 3 ] , [ 8 , 10 ] ]
    n = 3
    queries = [ 2 , 3 , 4 , 7 ]
    q = len ( queries )
    answerQueries ( a , n , queries , q )

Index/key variables: i, ind
Accumulator variables: v
Iterator variables: i
Python program:
def findmedian ( a , n1 , b , n2 ) :
    j = 0
    m1 = - 1
    m2 = - 1
    for k in range ( ( ( n1 + n2 ) // 2 ) + 1 ) :
        if ( i < n1 and j < n2 ) :
            if ( a [ i ] < b [ j ] ) :
                m2 = m1
                m1 = a [ i ]
                i += 1
            else :
                m2 = m1
                m1 = b [ j ]
                j += 1
        elif ( i == n1 ) :
            m2 = m1
            m1 = b [ j ]
            j += 1
        elif ( j == n2 ) :
            m2 = m1
            m1 = a [ i ]
            i += 1
    if ( ( n1 + n2 ) % 2 == 0 ) :
        return ( m1 + m2 ) * 1.0 / 2
    return m1
if __name__ == " _ _ main _ _ " :
    a = [ 1 , 12 , 15 , 26 , 38 ]
    b = [ 2 , 13 , 24 ]
    n1 = len ( a )
    n2 = len ( b )
    print ( findmedian ( a , n1 , b , n2 ) )

Index/key variables: i, j
Iterator variables: k
Python program:
def printNSE ( arr ) :
    for i in range ( 0 , len ( arr ) , 1 ) :
        next = - 1
        for j in range ( i + 1 , len ( arr ) , 1 ) :
            if arr [ i ] > arr [ j ] :
                next = arr [ j ]
                break
        print ( str ( arr [ i ] ) + " ▁ - - ▁ " + str ( next ) )
arr = [ 11 , 13 , 21 , 3 ]
printNSE ( arr )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def longestSubarray ( input , length ) :
    prev = - 1
    prevCount = 0
    currentCount = 1
    longest = 1
    current = input [ 0 ]
    for i in range ( 1 , length ) :
        next = input [ i ]
        if next == current :
            currentCount += 1
        elif next == prev :
            prevCount += currentCount
            prev = current
            current = next
            currentCount = 1
        else :
            longest = max ( longest , currentCount + prevCount )
            prev = current
            prevCount = currentCount
            current = next
            currentCount = 1
    return max ( longest , currentCount + prevCount )
if __name__ == " _ _ main _ _ " :
    input = [ 5 , 5 , 6 , 7 , 6 ]
    n = len ( input )
    print ( longestSubarray ( input , n ) )

Index/key variables: i
Accumulator variables: currentCount, prevCount
Iterator variables: i
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def reverseTreePathUtil ( root , data , temp , level , nextpos ) :
    if ( root == None ) :
        return None , temp , nextpos ;
    if ( data == root . data ) :
        temp [ level ] = root . data ;
        root . data = temp [ nextpos ] ;
        nextpos += 1
        return root , temp , nextpos ;
    temp [ level ] = root . data ;
    right = None
    left , temp , nextpos = reverseTreePathUtil ( root . left , data , temp , level + 1 , nextpos ) ;
    if ( left == None ) :
        right , temp , nextpos = reverseTreePathUtil ( root . right , data , temp , level + 1 , nextpos ) ;
    if ( left or right ) :
        root . data = temp [ nextpos ] ;
        nextpos += 1
        return ( left if left != None else right ) , temp , nextpos ;
    return None , temp , nextpos ;
def reverseTreePath ( root , data ) :
    temp = dict ( )
    nextpos = 0 ;
    reverseTreePathUtil ( root , data , temp , 0 , nextpos ) ;
def inorder ( root ) :
    if ( root != None ) :
        inorder ( root . left ) ;
        print ( root . data , end = ' ▁ ' )
        inorder ( root . right ) ;
def newNode ( data ) :
    temp = Node ( data )
    return temp ;
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 7 ) ;
    root . left = newNode ( 6 ) ;
    root . right = newNode ( 5 ) ;
    root . left . left = newNode ( 4 ) ;
    root . left . right = newNode ( 3 ) ;
    root . right . left = newNode ( 2 ) ;
    root . right . right = newNode ( 1 ) ;
    data = 4 ;
    reverseTreePath ( root , data ) ;
    inorder ( root ) ;

Index/key variables: level, nextpos
Class/struct names: Node