dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
from collections import deque
class new_Node :
    def __init__ ( self , key ) :
        self . data = key
        self . left = self . right = None
def deepestNode ( root ) :
    node = None
    if root == None :
        return 0
    q = deque ( )
    q . append ( root )
    while len ( q ) != 0 :
        node = q . popleft ( )
        if node . left is not None :
            q . append ( node . left )
        if node . right is not None :
            q . append ( node . right )
    return node . data
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 = deepestNode ( root )
    print ( levels )

Accumulator variables: q
Class/struct names: new_Node
Python program:
def nameRank ( names , marks , updates , n ) :
    x = [ [ 0 for j in range ( 3 ) ] for i in range ( n ) ]
    for i in range ( n ) :
        x [ i ] [ 0 ] = names [ i ]
        x [ i ] [ 1 ] = marks [ i ] + updates [ i ]
        x [ i ] [ 2 ] = i + 1
    highest = x [ 0 ]
    for j in range ( 1 , n ) :
        if ( x [ j ] [ 1 ] >= highest [ 1 ] ) :
            highest = x [ j ]
    print ( " Name : ▁ " , highest [ 0 ] , " , ▁ Jump : ▁ " , abs ( highest [ 2 ] - 1 ) , sep = " " )
names = [ " sam " , " ram " , " geek " ]
marks = [ 80 , 79 , 75 ]
updates = [ 0 , 5 , - 9 ]
n = len ( marks )
nameRank ( names , marks , updates , n )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def countDigits ( n ) :
    count = 0
    while ( n > 0 ) :
        count += 1
        n //= 10
    return count
def getDistinct ( d , count ) :
    num = 0
    count = pow ( 10 , count - 1 )
    while ( count > 0 ) :
        num += ( count * d )
        count //= 10
    return num
def findCount ( L , R ) :
    count = 0
    countDigitsL = countDigits ( L )
    countDigitsR = countDigits ( R )
    firstDigitL = ( L // pow ( 10 , countDigitsL - 1 ) )
    firstDigitR = ( R // pow ( 10 , countDigitsR - 1 ) )
    if ( countDigitsL < countDigitsR ) :
        count += ( 9 * ( countDigitsR - countDigitsL - 1 ) )
        if ( getDistinct ( firstDigitL , countDigitsL ) >= L ) :
            count += ( 9 - firstDigitL + 1 )
        else :
            count += ( 9 - firstDigitL )
        if ( getDistinct ( firstDigitR , countDigitsR ) <= R ) :
            count += firstDigitR
        else :
            count += ( firstDigitR - 1 )
    else :
        if ( getDistinct ( firstDigitL , countDigitsL ) >= L ) :
            count += ( 9 - firstDigitL + 1 )
        else :
            count += ( 9 - firstDigitL )
        if ( getDistinct ( firstDigitR , countDigitsR ) <= R ) :
            count -= ( 9 - firstDigitR )
        else :
            count -= ( 9 - firstDigitR + 1 )
    return count
L = 10
R = 50
print ( findCount ( L , R ) )

Accumulator variables: count, n, num
Python program:
N = 4
M = 4
def isPairWithDiff ( mat , k ) :
    s = set ( )
    for i in range ( N ) :
        for j in range ( M ) :
            if mat [ i ] [ j ] > k :
                m = mat [ i ] [ j ] - k
                if m in s :
                    return True
            else :
                m = k - mat [ i ] [ j ]
                if m in s :
                    return True
            s . add ( mat [ i ] [ j ] )
    return False
n , m = 4 , 4
mat = [ [ 5 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] , [ 13 , 14 , 15 , 100 ] ]
k = 85
if isPairWithDiff ( mat , k ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i, j
Accumulator variables: s
Iterator variables: i, j
Python program:
def printNSE ( arr , n ) :
    s = [ ]
    mp = { }
    s . append ( arr [ 0 ] )
    for i in range ( 1 , n ) :
        if ( len ( s ) == 0 ) :
            s . append ( arr [ i ] )
            continue
        while ( len ( s ) != 0 and s [ - 1 ] > arr [ i ] ) :
            mp [ s [ - 1 ] ] = arr [ i ]
            s . pop ( )
        s . append ( arr [ i ] )
    while ( len ( s ) != 0 ) :
        mp [ s [ - 1 ] ] = - 1
        s . pop ( )
    for i in range ( n ) :
        print ( arr [ i ] , " - - - > " , mp [ arr [ i ] ] )
arr = [ 11 , 13 , 21 , 3 ]
n = len ( arr )
printNSE ( arr , n )
s

Index/key variables: i
Accumulator variables: s
Iterator variables: i
Python program:
class newnode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def getDeepestLeftLeafNode ( root ) :
    if ( not root ) :
        return None
    q = [ ]
    q . append ( root )
    result = None
    while ( len ( q ) ) :
        temp = q [ 0 ]
        q . pop ( 0 )
        if ( temp . left ) :
            q . append ( temp . left )
            if ( not temp . left . left and not temp . left . right ) :
                result = temp . left
        if ( temp . right ) :
            q . append ( temp . right )
    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 )
    result = getDeepestLeftLeafNode ( root )
    if result :
        print ( " Deepest ▁ Left ▁ Leaf ▁ Node ▁ : : " , result . data )
    else :
        print ( " No ▁ result , ▁ Left ▁ leaf ▁ not ▁ found " )

Accumulator variables: q
Class/struct names: newnode
Python program:
def ElementsCalculationFunc ( pre , maxx , x , k , n ) :
    i = 0
    j = x
    while j <= n :
        if ( x * maxx [ j ] - ( pre [ j ] - pre [ i ] ) <= k ) :
            return True
        i += 1
        j += 1
    return False
def MaxNumberOfElements ( a , n , k ) :
    a . sort ( )
    for i in range ( n + 1 ) :
        pre [ i ] = 0
        maxx [ i ] = 0
    for i in range ( 1 , n + 1 ) :
        pre [ i ] = pre [ i - 1 ] + a [ i - 1 ]
        maxx [ i ] = max ( maxx [ i - 1 ] , a [ i - 1 ] )
    l = 1
    r = n
    while ( l < r ) :
        mid = ( l + r ) // 2
        if ( ElementsCalculationFunc ( pre , maxx , mid - 1 , k , n ) ) :
            ans = mid
            l = mid + 1
        else :
            r = mid - 1
    print ( ans )
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 4 , 9 ]
    n = len ( arr )
    k = 3
    MaxNumberOfElements ( arr , n , k )

Index/key variables: i, j
Iterator variables: i
Python program:
MAX_STR_LEN = 1000 ;
P = [ [ 0 for x in range ( MAX_STR_LEN ) ] for y in range ( MAX_STR_LEN ) ] ;
for i in range ( 0 , MAX_STR_LEN ) :
    for j in range ( 0 , MAX_STR_LEN ) :
        P [ i ] [ j ] = False ;
Kpal = [ 0 ] * MAX_STR_LEN ;
def checkSubStrPal ( str , n ) :
    global P , Kpal , MAX_STR_LEN ;
    for i in range ( 0 , MAX_STR_LEN ) :
        for j in range ( 0 , MAX_STR_LEN ) :
            P [ i ] [ j ] = False ;
        Kpal [ i ] = 0 ;
    for i in range ( 0 , n ) :
        P [ i ] [ i ] = True ;
    for i in range ( 0 , n - 1 ) :
        if ( str [ i ] == str [ i + 1 ] ) :
            P [ i ] [ i + 1 ] = True ;
    for gap in range ( 2 , n ) :
        for i in range ( 0 , n - gap ) :
            j = gap + i ;
            if ( str [ i ] == str [ j ] and P [ i + 1 ] [ j - 1 ] ) :
                P [ i ] [ j ] = True ;
def countKPalindromes ( i , j , k ) :
    global Kpal , P ;
    if ( i == j ) :
        Kpal [ k ] = Kpal [ k ] + 1 ;
        return ;
    if ( P [ i ] [ j ] == False ) :
        return ;
    Kpal [ k ] = Kpal [ k ] + 1 ;
    mid = int ( ( i + j ) / 2 ) ;
    if ( ( j - i + 1 ) % 2 == 1 ) :
        mid = mid - 1 ;
    countKPalindromes ( i , mid , k + 1 ) ;
def printKPalindromes ( s ) :
    global P , Kpal , MAX_STR_LEN ;
    n = len ( s ) ;
    checkSubStrPal ( s , n ) ;
    for i in range ( 0 , n ) :
        for j in range ( 0 , n - i ) :
            countKPalindromes ( j , j + i , 1 ) ;
    for i in range ( 1 , n + 1 ) :
        print ( Kpal [ i ] , end = " ▁ " ) ;
    print ( ) ;
s = " abacaba " ;
printKPalindromes ( s ) ;

Index/key variables: i, j, k
Iterator variables: gap, i, j
Python program:
class Interval :
    def __init__ ( self , s , e ) :
        self . s = s
        self . e = e
def kthSmallestNum ( merged : list , k : int ) -> int :
    n = len ( merged )
    for j in range ( n ) :
        if k <= abs ( merged [ j ] . e - merged [ j ] . s + 1 ) :
            return merged [ j ] . s + k - 1
        k = k - abs ( merged [ j ] . e - merged [ j ] . s + 1 )
    if k :
        return - 1
def mergeIntervals ( merged : list , arr : list , n : int ) :
    arr . sort ( key = lambda a : a . s )
    merged . append ( arr [ 0 ] )
    for i in range ( 1 , n ) :
        prev = merged [ - 1 ]
        curr = arr [ i ]
        if curr . s >= prev . s and curr . s <= prev . e and curr . e > prev . e :
            merged [ - 1 ] . e = curr . e
        else :
            if curr . s > prev . e :
                merged . append ( curr )
if __name__ == " _ _ main _ _ " :
    arr = [ Interval ( 2 , 6 ) , Interval ( 4 , 7 ) ]
    n = len ( arr )
    query = [ 5 , 8 ]
    q = len ( query )
    merged = [ ]
    mergeIntervals ( merged , arr , n )
    for i in range ( q ) :
        print ( kthSmallestNum ( merged , query [ i ] ) )

Index/key variables: i, j
Accumulator variables: merged
Iterator variables: i, j
Class/struct names: Interval
Python program:
def countCountries ( ans , N ) :
    total_countries = 0
    i = 0
    invalid = 0
    while ( i < N ) :
        curr_size = ans [ i ]
        num = ans [ i ]
        while ( num > 0 ) :
            if ( ans [ i ] != curr_size ) :
                print ( " Invalid ▁ Answer " )
                return ;
            else :
                num = num - 1
            i = i + 1
        total_countries = total_countries + 1 ;
    print ( " There ▁ are ▁ " , total_countries , " ▁ distinct ▁ companies ▁ in ▁ the ▁ group . " )
ans = [ 1 , 1 , 2 , 2 , 4 , 4 , 4 , 4 ] ;
n = len ( ans ) ;
countCountries ( ans , n ) ;

Index/key variables: i
Python program:
def check_elements ( arr , n , A , B ) :
    rangeV = B - A
    for i in range ( 0 , n ) :
        if ( abs ( arr [ i ] ) >= A and abs ( arr [ i ] ) <= B ) :
            z = abs ( arr [ i ] ) - A
            if ( arr [ z ] > 0 ) :
                arr [ z ] = arr [ z ] * - 1
    count = 0
    for i in range ( 0 , rangeV + 1 ) :
        if i >= n :
            break
        if ( arr [ i ] > 0 ) :
            return False
        else :
            count = count + 1
    if ( count != ( rangeV + 1 ) ) :
        return False
    return True
arr = [ 1 , 4 , 5 , 2 , 7 , 8 , 3 ]
n = len ( arr )
A = 2
B = 5
if ( check_elements ( arr , n , A , B ) ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i, z
Iterator variables: i
Python program:
def isPossible ( arr , n , m , curr_min ) :
    studentsRequired = 1
    curr_sum = 0
    for i in range ( n ) :
        if ( arr [ i ] > curr_min ) :
            return False
        if ( curr_sum + arr [ i ] > curr_min ) :
            studentsRequired += 1
            curr_sum = arr [ i ]
            if ( studentsRequired > m ) :
                return False
        else :
            curr_sum += arr [ i ]
    return True
def findPages ( arr , n , m ) :
    sum = 0
    if ( n < m ) :
        return - 1
    for i in range ( n ) :
        sum += arr [ i ]
    start , end = 0 , sum
    result = 10 ** 9
    while ( start <= end ) :
        mid = ( start + end ) // 2
        if ( isPossible ( arr , n , m , mid ) ) :
            result = mid
            end = mid - 1
        else :
            start = mid + 1
    return result
arr = [ 12 , 34 , 67 , 90 ]
n = len ( arr )
print ( " Minimum ▁ number ▁ of ▁ pages ▁ = ▁ " , findPages ( arr , n , m ) )

Index/key variables: i
Accumulator variables: curr_sum, studentsRequired, sum
Iterator variables: i
Python program:
def maxFreqElements ( arr , N , K ) :
    mp = { }
    for i in range ( N ) :
        if arr [ i ] in mp :
            mp [ arr [ i ] ] += 1
        else :
            mp [ arr [ i ] ] = 1
    while ( K > 0 ) :
        Max = 0
        for i in mp :
            if ( mp [ i ] > Max ) :
                Max = mp [ i ]
                element = i
        print ( element , end = " ▁ " )
        if element in mp :
            mp [ element ] -= 1
        else :
            mp [ element ] = - 1
        K -= 1
arr = [ 1 , 3 , 2 , 1 , 4 , 1 ]
N = len ( arr )
K = 2
maxFreqElements ( arr , N , K )

Index/key variables: element, i
Accumulator variables: K
Iterator variables: i
Python program:
def maxDiffLargSmallOper ( arr , N , K ) :
    maxDiff = 0 ;
    arr . sort ( reverse = True ) ;
    for i in range ( min ( K + 1 , N ) ) :
        maxDiff += arr [ i ] ;
    return maxDiff ;
if __name__ == " _ _ main _ _ " :
    arr = [ 7 , 7 , 7 , 7 ] ;
    N = len ( arr )
    K = 1 ;
    print ( maxDiffLargSmallOper ( arr , N , K ) ) ;

Index/key variables: i
Accumulator variables: maxDiff
Iterator variables: i
Python program:
def minCost ( s , R , C , N ) :
    ch = list ( s )
    pq = [ ]
    flip = 0
    cost = 0
    for i in range ( N ) :
        while ( len ( pq ) > 0 and pq [ 0 ] < i ) :
            pq . pop ( 0 ) ;
            flip -= 1
        cn = ord ( ch [ i ] ) - ord ( '0' )
        if ( flip % 2 == 1 ) :
            cn = 1 - cn
        if ( cn == 1 ) :
            flip += 1
            cost += C [ i ]
            pq . append ( R [ i ] )
    return cost
N = 4
s = "1010"
R = [ 1 , 2 , 2 , 3 ]
C = [ 3 , 1 , 2 , 3 ]
print ( minCost ( s , R , C , N ) )

Index/key variables: i
Accumulator variables: cost, flip, pq
Iterator variables: i
Python program:
def MaxDist ( A , N ) :
    V = [ 0 for i in range ( N ) ]
    V1 = [ 0 for i in range ( N ) ]
    for i in range ( N ) :
        V [ i ] = A [ i ] [ 0 ] + A [ i ] [ 1 ]
        V1 [ i ] = A [ i ] [ 0 ] - A [ i ] [ 1 ]
    V . sort ( )
    V1 . sort ( )
    maximum = max ( V [ - 1 ] - V [ 0 ] , V1 [ - 1 ] - V1 [ 0 ] )
    print ( maximum )
if __name__ == " _ _ main _ _ " :
    N = 3
    A = [ [ 1 , 2 ] , [ 2 , 3 ] , [ 3 , 4 ] ]
    MaxDist ( A , N )

Index/key variables: i
Iterator variables: i
Python program:
from math import sqrt
def dist ( p1 , p2 ) :
    x0 = p1 [ 0 ] - p2 [ 0 ]
    y0 = p1 [ 1 ] - p2 [ 1 ]
    return x0 * x0 + y0 * y0
def maxDist ( p ) :
    n = len ( p )
    maxm = 0
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            maxm = max ( maxm , dist ( p [ i ] , p [ j ] ) )
    return sqrt ( maxm )
if __name__ == ' _ _ main _ _ ' :
    n = 5
    p = [ ]
    p . append ( [ 4 , 0 ] )
    p . append ( [ 0 , 2 ] )
    p . append ( [ - 1 , - 7 ] )
    p . append ( [ 1 , 10 ] )
    p . append ( [ 2 , - 3 ] )
    print ( maxDist ( p ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def printArr ( arr , n ) :
    arr . sort ( )
    if ( arr [ 0 ] == arr [ n - 1 ] ) :
        print ( " No " )
    else :
        print ( " Yes " )
        for i in range ( n ) :
            print ( arr [ i ] , end = " ▁ " )
        print ( )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 2 , 1 , 3 , 1 ]
    N = len ( arr )
    printArr ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
def maximumSum ( a , b , k , n ) :
    a . sort ( )
    b . sort ( )
    i = 0
    j = n - 1
    while i < k :
        if ( a [ i ] < b [ j ] ) :
            a [ i ] , b [ j ] = b [ j ] , a [ i ]
        else :
            break
        i += 1
        j -= 1
    sum = 0
    for i in range ( n ) :
        sum += a [ i ]
    print ( sum )
if __name__ == " _ _ main _ _ " :
    K = 1
    A = [ 2 , 3 , 4 ]
    B = [ 6 , 8 , 5 ]
    N = len ( A )
    maximumSum ( A , B , K , N )

Index/key variables: i, j
Accumulator variables: sum
Iterator variables: i
Python program:
def max_dist_ele ( arr , n ) :
    arr . sort ( )
    ans = 0
    prev = 0
    for i in range ( n ) :
        if prev < ( arr [ i ] - 1 ) :
            ans += 1 ;
            prev = arr [ i ] - 1
        elif prev < ( arr [ i ] ) :
            ans += 1
            prev = arr [ i ]
        elif prev < ( arr [ i ] + 1 ) :
            ans += 1
            prev = arr [ i ] + 1
    return ans
arr = [ 1 , 1 , 1 , 8 , 8 , 8 , 9 , 9 ]
n = len ( arr )
print ( max_dist_ele ( arr , n ) )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def CheckSort ( arr , k , n ) :
    sortarr = sorted ( arr )
    if ( k == 1 ) :
        print ( " yes " )
    else :
        for i in range ( 0 , n ) :
            flag = 0
            for j in range ( i , n , k ) :
                if ( sortarr [ i ] == arr [ j ] ) :
                    arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]
                    flag = 1
                    break
                if ( j + k >= n ) :
                    break
            if ( flag == 0 ) :
                break
        if ( flag == 0 ) :
            print ( " Not ▁ possible ▁ to ▁ sort " )
        else :
            print ( " Possible ▁ to ▁ sort " )
if __name__ == " _ _ main _ _ " :
    k = 3
    arr = [ 1 , 5 , 6 , 9 , 2 , 3 , 5 , 9 ]
    n = len ( arr )
    CheckSort ( arr , k , n )

Index/key variables: i, j
Iterator variables: i, j
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
def replaceNode ( node , level = 0 ) :
    if ( node == None ) :
        return
    node . data = level
    replaceNode ( node . left , level + 1 )
    replaceNode ( node . right , level + 1 )
def printInorder ( node ) :
    if ( node == None ) :
        return
    printInorder ( node . left )
    print ( node . data , end = " ▁ " )
    printInorder ( node . right )
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 3 )
    root . left = newNode ( 2 )
    root . right = newNode ( 5 )
    root . left . left = newNode ( 1 )
    root . left . right = newNode ( 4 )
    print ( " Before ▁ Replacing ▁ Nodes " )
    printInorder ( root )
    replaceNode ( root )
    print ( )
    print ( " After ▁ Replacing ▁ Nodes " )
    printInorder ( root )

Class/struct names: newNode
Python program:
mod = 1000000007
def power ( x : int , y : int , p : int ) -> int :
    res = 1
    x %= p
    while y > 0 :
        if y & 1 :
            res = ( res * x ) % p
        y = y // 2
        x = ( x * x ) % p
    return res
size = [ 0 ] * 300005
freq = [ 0 ] * 300004
edges = [ ]
def initialize ( arr : list , N : int ) :
    for i in range ( N ) :
        arr [ i ] = i
        size [ i ] = 1
def root ( arr : list , i : int ) -> int :
    while arr [ i ] != i :
        i = arr [ i ]
    return i
def weighted_union ( arr : list , size : list , A : int , B : int ) :
    root_A = root ( arr , A )
    root_B = root ( arr , B )
    if size [ root_A ] < size [ root_B ] :
        arr [ root_A ] = arr [ root_B ]
        size [ root_B ] += size [ root_A ]
    else :
        arr [ root_B ] = arr [ root_A ]
        size [ root_A ] += size [ root_B ]
def AddEdge ( a : int , b : int , w : int ) :
    edges . append ( ( w , ( a , b ) ) )
def makeTree ( ) :
    AddEdge ( 1 , 2 , 1 )
    AddEdge ( 1 , 3 , 3 )
    AddEdge ( 3 , 4 , 2 )
def minProduct ( ) -> int :
    result = 1
    edges . sort ( key = lambda a : a [ 0 ] )
    for i in range ( len ( edges ) - 1 , - 1 , - 1 ) :
        curr_weight = edges [ i ] [ 0 ]
        node1 = edges [ i ] [ 1 ] [ 0 ]
        node2 = edges [ i ] [ 1 ] [ 1 ]
        root1 = root ( freq , node1 )
        set1_size = size [ root1 ]
        root2 = root ( freq , node2 )
        set2_size = size [ root2 ]
        prod = set1_size * set2_size
        product = power ( curr_weight , prod , mod )
        result = ( ( result % mod ) * ( product % mod ) ) % mod
        weighted_union ( freq , size , node1 , node2 )
    return result % mod
if __name__ == " _ _ main _ _ " :
    n = 4
    initialize ( freq , n )
    makeTree ( )
    print ( minProduct ( ) )

Index/key variables: i, root1, root2, root_A, root_B
Iterator variables: i
Python program:
def check ( arr , n ) :
    modify = 0
    if ( arr [ n - 1 ] >= arr [ n - 2 ] ) :
        arr [ n - 1 ] = arr [ n - 2 ] - 1
        modify += 1
    if ( arr [ 0 ] <= arr [ 1 ] ) :
        arr [ 0 ] = arr [ 1 ] + 1
        modify += 1
    for i in range ( n - 2 , 0 , - 1 ) :
        if ( arr [ i - 1 ] <= arr [ i ] and arr [ i + 1 ] <= arr [ i ] ) or ( arr [ i - 1 ] >= arr [ i ] and arr [ i + 1 ] >= arr [ i ] ) :
            arr [ i ] = ( arr [ i - 1 ] + arr [ i + 1 ] ) // 2
            modify += 1
            if ( arr [ i ] == arr [ i - 1 ] or arr [ i ] == arr [ i + 1 ] ) :
                return False
    if ( modify > 1 ) :
        return False
    return True
if __name__ == " _ _ main _ _ " :
    arr = [ 10 , 5 , 11 , 3 ]
    n = len ( arr )
    if ( check ( arr , n ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i
Accumulator variables: modify
Iterator variables: i
Python program:
def maxDisjointIntervals ( list_ ) :
    list_ . sort ( key = lambda x : x [ 1 ] )
    print ( " [ " , list_ [ 0 ] [ 0 ] , " , ▁ " , list_ [ 0 ] [ 1 ] , " ] " )
    r1 = list_ [ 0 ] [ 1 ]
    for i in range ( 1 , len ( list_ ) ) :
        l1 = list_ [ i ] [ 0 ]
        r2 = list_ [ i ] [ 1 ]
        if l1 > r1 :
            print ( " [ " , l1 , " , ▁ " , r2 , " ] " )
            r1 = r2
if __name__ == " _ _ main _ _ " :
    N = 4
    intervals = [ [ 1 , 4 ] , [ 2 , 3 ] , [ 4 , 6 ] , [ 8 , 9 ] ]
    maxDisjointIntervals ( intervals )

Index/key variables: i
Iterator variables: i
Python program:
def printAnswer ( v , n ) :
    indices = list ( range ( n ) )
    indices . sort ( key = lambda i : v [ i ] )
    res = [ 2 ] * n
    res [ indices [ 0 ] ] = 1
    maxR = v [ indices [ 0 ] ] [ 1 ]
    for i in range ( 1 , n ) :
        if maxR >= v [ indices [ i ] ] [ 0 ] :
            res [ indices [ i ] ] = res [ indices [ i - 1 ] ]
            maxR = max ( maxR , v [ indices [ i ] ] [ 1 ] )
        else :
            break
    else :
        print ( " Not ▁ possible " )
        return
    print ( " ▁ " . join ( map ( str , res ) ) )
if __name__ == " _ _ main _ _ " :
    v = [ [ 2 , 8 ] , [ 3 , 4 ] , [ 5 , 8 ] , [ 9 , 10 ] ]
    n = len ( v )
    printAnswer ( v , n )

Index/key variables: i
Iterator variables: i
Python program:
def countDistinct ( arr , n ) :
    s = set ( )
    res = 0
    for i in range ( n ) :
        if ( arr [ i ] not in s ) :
            s . add ( arr [ i ] )
            res += 1
    return res
arr = [ 6 , 10 , 5 , 4 , 9 , 120 , 4 , 6 , 10 ]
n = len ( arr )
print ( countDistinct ( arr , n ) )

Index/key variables: i
Accumulator variables: res, s
Iterator variables: i
Python program:
import math
def nextGap ( gap ) :
    if gap <= 1 :
        return 0
    return int ( math . ceil ( gap / 2 ) )
def swap ( nums , i , j ) :
    temp = nums [ i ]
    nums [ i ] = nums [ j ]
    nums [ j ] = temp
def inPlaceMerge ( nums , start , end ) :
    gap = end - start + 1
    gap = nextGap ( gap )
    while gap > 0 :
        i = start
        while ( i + gap ) <= end :
            j = i + gap
            if nums [ i ] > nums [ j ] :
                swap ( nums , i , j )
            i += 1
        gap = nextGap ( gap )
def mergeSort ( nums , s , e ) :
    if s == e :
        return
    mid = ( s + e ) // 2
    mergeSort ( nums , s , mid )
    mergeSort ( nums , mid + 1 , e )
    inPlaceMerge ( nums , s , e )
def printArray ( A , size ) :
    for i in range ( size ) :
        print ( A [ i ] , end = " ▁ " )
    print ( )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 12 , 11 , 13 , 5 , 6 , 7 ]
    arr_size = len ( arr )
    mergeSort ( arr , 0 , arr_size - 1 )
    printArray ( arr , arr_size )

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