dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
from math import pow
def findMissingBinaryString ( nums , N ) :
    s = set ( )
    counter = 0
    for x in nums :
        s . add ( x )
    total = int ( pow ( 2 , N ) )
    ans = " "
    for i in range ( total ) :
        num = " "
        j = N - 1
        while ( j >= 0 ) :
            if ( i & ( 1 << j ) ) :
                num += '1'
            else :
                num += '0'
            j -= 1
        if ( num in s ) :
            continue
            counter += 1
        else :
            print ( num , end = " , ▁ " )
    if ( counter == total ) :
        print ( " - 1" )
if __name__ == ' _ _ main _ _ ' :
    N = 3
    arr = [ "101" , "111" , "001" , "011" , "100" , "110" ]
    findMissingBinaryString ( arr , N )

Accumulator variables: counter, j, num, s
Iterator variables: i, x
Python program:
def check ( a , b , k , n , x ) :
    sum = 0
    for i in range ( n ) :
        sum = sum + pow ( max ( a [ i ] - x , 0 ) , b [ i ] )
    if ( sum <= k ) :
        return True
    else :
        return False
def findMin ( a , b , n , k ) :
    l = 0
    u = max ( a )
    while ( l < u ) :
        m = ( l + u ) // 2
        if ( check ( a , b , k , n , m ) ) :
            u = m
        else :
            l = m + 1
    return l
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 1 , 4 , 3 , 5 ]
    brr = [ 4 , 3 , 2 , 3 , 1 ]
    K = 12
    N = len ( arr )
    print ( findMin ( arr , brr , N , K ) )

Index/key variables: i
Iterator variables: i
Python program:
def getPairsCount ( arr , n ) :
    count = 0
    for i in range ( 0 , n ) :
        s = arr [ i ] - ( i % arr [ i ] )
        for j in range ( s , n ) :
            if ( i < j and ( arr [ i ] * arr [ j ] ) == abs ( i - j ) ) :
                count += 1
    return count
arr = [ 1 , 1 , 2 , 4 ]
N = len ( arr )
print ( getPairsCount ( arr , N ) )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
def printOccurences ( arr , N ) :
    mp = [ [ ] for i in range ( 26 ) ]
    for i in range ( N ) :
        for j in range ( len ( arr [ i ] ) ) :
            mp [ ord ( arr [ i ] [ j ] ) - ord ( ' a ' ) ] . append ( ( i + 1 , j + 1 ) )
    for i in range ( 26 ) :
        if len ( mp [ i ] ) == 0 :
            continue
        print ( " Occurences ▁ of : " , chr ( i + ord ( ' a ' ) ) , " = " , end = " ▁ " )
        for j in mp [ i ] :
            print ( " [ " + str ( j [ 0 ] ) + " ▁ " + str ( j [ 1 ] ) + " ] ▁ " , end = " " )
        print ( )
if __name__ == ' _ _ main _ _ ' :
    arr = [ " geeksforgeeks " , " gfg " ]
    N = len ( arr )
    printOccurences ( arr , N )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def mostFrequent ( arr , N ) :
    ans = [ 0 ] * N
    for i in range ( N ) :
        count = [ 0 ] * N
        best = 0
        for j in range ( i , N ) :
            count [ arr [ j ] - 1 ] += 1
            if ( count [ arr [ j ] - 1 ] > count [ best - 1 ] or ( count [ arr [ j ] - 1 ] == count [ best - 1 ] and arr [ j ] < best ) ) :
                best = arr [ j ]
            ans [ best - 1 ] += 1
    print ( * ans )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 1 , 2 , 3 ]
    N = len ( arr )
    mostFrequent ( arr , N )

Index/key variables: j
Iterator variables: i, j
Python program:
from math import log2
def countElement ( arr , N ) :
    count = 0
    m = { }
    for i in range ( N ) :
        m [ arr [ i ] ] = m . get ( arr [ i ] , 0 ) + 1
    for i in range ( N ) :
        lg = int ( log2 ( arr [ i ] ) )
        p = pow ( 2 , lg )
        if ( p in m ) :
            count += 1
    return count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 4 , 6 , 9 ]
    N = len ( arr )
    print ( countElement ( arr , N ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
from bisect import bisect_left , bisect_right
def lower_bound ( a , low , high , element ) :
    while ( low < high ) :
        middle = low + ( high - low ) // 2
        if ( element > a [ middle ] ) :
            low = middle + 1
        else :
            high = middle
    return low
def maximumIntersections ( arr , N ) :
    count = 0
    L = [ 0 ] * N
    R = [ 0 ] * N
    for i in range ( N ) :
        L [ i ] = arr [ i ] [ 0 ]
        R [ i ] = arr [ i ] [ 1 ]
    L . sort ( )
    R . sort ( )
    for i in range ( N ) :
        l = arr [ i ] [ 0 ]
        r = arr [ i ] [ 1 ]
        x = lower_bound ( L , 0 , N , l )
        y = N - lower_bound ( R , 0 , N , r + 1 )
        cnt = x + y
        cnt = N - cnt - 1
        count = max ( count , cnt )
    return count
if __name__ == " _ _ main _ _ " :
    arr = [ [ 1 , 6 ] , [ 5 , 5 ] , [ 2 , 3 ] ]
    N = len ( arr )
    print ( maximumIntersections ( arr , N ) )

Index/key variables: i, middle
Iterator variables: i
Python program:
def removeDuplicateCharacters ( arr ) :
    cset = set ( [ ] )
    n = len ( arr )
    out = [ ]
    for st in arr :
        out_curr = " "
        for ch in st :
            if ( ch in cset ) :
                continue
            out_curr += ch
            cset . add ( ch )
        if ( len ( out_curr ) ) :
            out . append ( out_curr )
    for i in range ( len ( out ) ) :
        print ( out [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ " Geeks " , " For " , " Geeks " , " Post " ]
    removeDuplicateCharacters ( arr )

Index/key variables: i
Accumulator variables: cset, out, out_curr
Iterator variables: ch, i, st
Python program:
def isPrime ( n ) :
    if ( n <= 1 ) :
        return False
    if ( n <= 3 ) :
        return True
    if ( n % 2 == 0 or n % 3 == 0 ) :
        return False
    i = 5
    while ( i * i <= n ) :
        if ( n % i == 0 or n % ( i + 2 ) == 0 ) :
            return False
        i = i + 6
    return True
def primeFactorSum ( arr , n , k ) :
    sum = 0
    for i in range ( n ) :
        if ( k % arr [ i ] == 0 and isPrime ( arr [ i ] ) ) :
            sum = sum + arr [ i ]
    print ( sum )
arr = [ 1 , 2 , 3 , 5 , 6 , 7 , 15 ]
N = len ( arr )
K = 35
primeFactorSum ( arr , N , K )

Index/key variables: i
Iterator variables: i
Python program:
import math
def minOperations ( nums , x ) :
    if sum ( nums ) < x :
        return - 1
    ans = math . inf
    l , r = len ( nums ) - 1 , len ( nums )
    x -= sum ( nums )
    while l >= 0 :
        if x <= 0 :
            x += nums [ l ]
            l -= 1
        if x > 0 :
            r -= 1
            x -= nums [ r ]
        if x == 0 :
            ans = min ( ans , ( l + 1 ) + ( len ( nums ) - r ) )
    return ans if ans < math . inf else - 1
nums = [ 1 , 1 , 4 , 2 , 3 ]
x = 5
print ( minOperations ( nums , x ) )

Index/key variables: l, r
Accumulator variables: x
Python program:
def evenproduct ( arr , length ) :
    total_subarray = length * ( length + 1 ) // 2
    total_odd = 0
    count_odd = 0
    for i in range ( length ) :
        if ( arr [ i ] % 2 == 0 ) :
            count_odd = 0
        else :
            count_odd += 1
            total_odd += count_odd
    print ( total_subarray - total_odd )
if __name__ == " _ _ main _ _ " :
    arr = [ 7 , 5 , 4 , 9 ]
    length = len ( arr )
    evenproduct ( arr , length )

Index/key variables: i
Accumulator variables: count_odd, total_odd
Iterator variables: i
Python program:
def checkGroup ( arr ) :
    if len ( arr ) <= 2 :
        return True
    corner = arr [ 0 ] + arr [ - 1 ]
    xorSum = 0
    for i in range ( len ( arr ) - 1 ) :
        xorSum += ( arr [ i ] ^ arr [ i + 1 ] )
    if not corner :
        if xorSum > 2 :
            return False
    elif corner == 1 :
        if xorSum > 1 :
            return False
    else :
        if xorSum > 0 :
            return False
    return True
def isInGroupUtil ( mat ) :
    for i in mat :
        if not checkGroup ( i ) :
            return False
    return True
def isInGroup ( mat ) :
    ans = isInGroupUtil ( mat )
    if ans :
        print ( " Yes " )
    else :
        print ( " No " )
mat = [ [ 0 , 1 , 1 , 0 ] , [ 1 , 1 , 0 , 0 ] , [ 0 , 0 , 0 , 1 ] , [ 1 , 1 , 1 , 0 ] ]
isInGroup ( mat )

Index/key variables: i
Accumulator variables: xorSum
Iterator variables: i
Python program:
def productOfDigits ( N ) :
    product = 1 ;
    while ( N != 0 ) :
        product = product * ( N % 10 ) ;
        N = N // 10 ;
    return product ;
def productOfDigitsK ( N , K ) :
    flag = 0 ;
    for i in range ( 1 , N + 1 ) :
        if ( K == productOfDigits ( i ) ) :
            print ( i , end = " ▁ " ) ;
            flag = 1 ;
    if ( flag == 0 ) :
        print ( " - 1" ) ;
if __name__ == " _ _ main _ _ " :
    N = 500 ; K = 10 ;
    productOfDigitsK ( N , K ) ;

Iterator variables: i
Python program:
def minimiseDifference ( arr , K ) :
    N = len ( arr )
    maxSuffix = [ 0 for i in range ( N + 1 ) ]
    minSuffix = [ 0 for i in range ( N + 1 ) ]
    maxSuffix [ N ] = - 1e9
    minSuffix [ N ] = 1e9
    maxSuffix [ N - 1 ] = arr [ N - 1 ]
    minSuffix [ N - 1 ] = arr [ N - 1 ]
    i = N - 2
    while ( i >= 0 ) :
        maxSuffix [ i ] = max ( maxSuffix [ i + 1 ] , arr [ i ] )
        minSuffix [ i ] = min ( minSuffix [ i + 1 ] , arr [ i ] )
        i -= 1
    maxPrefix = arr [ 0 ]
    minPrefix = arr [ 0 ]
    minDiff = maxSuffix [ K ] - minSuffix [ K ]
    for i in range ( 1 , N ) :
        if ( i + K <= N ) :
            maximum = max ( maxSuffix [ i + K ] , maxPrefix )
            minimum = min ( minSuffix [ i + K ] , minPrefix )
            minDiff = min ( minDiff , maximum - minimum )
        maxPrefix = max ( maxPrefix , arr [ i ] )
        minPrefix = min ( minPrefix , arr [ i ] )
    print ( minDiff )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 5 , 8 , 9 , 1 , 2 ]
    K = 2
    minimiseDifference ( arr , K )

Index/key variables: K, N, i
Iterator variables: i
Python program:
from bisect import bisect_left , bisect_right
def minSegments ( segments , n ) :
    startPoints = [ 0 for i in range ( n ) ]
    endPoints = [ 0 for i in range ( n ) ]
    for i in range ( n ) :
        startPoints [ i ] = segments [ i ] [ 0 ]
        endPoints [ i ] = segments [ i ] [ 1 ]
    startPoints . sort ( reverse = False )
    endPoints . sort ( reverse = False )
    ans = n - 1
    for i in range ( n ) :
        f = segments [ i ] [ 0 ]
        s = segments [ i ] [ 1 ]
        leftDelete = bisect_left ( endPoints , f )
        rightDelete = max ( 0 , n - bisect_right ( startPoints , s ) )
        ans = min ( ans , leftDelete + rightDelete )
    print ( ans )
if __name__ == ' _ _ main _ _ ' :
    arr = [ [ 1 , 2 ] , [ 5 , 6 ] , [ 6 , 7 ] , [ 7 , 10 ] , [ 8 , 9 ] ]
    N = len ( arr )
    minSegments ( arr , N )

Index/key variables: i
Iterator variables: i
Python program:
dRow = [ - 1 , 0 , 1 , 0 ]
dCol = [ 0 , 1 , 0 , - 1 ]
def isValid ( row , col , COL , ROW ) :
    global vis
    if ( row < 0 or col < 0 or col > COL - 1 or row > ROW - 1 ) :
        return False
    if ( vis [ row ] [ col ] == True ) :
        return False
    return True
def DFSUtil ( row , col , grid , M , N ) :
    global vis
    vis [ row ] [ col ] = True
    print ( grid [ row ] [ col ] , end = " ▁ " )
    for i in range ( 4 ) :
        x = row + dRow [ i ]
        y = col + dCol [ i ]
        if ( isValid ( x , y , M , N ) ) :
            DFSUtil ( x , y , grid , M , N )
def DFS ( row , col , grid , M , N ) :
    global vis
    DFSUtil ( 0 , 0 , grid , M , N )
if __name__ == ' _ _ main _ _ ' :
    grid = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] , [ 13 , 14 , 15 , 16 ] ]
    M = len ( grid )
    N = len ( grid [ 0 ] )
    vis = [ [ False for i in range ( M ) ] for i in range ( N ) ]
    DFS ( 0 , 0 , grid , M , N )

Index/key variables: col, i, row
Iterator variables: i
Python program:
dRow = [ - 1 , 0 , 1 , 0 ]
dCol = [ 0 , 1 , 0 , - 1 ]
vis = [ ]
def isValid ( row , col , COL , ROW ) :
    global vis
    if ( row < 0 or col < 0 or col > COL - 1 or row > ROW - 1 ) :
        return False
    if ( vis [ row ] [ col ] == True ) :
        return False
    return True
def DFS_iterative ( grid , M , N ) :
    global vis
    vis = [ ]
    for i in range ( M + 5 ) :
        vis . append ( [ ] )
        for j in range ( N + 5 ) :
            vis [ i ] . append ( False )
    st = [ ]
    st . append ( [ 0 , 0 ] )
    vis [ 0 ] [ 0 ] = True
    while ( len ( st ) > 0 ) :
        p = st [ - 1 ]
        st . pop ( )
        row = p [ 0 ]
        col = p [ 1 ]
        print ( grid [ row ] [ col ] , " " , end = " " )
        for i in range ( 4 ) :
            x = row + dRow [ i ]
            y = col + dCol [ i ]
            if ( isValid ( x , y , M , N ) ) :
                st . append ( [ x , y ] )
                vis [ x ] [ y ] = True
grid = [ [ 1 , 2 , 3 , 4 ] , [ 5 , 6 , 7 , 8 ] , [ 9 , 10 , 11 , 12 ] , [ 13 , 14 , 15 , 16 ] ]
M = len ( grid )
N = len ( grid [ 0 ] )
DFS_iterative ( grid , M , N )

Index/key variables: col, i, row, x, y
Accumulator variables: st, vis
Iterator variables: i, j
Python program:
def minOps ( s , N ) :
    ans = 0
    for i in range ( 1 , N ) :
        if ( s [ i ] != s [ i - 1 ] ) :
            ans += 1
    if ( ans % 2 == 1 ) :
        print ( ( ans - 1 ) // 2 )
        return
    print ( ans // 2 )
str = "01011100"
N = len ( str )
minOps ( str , N )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
def count ( a , n ) :
    if ( n == 1 ) :
        print ( 0 )
        return
    pre = [ 0 ] * ( n - 1 )
    suf = [ 0 ] * ( n - 1 )
    max = a [ 0 ]
    ans = 0
    pre [ 0 ] = a [ 0 ]
    for i in range ( n - 1 ) :
        if ( a [ i ] > max ) :
            max = a [ i ]
        pre [ i ] = max
    max = a [ n - 1 ]
    suf [ n - 2 ] = a [ n - 1 ]
    for i in range ( n - 2 , 0 , - 1 ) :
        if ( a [ i ] > max ) :
            max = a [ i ]
        suf [ i - 1 ] = max
    for i in range ( n - 1 ) :
        if ( pre [ i ] < suf [ i ] ) :
            ans += 1
    print ( ans )
arr = [ 2 , 3 , 4 , 8 , 1 , 4 ]
N = len ( arr )
count ( arr , N )

Index/key variables: i
Accumulator variables: ans
Iterator variables: i
Python program:
class TreeNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
ans = 0
def newNode ( data ) :
    Node = TreeNode ( data )
    return ( Node )
def sumofsubtree ( root ) :
    global ans
    p = [ 1 , 0 ]
    if ( root . left != None ) :
        ptemp = sumofsubtree ( root . left )
        p [ 1 ] += ptemp [ 0 ] + ptemp [ 1 ]
        p [ 0 ] += ptemp [ 0 ]
    if ( root . right != None ) :
        ptemp = sumofsubtree ( root . right )
        p [ 1 ] += ptemp [ 0 ] + ptemp [ 1 ]
        p [ 0 ] += ptemp [ 0 ]
    ans += p [ 1 ]
    return p
root = newNode ( 1 )
root . left = newNode ( 2 )
root . right = newNode ( 3 )
root . left . left = newNode ( 4 )
root . left . right = newNode ( 5 )
root . right . left = newNode ( 6 )
root . right . right = newNode ( 7 )
root . left . left . left = newNode ( 8 )
root . left . left . right = newNode ( 9 )
sumofsubtree ( root )
print ( ans )

Class/struct names: TreeNode
Python program:
def minTime ( arr , N , K ) :
    q = [ ]
    vis = [ False ] * ( N + 1 )
    time = 0
    for i in range ( K ) :
        q . append ( arr [ i ] )
        vis [ arr [ i ] ] = True
    while ( len ( q ) > 0 ) :
        for i in range ( len ( q ) ) :
            curr = q [ 0 ]
            q . pop ( 0 )
            if ( curr - 1 >= 1 and vis [ curr - 1 ] == 0 ) :
                vis [ curr - 1 ] = True
                q . append ( curr - 1 )
            if ( curr + 1 <= N and vis [ curr + 1 ] == 0 ) :
                vis [ curr + 1 ] = True
                q . append ( curr + 1 )
        time += 1
    print ( time - 1 )
N = 6
arr = [ 2 , 6 ]
K = len ( arr )
minTime ( arr , N , K )

Index/key variables: i
Accumulator variables: q, time
Iterator variables: i
Python program:
MAXL = 17 ;
N = 0 ;
v = 0 ;
def findN ( D ) :
    global N ;
    global v ;
    if ( D % 9 != 0 ) :
        return 0 ;
    D //= 9 ;
    B = [ 0 ] * MAXL ;
    B [ 0 ] = 1 ;
    for i in range ( 1 , MAXL ) :
        B [ i ] = B [ i - 1 ] * 10 ;
    ans = 0 ;
    for i in range ( 1 , MAXL + 1 ) :
        N = ( i + 1 ) // 2 ;
        v = [ 0 ] * N ;
        for j in range ( N ) :
            for k in range ( j , i - j ) :
                v [ j ] += B [ k ] ;
        temp = [ 0 ] * N ;
        ans += count ( D , i , 0 , temp ) ;
        return ans ;
def count ( D , l , t , x ) :
    global N ;
    global v ;
    if ( t == N ) :
        if ( D != 0 ) :
            return 0 ;
        ans = 1 ;
        for i in range ( N ) :
            ans *= ( 9 if i == 0 else 10 ) - abs ( x [ i ] ) ;
        if ( l % 2 == 0 ) :
            ans *= 10 ;
        return ans ;
    ans = 0 ;
    for m in range ( - 9 , 10 ) :
        if ( - v [ t ] < D + v [ t ] * m and D + v [ t ] * m < v [ t ] ) :
            x [ t ] = m ;
            ans += count ( D + v [ t ] * m , l , t + 1 , x ) ;
    return ans ;
if __name__ == ' _ _ main _ _ ' :
    D = 63 ;
    print ( findN ( D ) ) ;

Index/key variables: i, j, k, t
Accumulator variables: ans
Iterator variables: i, j, k, m
Python program:
def findPeak ( arr ) :
    left = 0
    right = len ( arr ) - 1
    while ( left < right ) :
        mid = left + ( right - left ) // 2
        if ( arr [ mid ] < arr [ ( mid + 1 ) ] ) :
            left = mid + 1
        else :
            right = mid
    return left
def BS ( X , left , right , arr ) :
    while ( left <= right ) :
        mid = left + ( right - left ) // 2
        if ( arr [ mid ] == X ) :
            return mid
        elif ( X > arr [ mid ] ) :
            left = mid + 1
        else :
            right = mid - 1
    return - 1
def reverseBS ( X , left , right , arr ) :
    while ( left <= right ) :
        mid = left + ( right - left ) // 2
        if ( arr [ mid ] == X ) :
            return mid
        elif ( X > arr [ mid ] ) :
            right = mid - 1
        else :
            left = mid + 1
    return - 1
def findInMA ( X , mountainArr ) :
    peakIndex = findPeak ( mountainArr )
    res = - 1
    if ( X >= mountainArr [ 0 ] and X <= mountainArr [ peakIndex ] ) :
        res = BS ( X , 0 , peakIndex , mountainArr )
    if ( res == - 1 ) :
        res = reverseBS ( X , peakIndex + 1 , mountainArr . size ( ) - 1 , mountainArr )
    print ( res )
if __name__ == " _ _ main _ _ " :
    X = 3
    arr = [ 1 , 2 , 3 , 4 , 5 , 3 , 1 ]
    findInMA ( X , arr )

Index/key variables: mid, peakIndex
Python program:
def rearrange ( a , n , x ) :
    for i in range ( n ) :
        a [ i ] = abs ( a [ i ] )
    a = sorted ( a )
    x = n - x ;
    z = a . count ( 0 )
    if ( x > n - z ) :
        print ( " - 1" )
        return
    for i in range ( 0 , n , 2 ) :
        if x <= 0 :
            break
        a [ i ] = - a [ i ]
        x -= 1
    for i in range ( n - 1 , - 1 , - 1 ) :
        if x <= 0 :
            break
        if ( a [ i ] > 0 ) :
            a [ i ] = - a [ i ]
            x -= 1
    for i in range ( n ) :
        print ( a [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 0 , - 2 , 4 , 5 , - 3 ]
    K = 3
    N = len ( arr )
    rearrange ( arr , N , K )

Index/key variables: i
Accumulator variables: x
Iterator variables: i
Python program:
def maxSubarrayProduct ( arr , n ) :
    max_ending_here = 1
    min_ending_here = 1
    max_so_far = 0
    flag = 0
    for i in range ( n ) :
        if ( arr [ i ] > 0 ) :
            max_ending_here = max_ending_here * arr [ i ]
            min_ending_here = min ( min_ending_here * arr [ i ] , 1 )
            flag = 1
        elif ( arr [ i ] == 0 ) :
            max_ending_here = 1
            min_ending_here = 1
        else :
            temp = max_ending_here
            max_ending_here = max ( min_ending_here * arr [ i ] , 1 )
            min_ending_here = temp * arr [ i ]
        if ( max_so_far < max_ending_here ) :
            max_so_far = max_ending_here
    if ( flag == 0 and max_so_far == 0 ) :
        return 0
    return max_so_far
def findMaxProduct ( a , n ) :
    i = 0
    maxProd = - 10 ** 9
    while ( i < n ) :
        v = [ ]
        v . append ( a [ i ] )
        if i < n - 1 and a [ i ] < a [ i + 1 ] :
            while ( i < n - 1 and a [ i ] < a [ i + 1 ] ) :
                v . append ( a [ i + 1 ] )
                i += 1
        elif ( i < n - 1 and a [ i ] > a [ i + 1 ] ) :
            while ( i < n - 1 and a [ i ] > a [ i + 1 ] ) :
                v . append ( a [ i + 1 ] )
                i += 1
        prod = maxSubarrayProduct ( v , len ( v ) )
        maxProd = max ( maxProd , prod )
        i += 1
    return maxProd
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 10 , 8 , 1 , 100 , 101 ]
    N = len ( arr )
    print ( findMaxProduct ( arr , N ) )

Index/key variables: i
Accumulator variables: v
Iterator variables: i
Python program:
parent = [ 0 ] * ( 1000000 )
def root ( a ) :
    if ( a == parent [ a ] ) :
        return a
    parent [ a ] = root ( parent [ a ] )
    return parent [ a ]
def connect ( a , b ) :
    a = root ( a )
    b = root ( b )
    if ( a != b ) :
        parent [ b ] = a
def connectedComponents ( n ) :
    s = set ( )
    for i in range ( n ) :
        s . add ( root ( parent [ i ] ) )
    print ( len ( s ) )
def printAnswer ( N , edges ) :
    for i in range ( N + 1 ) :
        parent [ i ] = i
    for i in range ( len ( edges ) ) :
        connect ( edges [ i ] [ 0 ] , edges [ i ] [ 1 ] )
    connectedComponents ( N )
N = 6
edges = [ [ 1 , 0 ] , [ 2 , 3 ] , [ 1 , 2 ] , [ 4 , 5 ] ]
printAnswer ( N , edges )

Index/key variables: a, b, i
Accumulator variables: s
Iterator variables: i
Python program:
def removeZeroRowCol ( arr ) :
    n = len ( arr )
    col = [ 0 ] * ( n + 1 )
    row = [ 0 ] * ( n + 1 )
    for i in range ( n ) :
        count = 0
        for j in range ( n ) :
            col [ j ] += ( arr [ i ] [ j ] == 1 )
            count += ( arr [ i ] [ j ] == 1 )
        row [ i ] = count
    for i in range ( n ) :
        if ( row [ i ] == 0 ) :
            continue
        for j in range ( n ) :
            if ( col [ j ] != 0 ) :
                print ( arr [ i ] [ j ] , end = " " )
        print ( )
arr = [ [ 1 , 1 , 0 , 1 ] , [ 0 , 0 , 0 , 0 ] , [ 1 , 1 , 0 , 1 ] , [ 0 , 1 , 0 , 1 ] ]
removeZeroRowCol ( arr )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
def findOverlapSegement ( N , a , b ) :
    tup = [ ]
    for i in range ( N ) :
        x = a [ i ]
        y = b [ i ]
        tup . append ( ( ( x , y ) , i ) )
    tup . sort ( )
    curr = tup [ 0 ] [ 0 ] [ 1 ]
    currPos = tup [ 0 ] [ 1 ]
    for i in range ( 1 , N ) :
        Q = tup [ i - 1 ] [ 0 ] [ 0 ]
        R = tup [ i ] [ 0 ] [ 0 ]
        if Q == R :
            if tup [ i - 1 ] [ 0 ] [ 1 ] < tup [ i ] [ 0 ] [ 1 ] :
                print ( tup [ i - 1 ] [ 1 ] , tup [ i ] [ 1 ] )
            else :
                print ( tup [ i ] [ 1 ] , tup [ i - 1 ] [ 1 ] )
            return
        T = tup [ i ] [ 0 ] [ 1 ]
        if ( T <= curr ) :
            print ( tup [ i ] [ 1 ] , currPos )
            return
        else :
            curr = T
            currPos = tup [ i ] [ 1 ]
    print ( " - 1" , " - 1" , end = " " )
a = [ 1 , 2 , 3 , 2 , 2 ]
b = [ 5 , 10 , 10 , 2 , 15 ]
N = len ( a )
findOverlapSegement ( N , a , b )

Index/key variables: i
Accumulator variables: tup
Iterator variables: i