dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def printt ( arr , N ) :
    for i in range ( N ) :
        print ( arr [ i ] , end = " ▁ " )
def makeLexicographically ( arr , N ) :
    index = 0
    temp = 0
    check = 0
    condition = 0
    element = 0
    for i in range ( N ) :
        if ( element == arr [ i ] ) :
            check = i
            break
        elif ( arr [ i ] != i + 1 and check == 0 ) :
            index = i
            check = 1
            condition = - 1
            element = i + 1
    if ( condition == - 1 ) :
        temp = arr [ index ]
        arr [ index ] = arr [ check ]
        arr [ check ] = temp
    printt ( arr , N )
arr = [ 1 , 2 , 3 , 4 ]
N = len ( arr )
makeLexicographically ( arr , N )

Index/key variables: check, i, index
Iterator variables: i
Python program:
def isLower ( c ) :
    return ord ( c ) >= ord ( ' a ' ) and ord ( c ) <= ord ( ' z ' )
def isUpper ( c ) :
    return ord ( c ) >= ord ( ' A ' ) and ord ( c ) <= ord ( ' Z ' )
def detectUppercaseUseUtil ( S ) :
    N = len ( S )
    i = 0
    if ( isLower ( S [ 0 ] ) ) :
        i = 1
        while ( S [ i ] and isLower ( S [ i ] ) ) :
            i += 1
        return True if ( i == N ) else False
    else :
        i = 1
        while ( S [ i ] and isUpper ( S [ i ] ) ) :
            i += 1
        if ( i == N ) :
            return True
        elif ( i > 1 ) :
            return False
        while ( S [ i ] and isLower ( S [ i ] ) ) :
            i += 1
        return True if ( i == N ) else False
def detectUppercaseUse ( S ) :
    check = detectUppercaseUseUtil ( S )
    if ( check ) :
        print ( " Yes " )
    else :
        print ( " No " )
if __name__ == ' _ _ main _ _ ' :
    S = " GeeKs "
    detectUppercaseUse ( S )

Index/key variables: i
Python program:
def check ( N ) :
    if ( N == 0 ) :
        return 0
    return ( ( N & ( N - 1 ) ) == 0 )
def build_seg_tree ( ss , se , si , tree , arr ) :
    if ( ss == se ) :
        tree [ si ] = check ( arr [ ss ] )
        return
    mid = ( ss + se ) // 2
    build_seg_tree ( ss , mid , 2 * si + 1 , tree , arr )
    build_seg_tree ( mid + 1 , se , 2 * si + 2 , tree , arr )
    tree [ si ] = tree [ 2 * si + 1 ] + tree [ 2 * si + 2 ]
def update ( ss , se , si , X , V , tree , arr ) :
    if ( ss == se ) :
        if ( ss == X ) :
            arr [ X ] = V
            tree [ si ] = check ( V )
        return
    mid = ( ss + se ) // 2
    if ( X <= mid ) :
        update ( ss , mid , 2 * si + 1 , X , V , tree , arr )
    else :
        update ( mid + 1 , se , 2 * si + 2 , X , V , tree , arr )
    tree [ si ] = tree [ 2 * si + 1 ] + tree [ 2 * si + 2 ]
def query ( l , r , ss , se , si , tree ) :
    if ( r < ss or l > se ) :
        return 0
    if ( l <= ss and r >= se ) :
        return tree [ si ]
    mid = ( ss + se ) // 2
    return ( query ( l , r , ss , mid , 2 * si + 1 , tree ) + query ( l , r , mid + 1 , se , 2 * si + 2 , tree ) )
def Query ( arr , N , Q ) :
    tree = [ 0 ] * ( 4 * N )
    build_seg_tree ( 0 , N - 1 , 0 , tree , arr )
    for i in range ( len ( Q ) ) :
        if ( Q [ i ] [ 0 ] == 1 ) :
            print ( query ( Q [ i ] [ 1 ] , Q [ i ] [ 2 ] , 0 , N - 1 , 0 , tree ) , end = " ▁ " )
        else :
            update ( 0 , N - 1 , 0 , Q [ i ] [ 1 ] , Q [ i ] [ 2 ] , tree , arr )
arr = [ 12 , 11 , 16 , 2 , 32 ]
Q = [ [ 1 , 0 , 2 ] , [ 2 , 4 , 24 ] , [ 1 , 1 , 4 ] ]
N = len ( arr )
Query ( arr , N , Q )

Index/key variables: X, i, si, ss
Iterator variables: i
Python program:
m = 0
n = 0
def valid ( x , y ) :
    global n
    global m
    return ( x >= 0 and x < m and y >= 0 and y < n )
def border ( x , y ) :
    global n
    global m
    return ( x == 0 or x == m - 1 or y == 0 or y == n - 1 )
def minStep ( mat ) :
    global n
    global m
    m = len ( mat )
    n = len ( mat [ 0 ] )
    dx = [ 1 , - 1 , 0 , 0 ]
    dy = [ 0 , 0 , 1 , - 1 ]
    pQ = [ ]
    fQ = [ ]
    for i in range ( m ) :
        for j in range ( n ) :
            if ( mat [ i ] [ j ] == 2 ) :
                fQ . append ( [ i , j ] )
            elif ( mat [ i ] [ j ] == 1 ) :
                if ( border ( i , j ) ) :
                    return 0
                pQ . append ( [ i , j ] )
    depth = 0
    visited = [ [ 0 for i in range ( m ) ] for j in range ( n ) ]
    while ( len ( pQ ) > 0 ) :
        depth += 1
        i = len ( pQ )
        while ( i > 0 ) :
            pos = pQ [ 0 ]
            pQ . remove ( pQ [ 0 ] )
            if ( mat [ pos [ 0 ] ] [ pos [ 1 ] ] == 2 ) :
                continue
            for j in range ( 4 ) :
                x = pos [ 0 ] + dx [ j ]
                y = pos [ 1 ] + dy [ j ]
                if ( valid ( x , y ) and mat [ x ] [ y ] != 2 and visited [ x ] [ y ] == 0 ) :
                    visited [ x ] [ y ] = 1
                    pQ . append ( [ x , y ] )
                    if ( border ( x , y ) ) :
                        return depth
            i -= 1
        i = len ( fQ )
        while ( i > 0 ) :
            pos = fQ [ 0 ]
            fQ . remove ( fQ [ 0 ] )
            for j in range ( 4 ) :
                x = pos [ 0 ] + dx [ j ]
                y = pos [ 1 ] + dy [ j ]
                if ( valid ( x , y ) and mat [ x ] [ y ] != 2 ) :
                    mat [ x ] [ y ] = 2
                    fQ . append ( [ x , y ] )
            i -= 1
    return - 1
if __name__ == ' _ _ main _ _ ' :
    grid = [ [ 0 , 0 , 0 , 0 ] , [ 2 , 0 , 0 , 0 ] , [ 2 , 1 , 0 , 0 ] , [ 2 , 2 , 0 , 0 ] ]
    print ( minStep ( grid ) )

Index/key variables: i, j, x, y
Accumulator variables: depth, fQ, pQ
Iterator variables: i, j
Python program:
def findSum ( arr , n ) :
    arr . sort ( )
    sum = arr [ 0 ]
    for i in range ( 0 , n - 1 ) :
        if ( arr [ i ] != arr [ i + 1 ] ) :
            sum = sum + arr [ i + 1 ]
    return sum
def main ( ) :
    arr = [ 1 , 2 , 3 , 1 , 1 , 4 , 5 , 6 ]
    n = len ( arr )
    print ( findSum ( arr , n ) )
if __name__ == ' _ _ main _ _ ' :
    main ( )

Index/key variables: i
Iterator variables: i
Python program:
def xorSubsequence ( a , n , k ) :
    ans = 0 ;
    dp = [ 0 ] * n ;
    dp [ 0 ] = 1 ;
    for i in range ( 1 , n ) :
        for j in range ( i - 1 , - 1 , - 1 ) :
            if ( ( a [ i ] ^ a [ j ] ) == k ) :
                dp [ i ] = max ( dp [ i ] , dp [ j ] + 1 ) ;
        ans = max ( ans , dp [ i ] ) ;
        dp [ i ] = max ( 1 , dp [ i ] ) ;
    return ans if ans >= 2 else 0 ;
if __name__ == ' _ _ main _ _ ' :
    arr = [ 3 , 2 , 4 , 3 , 5 ] ;
    K = 1 ;
    N = len ( arr ) ;
    print ( xorSubsequence ( arr , N , K ) ) ;

Index/key variables: i, j
Iterator variables: i, j
Python program:
from collections import defaultdict
def getCount ( rows , columns , sides ) :
    ans = 0
    umap = defaultdict ( int )
    for i in range ( rows ) :
        ratio = sides [ i ] [ 0 ] / sides [ i ] [ 1 ]
        umap [ ratio ] += 1
    for x in umap :
        value = umap [ x ]
        if ( value > 1 ) :
            ans += ( value * ( value - 1 ) ) / 2
    return ans
if __name__ == " _ _ main _ _ " :
    sides = [ [ 4 , 8 ] , [ 10 , 20 ] , [ 15 , 30 ] , [ 3 , 6 ] ]
    rows = 4
    columns = 2
    print ( int ( getCount ( rows , columns , sides ) ) )

Index/key variables: i, ratio, x
Accumulator variables: ans
Iterator variables: i, x
Python program:
def firstNonRepeating ( arr , n ) :
    for i in range ( n ) :
        j = 0
        while ( j < n ) :
            if ( i != j and arr [ i ] == arr [ j ] ) :
                break
            j += 1
        if ( j == n ) :
            return arr [ i ]
    return - 1
arr = [ 9 , 4 , 9 , 6 , 7 , 4 ]
n = len ( arr )
print ( firstNonRepeating ( arr , n ) )

Index/key variables: i, j
Iterator variables: i
Python program:
from collections import defaultdict
def firstNonRepeating ( arr , n ) :
    mp = defaultdict ( lambda : 0 )
    for i in range ( n ) :
        mp [ arr [ i ] ] += 1
    for i in range ( n ) :
        if mp [ arr [ i ] ] == 1 :
            return arr [ i ]
    return - 1
arr = [ 9 , 4 , 9 , 6 , 7 , 4 ]
n = len ( arr )
print ( firstNonRepeating ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def firstNonRepeating ( arr , n ) :
    mp = { }
    for i in range ( n ) :
        if arr [ i ] not in mp :
            mp [ arr [ i ] ] = 0
        mp [ arr [ i ] ] += 1
    for x in mp :
        if ( mp [ x ] == 1 ) :
            print ( x , end = " ▁ " )
arr = [ 9 , 4 , 9 , 6 , 7 , 4 ]
n = len ( arr )
firstNonRepeating ( arr , n )

Index/key variables: i, x
Iterator variables: i, x
Python program:
class Node :
    def __init__ ( self , x ) :
        self . data = x
        self . child = [ ]
def printPath ( vec ) :
    for ele in vec :
        print ( ele , end = " ▁ " )
    print ( )
def printAllRootToLeafPaths ( root ) :
    global vec
    if ( not root ) :
        return
    vec . append ( root . data )
    if ( len ( root . child ) == 0 ) :
        printPath ( vec )
        vec . pop ( )
        return
    for i in range ( len ( root . child ) ) :
        printAllRootToLeafPaths ( root . child [ i ] )
    vec . pop ( )
def printRootToLeafPaths ( root ) :
    global vec
    if ( not root ) :
        return
    printAllRootToLeafPaths ( root )
if __name__ == ' _ _ main _ _ ' :
    vec = [ ]
    root = Node ( 1 )
    root . child . append ( Node ( 2 ) )
    root . child . append ( Node ( 3 ) )
    root . child [ 0 ] . child . append ( Node ( 4 ) )
    root . child [ 1 ] . child . append ( Node ( 5 ) )
    root . child [ 1 ] . child . append ( Node ( 6 ) )
    root . child [ 1 ] . child [ 1 ] . child . append ( Node ( 7 ) )
    root . child [ 1 ] . child [ 1 ] . child . append ( Node ( 8 ) )
    printRootToLeafPaths ( root )

Index/key variables: i
Iterator variables: ele, i
Class/struct names: Node
Python program:
def printPairs ( arr , n ) :
    v = [ ]
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            if ( abs ( arr [ i ] ) == abs ( arr [ j ] ) ) :
                v . append ( abs ( arr [ i ] ) )
    if ( len ( v ) == 0 ) :
        return ;
    v . sort ( )
    for i in range ( len ( v ) ) :
        print ( - v [ i ] , " " , v [ i ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ 4 , 8 , 9 , - 4 , 1 , - 1 , - 8 , - 9 ]
    n = len ( arr )
    printPairs ( arr , n )

Index/key variables: i, j
Accumulator variables: v
Iterator variables: i, j
Python program:
from collections import defaultdict
def canPairs ( arr , n , k ) :
    if ( n & 1 ) :
        return 0
    freq = defaultdict ( lambda : 0 )
    for i in range ( 0 , n ) :
        freq [ ( ( arr [ i ] % k ) + k ) % k ] += 1
    for i in range ( 0 , n ) :
        rem = ( ( arr [ i ] % k ) + k ) % k
        if ( 2 * rem == k ) :
            if ( freq [ rem ] % 2 != 0 ) :
                return 0
        elif ( rem == 0 ) :
            if ( freq [ rem ] & 1 ) :
                return 0
        elif ( freq [ rem ] != freq [ k - rem ] ) :
            return 0
    return 1
arr = [ 92 , 75 , 65 , 48 , 45 , 35 ]
k = 10
n = len ( arr )
if ( canPairs ( arr , n , k ) ) :
    print ( " True " )
else :
    print ( " False " )

Index/key variables: i, rem
Iterator variables: i
Python program:
def findTriplet ( a1 , a2 , a3 , n1 , n2 , n3 , sum ) :
    for i in range ( 0 , n1 ) :
        for j in range ( 0 , n2 ) :
            for k in range ( 0 , n3 ) :
                if ( a1 [ i ] + a2 [ j ] + a3 [ k ] == sum ) :
                    return True
    return False
a1 = [ 1 , 2 , 3 , 4 , 5 ]
a2 = [ 2 , 3 , 6 , 1 , 2 ]
a3 = [ 3 , 2 , 4 , 5 , 6 ]
sum = 9
n1 = len ( a1 )
n2 = len ( a2 )
n3 = len ( a3 )
print ( " Yes " ) if findTriplet ( a1 , a2 , a3 , n1 , n2 , n3 , sum ) else print ( " No " )

Index/key variables: i, j, k
Iterator variables: i, j, k
Python program:
def findTriplet ( a1 , a2 , a3 , n1 , n2 , n3 , sum ) :
    s = set ( )
    for i in range ( n1 ) :
        s . add ( a1 [ i ] )
    for i in range ( n2 ) :
        for j in range ( n3 ) :
            if sum - a2 [ i ] - a3 [ j ] in s :
                return True
    return False
a1 = [ 1 , 2 , 3 , 4 , 5 ]
a2 = [ 2 , 3 , 6 , 1 , 2 ]
a3 = [ 3 , 24 , 5 , 6 ]
n1 = len ( a1 )
n2 = len ( a2 )
n3 = len ( a3 )
sum = 9
if findTriplet ( a1 , a2 , a3 , n1 , n2 , n3 , sum ) == True :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i, j
Accumulator variables: s
Iterator variables: i, j
Python program:
def countSum ( a , n , sum ) :
    count = 0
    for i in range ( n - 3 ) :
        for j in range ( i + 1 , n - 2 , 1 ) :
            req = sum - a [ i ] - a [ j ]
            m = { }
            for k in range ( j + 1 , n , 1 ) :
                m [ a [ k ] ] = m . get ( a [ k ] , 0 ) + 1
            twice_count = 0
            for k in range ( j + 1 , n , 1 ) :
                twice_count += m . get ( req - a [ k ] , 0 )
                if ( req - a [ k ] == a [ k ] ) :
                    twice_count -= 1
            count += twice_count // 2
    return count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 4 , 5 , 3 , 1 , 2 , 4 ]
    S = 13
    N = len ( arr )
    print ( countSum ( arr , N , S ) )

Index/key variables: i, j, k
Accumulator variables: count, twice_count
Iterator variables: i, j, k
Python program:
def check ( arr , n ) :
    for i in range ( n ) :
        hm = { }
        count = 0
        for j in range ( i , n ) :
            hm [ arr [ j ] ] = hm . get ( arr [ j ] , 0 ) + 1
            if ( hm [ arr [ j ] ] == 1 ) :
                count += 1
            if ( hm [ arr [ j ] ] == 2 ) :
                count -= 1
            if ( count == 0 ) :
                return " No "
    return " Yes "
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 1 ]
    N = len ( arr )
    print ( check ( arr , N ) )

Index/key variables: j
Accumulator variables: count
Iterator variables: i, j
Python program:
def countPairsWithDiffK ( arr , N , K ) :
    vis = [ 0 ] * N
    count = 0
    for i in range ( N ) :
        if ( vis [ i ] == 1 ) :
            continue
        for j in range ( i + 1 , N ) :
            if ( vis [ j ] == 1 ) :
                continue
            if ( abs ( arr [ i ] - arr [ j ] ) >= K ) :
                count += 1
                vis [ i ] = 1
                vis [ j ] = 1
                break
    print ( count )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 3 , 3 , 5 ]
    N = len ( arr )
    K = 2
    countPairsWithDiffK ( arr , N , K )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . left = None
        self . right = None
def areMirror ( a , b ) :
    if a is None and b is None :
        return True
    if a is None or b is None :
        return False
    return ( a . data == b . data and areMirror ( a . left , b . right ) and areMirror ( a . right , b . left ) )
root1 = Node ( 1 )
root2 = Node ( 1 )
root1 . left = Node ( 2 )
root1 . right = Node ( 3 )
root1 . left . left = Node ( 4 )
root1 . left . right = Node ( 5 )
root2 . left = Node ( 3 )
root2 . right = Node ( 2 )
root2 . right . left = Node ( 5 )
root2 . right . right = Node ( 4 )
if areMirror ( root1 , root2 ) :
    print ( " Yes " )
else :
    print ( " No " )

Class/struct names: Node
Python program:
def printAlter ( arr , N ) :
    for currIndex in range ( 0 , N , 2 ) :
        print ( arr [ currIndex ] , end = " ▁ " )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 4 , 5 ]
    N = len ( arr )
    printAlter ( arr , N )

Index/key variables: currIndex
Iterator variables: currIndex
Python program:
from collections import defaultdict
import sys
def longestSubsequence ( a , n ) :
    mp = defaultdict ( lambda : 0 )
    dp = [ 0 for i in range ( n ) ]
    maximum = - sys . maxsize
    for i in range ( n ) :
        if a [ i ] - 1 in mp :
            lastIndex = mp [ a [ i ] - 1 ] - 1
            dp [ i ] = 1 + dp [ lastIndex ]
        else :
            dp [ i ] = 1
        mp [ a [ i ] ] = i + 1
        maximum = max ( maximum , dp [ i ] )
    return maximum
a = [ 3 , 10 , 3 , 11 , 4 , 5 , 6 , 7 , 8 , 12 ]
n = len ( a )
print ( longestSubsequence ( a , n ) )

Index/key variables: i, lastIndex
Iterator variables: i
Python program:
from collections import defaultdict
def longLenSub ( arr , n ) :
    um = defaultdict ( lambda : 0 )
    longLen = 0
    for i in range ( n ) :
        len1 = 0
        if ( arr [ i - 1 ] in um and len1 < um [ arr [ i ] - 1 ] ) :
            len1 = um [ arr [ i ] - 1 ]
        if ( arr [ i ] + 1 in um and len1 < um [ arr [ i ] + 1 ] ) :
            len1 = um [ arr [ i ] + 1 ]
        um [ arr [ i ] ] = len1 + 1
        if longLen < um [ arr [ i ] ] :
            longLen = um [ arr [ i ] ]
    return longLen
arr = [ 1 , 2 , 3 , 4 , 5 , 3 , 2 ]
n = len ( arr )
print ( " Longest ▁ length ▁ subsequence ▁ = " , longLenSub ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
import sys
ct = 0
class newNode :
    def __init__ ( self , x ) :
        self . val = x
        self . left = None
        self . right = None
def find ( root , mx ) :
    global ct
    if ( root == None ) :
        return
    if ( root . val >= mx ) :
        ct += 1
    find ( root . left , max ( mx , root . val ) )
    find ( root . right , max ( mx , root . val ) )
def NodesMaxInPath ( root ) :
    global ct
    find ( root , - sys . maxsize - 1 )
    return ct
if __name__ == ' _ _ main _ _ ' :
    root = newNode ( 3 )
    root . left = newNode ( 2 )
    root . right = newNode ( 5 )
    root . left . left = newNode ( 4 )
    root . right . right = newNode ( 7 )
    answer = NodesMaxInPath ( root )
    print ( answer )

Class/struct names: newNode
Python program:
def findLongestConseqSubseq ( arr , n ) :
    ans = 0
    count = 0
    arr . sort ( )
    v = [ ]
    v . append ( arr [ 0 ] )
    for i in range ( 1 , n ) :
        if ( arr [ i ] != arr [ i - 1 ] ) :
            v . append ( arr [ i ] )
    for i in range ( len ( v ) ) :
        if ( i > 0 and v [ i ] == v [ i - 1 ] + 1 ) :
            count += 1
        else :
            count = 1
        ans = max ( ans , count )
    return ans
arr = [ 1 , 2 , 2 , 3 ]
n = len ( arr )
print ( " Length ▁ of ▁ the ▁ Longest ▁ contiguous ▁ subsequence ▁ is " , findLongestConseqSubseq ( arr , n ) )

Index/key variables: i
Accumulator variables: count, v
Iterator variables: i
Python program:
maxn = int ( 1e6 ) + 5
BITree = [ 0 ] * ( maxn )
def is_prime ( n ) :
    if ( n <= 1 ) :
        return False
    i = 2
    while ( i * i <= n ) :
        if ( n % i == 0 ) :
            return False
        i += 1
    return True
def update_bitree ( index , value ) :
    while ( index <= maxn ) :
        BITree [ index ] += value
        index += ( index & ( - index ) )
def sum_bitree ( index ) :
    s = 0
    while ( index > 0 ) :
        s += BITree [ index ]
        index -= ( index & ( - index ) )
    return s
def countSmallerPrimes ( ar , N ) :
    ans = [ 0 ] * ( N )
    global BITree
    for i in range ( N - 1 , 0 , - 1 ) :
        ans [ i ] = sum_bitree ( ar [ i ] )
        if ( is_prime ( ar [ i ] ) ) :
            update_bitree ( ar [ i ] , 1 )
    ans [ 0 ] = 2
    for i in range ( N ) :
        print ( ans [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    ar = [ 5 , 5 , 17 , 9 , 12 , 15 , 11 , 7 , 39 , 3 ]
    N = len ( ar )
    countSmallerPrimes ( ar , N )

Index/key variables: i, index
Accumulator variables: s
Iterator variables: i
Python program:
def findLIS ( A , n ) :
    hash = dict ( )
    LIS_size , LIS_index = 1 , 0
    hash [ A [ 0 ] ] = 1
    for i in range ( 1 , n ) :
        if A [ i ] - 1 not in hash :
            hash [ A [ i ] - 1 ] = 0
        hash [ A [ i ] ] = hash [ A [ i ] - 1 ] + 1
        if LIS_size < hash [ A [ i ] ] :
            LIS_size = hash [ A [ i ] ]
            LIS_index = A [ i ]
    print ( " LIS _ size ▁ = " , LIS_size )
    print ( " LIS ▁ : ▁ " , end = " " )
    start = LIS_index - LIS_size + 1
    while start <= LIS_index :
        print ( start , end = " ▁ " )
        start += 1
if __name__ == " _ _ main _ _ " :
    A = [ 2 , 5 , 3 , 7 , 4 , 8 , 5 , 13 , 6 ]
    n = len ( A )
    findLIS ( A , n )

Index/key variables: i
Accumulator variables: start
Iterator variables: i
Python program:
def countSubSets ( arr , n ) :
    us = set ( )
    even_count = 0
    for i in range ( n ) :
        if arr [ i ] % 2 == 0 :
            us . add ( arr [ i ] )
    even_count = len ( us )
    return pow ( 2 , even_count ) - 1
arr = [ 4 , 2 , 1 , 9 , 2 , 6 , 5 , 3 ]
n = len ( arr )
print ( " Numbers ▁ of ▁ subset = " , countSubSets ( arr , n ) )

Index/key variables: i
Accumulator variables: us
Iterator variables: i
Python program:
import math as mt
def countWindowDistinct ( win , k ) :
    dist_count = 0
    for i in range ( k ) :
        j = 0
        while j < i :
            if ( win [ i ] == win [ j ] ) :
                break
            else :
                j += 1
        if ( j == i ) :
            dist_count += 1
    return dist_count
def countDistinct ( arr , n , k ) :
    for i in range ( n - k + 1 ) :
        print ( countWindowDistinct ( arr [ i : k + i ] , k ) )
arr = [ 1 , 2 , 1 , 3 , 4 , 2 , 3 ]
k = 4
n = len ( arr )
countDistinct ( arr , n , k )

Index/key variables: i, j
Accumulator variables: dist_count
Iterator variables: i
Python program:
class newNode :
    def __init__ ( self , data ) :
        self . data = data
        self . left = self . right = None
def areMirrors ( root1 , root2 ) :
    st1 = [ ]
    st2 = [ ]
    while ( 1 ) :
        while ( root1 and root2 ) :
            if ( root1 . data != root2 . data ) :
                return " No "
            st1 . append ( root1 )
            st2 . append ( root2 )
            root1 = root1 . left
            root2 = root2 . right
        if ( not ( root1 == None and root2 == None ) ) :
            return " No "
        if ( not len ( st1 ) == 0 and not len ( st2 ) == 0 ) :
            root1 = st1 [ - 1 ]
            root2 = st2 [ - 1 ]
            st1 . pop ( - 1 )
            st2 . pop ( - 1 )
            root1 = root1 . right
            root2 = root2 . left
        else :
            break
    return " Yes "
if __name__ == ' _ _ main _ _ ' :
    root1 = newNode ( 1 )
    root1 . left = newNode ( 3 )
    root1 . right = newNode ( 2 )
    root1 . right . left = newNode ( 5 )
    root1 . right . right = newNode ( 4 )
    root2 = newNode ( 1 )
    root2 . left = newNode ( 2 )
    root2 . right = newNode ( 3 )
    root2 . left . left = newNode ( 4 )
    root2 . left . right = newNode ( 5 )
    print ( areMirrors ( root1 , root2 ) )

Accumulator variables: st1, st2
Class/struct names: newNode
Python program:
def maximumSum ( a , b , n , index , lastpicked , dp ) :
    if ( index == n ) :
        return 0
    if ( dp [ index ] [ lastpicked + 1 ] != - 1 ) :
        return dp [ index ] [ lastpicked + 1 ]
    option1 , option2 = 0 , 0
    if ( lastpicked == - 1 or a [ lastpicked ] != a [ index ] ) :
        option1 = ( b [ index ] + maximumSum ( a , b , n , index + 1 , index , dp ) )
    option2 = maximumSum ( a , b , n , index + 1 , lastpicked , dp )
    dp [ index ] [ lastpicked + 1 ] = max ( option1 , option2 )
    return dp [ index ] [ lastpicked + 1 ]
def maximumPoints ( arr , brr , n ) :
    index = 0
    lastPicked = - 1
    dp = [ [ - 1 for x in range ( n + 5 ) ] for y in range ( n + 5 ) ]
    print ( maximumSum ( arr , brr , n , index , lastPicked , dp ) )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 , 3 , 3 , 1 ]
    brr = [ - 1 , 2 , 10 , 20 , - 10 , - 9 ]
    N = len ( arr )
    maximumPoints ( arr , brr , N )

Index/key variables: index, lastpicked
Python program:
def returnMaxSum ( A , B , n ) :
    mp = set ( )
    result = 0
    curr_sum = curr_begin = 0
    for i in range ( 0 , n ) :
        while A [ i ] in mp :
            mp . remove ( A [ curr_begin ] )
            curr_sum -= B [ curr_begin ]
            curr_begin += 1
        mp . add ( A [ i ] )
        curr_sum += B [ i ]
        result = max ( result , curr_sum )
    return result
if __name__ == " _ _ main _ _ " :
    A = [ 0 , 1 , 2 , 3 , 0 , 1 , 4 ]
    B = [ 9 , 8 , 1 , 2 , 3 , 4 , 5 ]
    n = len ( A )
    print ( returnMaxSum ( A , B , n ) )

Index/key variables: curr_begin, i
Accumulator variables: curr_sum, mp
Iterator variables: i