dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def findValue ( R , C ) :
    k = ( R * ( R - 1 ) ) // 2 + 1
    diff = R + 1
    for i in range ( 1 , C ) :
        k = ( k + diff )
        diff += 1
    return k
if __name__ == " _ _ main _ _ " :
    R = 4
    C = 4
    k = findValue ( R , C )
    print ( k )

Accumulator variables: diff
Iterator variables: i
Python program:
def makeGroups ( a , n ) :
    v = [ 0 ] * ( n + 1 )
    for i in range ( n ) :
        v [ a [ i ] ] += 1
    no_of_groups = 0
    for i in range ( 1 , n + 1 ) :
        no_of_groups += v [ i ] // i
        v [ i ] = v [ i ] % i
    i = 1
    total = 0
    for i in range ( 1 , n + 1 ) :
        if ( v [ i ] != 0 ) :
            total = v [ i ]
            break
    i += 1
    while ( i <= n ) :
        if ( v [ i ] != 0 ) :
            total += v [ i ]
            if ( total >= i ) :
                rem = total - i
                no_of_groups += 1
                total = rem
        i += 1
    print ( no_of_groups )
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 3 , 1 , 2 , 2 ]
    size = len ( arr )
    makeGroups ( arr , size )

Index/key variables: i
Accumulator variables: no_of_groups, total
Iterator variables: i
Python program:
N = 3
M = 4
def findColumn ( mat : list ) -> int :
    row = 0
    col = M - 1
    while row < N and col >= 0 :
        if mat [ row ] [ col ] == 1 :
            col -= 1
            flag = 1
        else :
            row += 1
    col += 1
    if flag :
        return col + 1
    else :
        return - 1
if __name__ == " _ _ main _ _ " :
    mat = [ [ 0 , 0 , 0 , 1 ] , [ 0 , 1 , 1 , 1 ] , [ 0 , 0 , 1 , 1 ] ]
    print ( findColumn ( mat ) )

Index/key variables: col, row
Python program:
def findNumbers ( N , M ) :
    m = M
    remLen = { }
    for len1 in range ( 1 , N + 1 , 1 ) :
        remainder = M % N
        if ( remLen . get ( remainder ) == None ) :
            remLen [ remainder ] = len1
        else :
            break
        M = M * 10 + m
        M = M % N
    LenA = len1
    LenB = remLen [ remainder ]
    for i in range ( LenB ) :
        print ( m , end = " " )
    print ( " ▁ " , end = " " )
    for i in range ( LenA ) :
        print ( m , end = " " )
    return
if __name__ == ' _ _ main _ _ ' :
    N = 8
    M = 2
    findNumbers ( N , M )

Index/key variables: remainder
Iterator variables: i, len1
Python program:
prefix_2D = [ [ 0 for x in range ( 2005 ) ] for y in range ( 2005 ) ]
def subMatrixSum ( i , j , length ) :
    return ( prefix_2D [ i ] [ j ] - prefix_2D [ i ] [ j - length ] - prefix_2D [ i - length ] [ j ] + prefix_2D [ i - length ] [ j - length ] )
def numberOfWays ( a , b , n , m , k ) :
    for i in range ( 1 , n + 1 ) :
        for j in range ( 1 , m + 1 ) :
            if ( a [ i - 1 ] == b [ j - 1 ] ) :
                prefix_2D [ i ] [ j ] = 1
            else :
                prefix_2D [ i ] [ j ] = 0
    for i in range ( 1 , n + 1 ) :
        for j in range ( 1 , m + 1 ) :
            prefix_2D [ i ] [ j ] += prefix_2D [ i ] [ j - 1 ]
    for i in range ( 1 , n + 1 ) :
        for j in range ( 1 , m + 1 ) :
            prefix_2D [ i ] [ j ] += prefix_2D [ i - 1 ] [ j ]
    answer = 0
    for i in range ( 1 , n + 1 ) :
        for j in range ( 1 , m + 1 ) :
            low = 1
            high = min ( i , j )
            while ( low < high ) :
                mid = ( low + high ) >> 1
                if ( subMatrixSum ( i , j , mid ) >= k ) :
                    high = mid
                else :
                    low = mid + 1
            if ( subMatrixSum ( i , j , low ) >= k ) :
                answer += ( min ( i , j ) - low + 1 )
    return answer
if __name__ == " _ _ main _ _ " :
    N = 2
    M = 3
    A = [ 1 , 2 ]
    B = [ 1 , 2 , 3 ]
    K = 1
    print ( numberOfWays ( A , B , N , M , K ) )

Index/key variables: i, j
Accumulator variables: answer
Iterator variables: i, j
Python program:
def findSmallest ( s ) :
    length = len ( s ) ;
    loccur = [ - 1 ] * 26 ;
    for i in range ( length - 1 , - 1 , - 1 ) :
        chI = ord ( s [ i ] ) - ord ( ' a ' ) ;
        if ( loccur [ chI ] == - 1 ) :
            loccur [ chI ] = i ;
    sorted_s = s ;
    sorted_s . sort ( ) ;
    for i in range ( length ) :
        if ( s [ i ] != sorted_s [ i ] ) :
            chI = ord ( sorted_s [ i ] ) - ord ( ' a ' ) ;
            last_occ = loccur [ chI ] ;
            s [ i ] , s [ last_occ ] = s [ last_occ ] , s [ i ]
            break ;
    return " " . join ( s ) ;
if __name__ == " _ _ main _ _ " :
    s = " geeks " ;
    print ( findSmallest ( list ( s ) ) ) ;

Index/key variables: chI, i, last_occ
Iterator variables: i
Python program:
def preProcess ( mat , aux ) :
    for i in range ( 5 ) :
        aux [ 0 ] [ i ] = mat [ 0 ] [ i ]
    for i in range ( 1 , 4 ) :
        for j in range ( 5 ) :
            aux [ i ] [ j ] = ( mat [ i ] [ j ] + aux [ i - 1 ] [ j ] )
    for i in range ( 4 ) :
        for j in range ( 1 , 5 ) :
            aux [ i ] [ j ] += aux [ i ] [ j - 1 ]
    return aux
def sumQuery ( aux , tli , tlj , rbi , rbj ) :
    res = aux [ rbi ] [ rbj ]
    if ( tli > 0 ) :
        res = res - aux [ tli - 1 ] [ rbj ]
    if ( tlj > 0 ) :
        res = res - aux [ rbi ] [ tlj - 1 ]
    if ( tli > 0 and tlj > 0 ) :
        res = res + aux [ tli - 1 ] [ tlj - 1 ]
    return res
def check ( mid , aux , K ) :
    satisfies = True
    for x in range ( 4 ) :
        for y in range ( 5 ) :
            if ( x + mid - 1 <= 4 - 1 and y + mid - 1 <= 5 - 1 ) :
                if ( sumQuery ( aux , x , y , x + mid - 1 , y + mid - 1 ) > K ) :
                    satisfies = False
    return True if satisfies == True else False
def maximumSquareSize ( mat , K ) :
    aux = [ [ 0 for i in range ( 5 ) ] for i in range ( 4 ) ]
    aux = preProcess ( mat , aux )
    low , high = 1 , min ( 4 , 5 )
    mid = 0
    while ( high - low > 1 ) :
        mid = ( low + high ) // 2
        if ( check ( mid , aux , K ) ) :
            low = mid
        else :
            high = mid
    if ( check ( high , aux , K ) ) :
        return high
    return low
if __name__ == ' _ _ main _ _ ' :
    K = 30
    mat = [ [ 1 , 2 , 3 , 4 , 6 ] , [ 5 , 3 , 8 , 1 , 2 ] , [ 4 , 6 , 7 , 5 , 5 ] , [ 2 , 4 , 8 , 9 , 4 ] ]
    print ( maximumSquareSize ( mat , K ) )

Index/key variables: i, j, rbi, rbj
Iterator variables: i, j, x, y
Boolean variables: satisfies
Python program:
segment_tree = [ 0 ] * ( 4 * 1000000 ) ;
def build ( A , start , end , node ) :
    if ( start == end ) :
        segment_tree [ node ] = A [ start ] ;
    else :
        mid = ( start + end ) // 2 ;
        segment_tree [ node ] = max ( build ( A , start , mid , 2 * node + 1 ) , build ( A , mid + 1 , end , 2 * node + 2 ) ) ;
    return segment_tree [ node ] ;
def query ( start , end , l , r , node ) :
    if ( start > r or end < l ) :
        return - 1 ;
    if ( start >= l and end <= r ) :
        return segment_tree [ node ] ;
    mid = ( start + end ) // 2 ;
    return max ( query ( start , mid , l , r , 2 * node + 1 ) , query ( mid + 1 , end , l , r , 2 * node + 2 ) ) ;
def longestSubArray ( A , N , K ) :
    res = 1 ;
    preSum = [ 0 ] * ( N + 1 ) ;
    preSum [ 0 ] = A [ 0 ] ;
    for i in range ( N ) :
        preSum [ i + 1 ] = preSum [ i ] + A [ i ] ;
    build ( A , 0 , N - 1 , 0 ) ;
    for i in range ( N ) :
        start = i ;
        end = N - 1 ;
        max_index = i ;
        while ( start <= end ) :
            mid = ( start + end ) // 2 ;
            max_element = query ( 0 , N - 1 , i , mid , 0 ) ;
            expected_sum = ( mid - i + 1 ) * max_element ;
            actual_sum = preSum [ mid + 1 ] - preSum [ i ] ;
            if ( expected_sum - actual_sum <= K ) :
                start = mid + 1 ;
                max_index = max ( max_index , mid ) ;
            else :
                end = mid - 1 ;
        res = max ( res , max_index - i + 1 ) ;
    return res ;
if __name__ == " _ _ main _ _ " :
    arr = [ 2 , 0 , 4 , 6 , 7 ] ; K = 6 ;
    N = len ( arr ) ;
    print ( longestSubArray ( arr , N , K ) ) ;

Index/key variables: i, node, start
Iterator variables: i
Python program:
def countNums ( l , r ) :
    cnt = 0 ;
    for i in range ( l , r + 1 ) :
        lastDigit = ( i % 10 ) ;
        if ( ( lastDigit % 10 ) == 2 or ( lastDigit % 10 ) == 3 or ( lastDigit % 10 ) == 9 ) :
            cnt += 1 ;
    return cnt ;
if __name__ == " _ _ main _ _ " :
    l = 11 ; r = 33 ;
    print ( countNums ( l , r ) ) ;

Accumulator variables: cnt
Iterator variables: i
Python program:
def findMinimumK ( a , n , s ) :
    maximum = a [ 0 ]
    for i in range ( n ) :
        maximum = max ( maximum , a [ i ] )
    low = 1
    high = maximum + 1
    ans = high
    while ( low <= high ) :
        mid = ( low + high ) // 2
        sum = 0
        for i in range ( n ) :
            sum += ( a [ i ] // mid )
        if ( sum > s ) :
            low = mid + 1
        else :
            ans = min ( ans , mid )
            high = mid - 1
    return ans
a = [ 10 , 7 , 8 , 10 , 12 , 19 ]
n = len ( a )
s = 27
print ( findMinimumK ( a , n , s ) )

Index/key variables: i
Accumulator variables: sum
Iterator variables: i
Python program:
def partition ( arr , low , high ) :
    pivot = arr [ high ]
    i = ( low - 1 )
    for j in range ( low , high ) :
        if arr [ j ] <= pivot :
            i += 1
            arr [ i ] , arr [ j ] = arr [ j ] , arr [ i ]
    arr [ i + 1 ] , arr [ high ] = arr [ high ] , arr [ i + 1 ]
    return ( i + 1 )
def kthSmallest ( a , left , right , k ) :
    while left <= right :
        pivotIndex = partition ( a , left , right )
        if pivotIndex == k - 1 :
            return a [ pivotIndex ]
        elif pivotIndex > k - 1 :
            right = pivotIndex - 1
        else :
            left = pivotIndex + 1
    return - 1
arr = [ 10 , 4 , 5 , 8 , 11 , 6 , 26 ]
n = len ( arr )
k = 5
print ( " K - th ▁ smallest ▁ element ▁ is " , kthSmallest ( arr , 0 , n - 1 , k ) )

Index/key variables: high, i, j, pivotIndex
Iterator variables: j
Python program:
def Max_Sum ( arr , n , k ) :
    p = n
    arr . sort ( )
    for i in range ( 0 , n ) :
        if ( arr [ i ] >= k ) :
            p = i
            break
    maxsum = 0
    a = 0
    b = 0
    for i in range ( 0 , p ) :
        for j in range ( i + 1 , p ) :
            if ( arr [ i ] + arr [ j ] < k and arr [ i ] + arr [ j ] > maxsum ) :
                maxsum = arr [ i ] + arr [ j ]
                a = arr [ i ]
                b = arr [ j ]
    print ( a , b )
arr = [ 5 , 20 , 110 , 100 , 10 ]
k = 85
n = len ( arr )
Max_Sum ( arr , n , k )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def isPalindrome ( str , i , j ) :
    while ( i < j ) :
        if ( str [ i ] != str [ j ] ) :
            return False ;
        i += 1 ;
        j -= 1 ;
    return True ;
def maxLenPalindrome ( str , n , ch ) :
    maxLen = 0 ;
    for i in range ( n ) :
        if ( str [ i ] == ch ) :
            for j in range ( n - 1 , i + 1 , - 1 ) :
                if ( str [ j ] == ch ) :
                    if ( isPalindrome ( str , i , j ) ) :
                        maxLen = max ( maxLen , j - i + 1 ) ;
                        break ;
    return maxLen ;
str = " lapqooqpqpl " ;
n = len ( str ) ;
ch = ' p ' ;
print ( maxLenPalindrome ( str , n , ch ) ) ;

Index/key variables: i, j
Iterator variables: i, j
Python program:
MAX = 26
def countingsort ( s ) :
    count = [ 0 for i in range ( MAX ) ]
    for i in range ( len ( s ) ) :
        count [ ord ( s [ i ] ) - ord ( ' a ' ) ] += 1
    index = 0
    for i in range ( MAX ) :
        j = 0
        while ( j < count [ i ] ) :
            s = s . replace ( s [ index ] , chr ( 97 + i ) )
            index += 1
            j += 1
def isPossible ( v , str1 ) :
    countingsort ( str1 ) ;
    for i in range ( len ( v ) - 1 ) :
        for j in range ( i + 1 , len ( v ) , 1 ) :
            temp = v [ i ] + v [ j ]
            countingsort ( temp )
            if ( temp == str1 ) :
                return False
    return True
if __name__ == ' _ _ main _ _ ' :
    str1 = " amazon "
    v = [ " fds " , " oxq " , " zoa " , " epw " , " amn " ]
    if ( isPossible ( v , str1 ) ) :
        print ( " Yes " )
    else :
        print ( " No " )

Index/key variables: i, index, j
Iterator variables: i, j
Python program:
MAX = 256
freq = [ [ 0 for i in range ( MAX ) ] for j in range ( MAX ) ]
def preCalculate ( string , n ) :
    freq [ ord ( string [ 0 ] ) ] [ 0 ] = 1
    for i in range ( 1 , n ) :
        ch = string [ i ]
        for j in range ( MAX ) :
            charToUpdate = chr ( j )
            if charToUpdate == ch :
                freq [ j ] [ i ] = freq [ j ] [ i - 1 ] + 1
            else :
                freq [ j ] [ i ] = freq [ j ] [ i - 1 ]
def getFrequency ( ch , l , r ) :
    if l == 0 :
        return freq [ ord ( ch ) ] [ r ]
    else :
        return ( freq [ ord ( ch ) ] [ r ] - freq [ ord ( ch ) ] [ l - 1 ] )
def firstNonRepeating ( string , n , l , r ) :
    t = [ " " ] * 2
    for i in range ( l , r ) :
        ch = string [ i ]
        if getFrequency ( ch , l , r ) == 1 :
            t [ 0 ] = ch
            return t [ 0 ]
    return " - 1"
if __name__ == " _ _ main _ _ " :
    string = " GeeksForGeeks "
    n = len ( string )
    queries = [ ( 0 , 3 ) , ( 2 , 3 ) , ( 5 , 12 ) ]
    q = len ( queries )
    preCalculate ( string , n )
    for i in range ( q ) :
        print ( firstNonRepeating ( string , n , queries [ i ] [ 0 ] , queries [ i ] [ 1 ] ) )

Index/key variables: i, j, r
Iterator variables: i, j
Python program:
NO_OF_CHARS = 256
def firstRepeating ( string ) :
    visited = [ False ] * NO_OF_CHARS ;
    for i in range ( NO_OF_CHARS ) :
        visited [ i ] = False ;
    res = - 1 ;
    for i in range ( len ( string ) - 1 , - 1 , - 1 ) :
        if ( visited [ string . index ( string [ i ] ) ] == False ) :
            visited [ string . index ( string [ i ] ) ] = True ;
        else :
            res = i ;
    return res ;
if __name__ == " _ _ main _ _ " :
    string = " geeksforgeeks " ;
    index = firstRepeating ( string ) ;
    if ( index == - 1 ) :
        print ( " Either ▁ all ▁ characters ▁ are " , " distinct ▁ or ▁ string ▁ is ▁ empty " ) ;
    else :
        print ( " First ▁ Repeating ▁ character ▁ is : " , string [ index ] ) ;

Index/key variables: i, index
Iterator variables: i
Python program:
def maxSum ( arr , n , K ) :
    maximum = - 2 ** 32 ;
    sum = [ 0 ] * n
    for i in range ( n - 1 , - 1 , - 1 ) :
        if ( i + K < n ) :
            sum [ i ] = sum [ i + K ] + arr [ i ]
        else :
            sum [ i ] = arr [ i ] ;
        maximum = max ( maximum , sum [ i ] )
    return maximum ;
arr = [ 3 , 6 , 4 , 7 , 2 ]
n = len ( arr ) ;
K = 2
print ( maxSum ( arr , n , K ) )

Index/key variables: i
Iterator variables: i
Python program:
def countPairs ( s1 , n1 , s2 , n2 ) :
    freq1 = [ 0 ] * 26 ;
    freq2 = [ 0 ] * 26 ;
    count = 0 ;
    for i in range ( n1 ) :
        freq1 [ ord ( s1 [ i ] ) - ord ( ' a ' ) ] += 1 ;
    for i in range ( n2 ) :
        freq2 [ ord ( s2 [ i ] ) - ord ( ' a ' ) ] += 1 ;
    for i in range ( 26 ) :
        count += min ( freq1 [ i ] , freq2 [ i ] ) ;
    return count ;
if __name__ == " _ _ main _ _ " :
    s1 = " geeksforgeeks " ;
    s2 = " platformforgeeks " ;
    n1 = len ( s1 ) ;
    n2 = len ( s2 ) ;
    print ( countPairs ( s1 , n1 , s2 , n2 ) ) ;

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def findpair ( l , r ) :
    c = 0
    for i in range ( l , r + 1 ) :
        for j in range ( i + 1 , r + 1 ) :
            if ( j % i == 0 and j != i ) :
                print ( i , " , ▁ " , j )
                c = 1
                break
        if ( c == 1 ) :
            break
if __name__ == " _ _ main _ _ " :
    l = 1
    r = 10
    findpair ( l , r )

Iterator variables: i, j
Python program:
def check ( arr , N , K ) :
    unique = dict ( )
    for i in range ( N ) :
        unique [ arr [ i ] ] = 1
    if len ( unique ) == K :
        return True
    return False
arr = [ 1 , 1 , 2 , 3 ]
N = len ( arr )
K = 3
if ( check ( arr , N , K ) == True ) :
    print ( " Yes " )
else :
    print ( " No " )

Index/key variables: i
Iterator variables: i
Python program:
def findSumPairs ( a , n ) :
    mpp = { i : 0 for i in range ( 21 ) }
    for i in range ( n - 1 ) :
        for j in range ( i + 1 , n , 1 ) :
            mpp [ a [ i ] + a [ j ] ] += 1
    occur = 0
    for key , value in mpp . items ( ) :
        if ( value > occur ) :
            occur = value
    for key , value in mpp . items ( ) :
        if ( value == occur ) :
            print ( key )
if __name__ == ' _ _ main _ _ ' :
    a = [ 1 , 8 , 3 , 11 , 4 , 9 , 2 , 7 ]
    n = len ( a )
    findSumPairs ( a , n )

Index/key variables: i, j
Iterator variables: i, j, key, value
Python program:
def minIndex ( arr , n , pos ) :
    num = arr [ pos ]
    i = pos - 1
    while ( i >= 0 ) :
        if ( arr [ i ] != num ) :
            break
        i -= 1
    return i + 1
arr = [ 2 , 1 , 1 , 1 , 5 , 2 ]
n = len ( arr )
pos = 4
print ( minIndex ( arr , n , pos ) )

Index/key variables: i, pos
Python program:
def minIndex ( arr , pos ) :
    low = 0
    high = pos
    i = pos
    while low < high :
        mid = ( low + high ) // 2
        if arr [ mid ] != arr [ pos ] :
            low = mid + 1
        else :
            high = mid - 1
            i = mid
            if mid > 0 and arr [ mid - 1 ] != arr [ pos ] :
                break
    return low if arr [ low ] == arr [ pos ] else i
arr = [ 2 , 1 , 1 , 1 , 5 , 2 ]

Index/key variables: low, mid, pos
Python program:
def findMinDifference ( arr , n ) :
    if ( arr [ 0 ] < arr [ 1 ] ) :
        min__ = secondMax = arr [ 0 ]
    else :
        min__ = secondMax = arr [ 1 ]
    if ( arr [ 0 ] < arr [ 1 ] ) :
        max__ = secondMin = arr [ 1 ]
    else :
        max__ = secondMin = arr [ 0 ]
    for i in range ( 2 , n ) :
        if ( arr [ i ] > max__ ) :
            secondMax = max__
            max__ = arr [ i ]
        elif ( arr [ i ] > secondMax ) :
            secondMax = arr [ i ]
        elif ( arr [ i ] < min__ ) :
            secondMin = min__
            min__ = arr [ i ]
        elif ( arr [ i ] < secondMin ) :
            secondMin = arr [ i ]
    diff = min ( max__ - secondMin , secondMax - min__ )
    return diff
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 4 , 3 , 4 ]
    n = len ( arr )
    print ( findMinDifference ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def checkDistinct ( x ) :
    last = x % 10
    while ( x ) :
        if ( x % 10 != last ) :
            return False
        x = x // 10
    return True
def findCount ( L , R ) :
    count = 0
    for i in range ( L , R + 1 ) :
        if ( checkDistinct ( i ) ) :
            count += 1
    return count
L = 10
R = 50
print ( findCount ( L , R ) )

Accumulator variables: count
Iterator variables: i
Python program:
import sys
def smallest_pair ( a , n ) :
    min = sys . maxsize
    secondMin = sys . maxsize
    for j in range ( n ) :
        if ( a [ j ] < min ) :
            secondMin = min
            min = a [ j ]
        elif ( ( a [ j ] < secondMin ) and a [ j ] != min ) :
            secondMin = a [ j ]
    return ( secondMin + min )
if __name__ == " _ _ main _ _ " :
    arr = [ 1 , 2 , 3 ]
    n = len ( arr )
    print ( smallest_pair ( arr , n ) )

Index/key variables: j
Iterator variables: j
Python program:
def longestsubarray ( arr , n , k ) :
    current_count = 0
    max_count = 0
    for i in range ( 0 , n , 1 ) :
        if ( arr [ i ] % k == 0 ) :
            current_count += 1
        else :
            current_count = 0
        max_count = max ( current_count , max_count )
    return max_count
if __name__ == ' _ _ main _ _ ' :
    arr = [ 2 , 5 , 11 , 32 , 64 , 88 ]
    n = len ( arr )
    k = 8
    print ( longestsubarray ( arr , n , k ) )

Index/key variables: i
Accumulator variables: current_count
Iterator variables: i
Python program:
def removeElements ( arr , n , k ) :
    mp = dict ( )
    for i in range ( n ) :
        mp [ arr [ i ] ] = mp . get ( arr [ i ] , 0 ) + 1
    for i in range ( n ) :
        if ( arr [ i ] in mp and mp [ arr [ i ] ] >= k ) :
            print ( arr [ i ] , end = " ▁ " )
arr = [ 1 , 2 , 2 , 3 , 2 , 3 , 4 ]
n = len ( arr )
k = 2
removeElements ( arr , n , k )

Index/key variables: i
Iterator variables: i
Python program:
def check ( s ) :
    for i in range ( 0 , len ( s ) ) :
        if ( s [ i ] == s [ i + 1 ] ) :
            return True
    return False
s = " xzyyz "
if ( check ( s ) ) :
    print ( " YES " )
else :
    print ( " NO " )

Index/key variables: i
Iterator variables: i
Python program:
def RemoveElements ( arr , n , k ) :
    mp = { i : 0 for i in range ( len ( arr ) ) }
    for i in range ( n ) :
        mp [ arr [ i ] ] += 1
    for i in range ( n ) :
        if ( mp [ arr [ i ] ] <= k ) :
            print ( arr [ i ] , end = " ▁ " )
if __name__ == ' _ _ main _ _ ' :
    arr = [ 1 , 2 , 2 , 3 , 2 , 3 , 4 ]
    n = len ( arr )
    k = 2
    RemoveElements ( arr , n , k )

Index/key variables: i
Iterator variables: i
Python program:
import math as mt
def findSmallestAfterDel ( arr , m , dell , n ) :
    mp = dict ( )
    for i in range ( n ) :
        if dell [ i ] in mp . keys ( ) :
            mp [ dell [ i ] ] += 1
        else :
            mp [ dell [ i ] ] = 1
    SmallestElement = 10 ** 9
    for i in range ( m ) :
        if ( arr [ i ] in mp . keys ( ) ) :
            mp [ arr [ i ] ] -= 1
            if ( mp [ arr [ i ] ] == 0 ) :
                mp . pop ( arr [ i ] )
        else :
            SmallestElement = min ( SmallestElement , arr [ i ] )
    return SmallestElement
array = [ 5 , 12 , 33 , 4 , 56 , 12 , 20 ]
m = len ( array )
dell = [ 12 , 4 , 56 , 5 ]
n = len ( dell )
print ( findSmallestAfterDel ( array , m , dell , n ) )

Index/key variables: i
Iterator variables: i
Python program:
import math as mt
def findlargestAfterDel ( arr , m , dell , n ) :
    mp = dict ( )
    for i in range ( n ) :
        if dell [ i ] in mp . keys ( ) :
            mp [ dell [ i ] ] += 1
        else :
            mp [ dell [ i ] ] = 1
    largestElement = - 10 ** 9
    for i in range ( m ) :
        if ( arr [ i ] in mp . keys ( ) ) :
            mp [ arr [ i ] ] -= 1
            if ( mp [ arr [ i ] ] == 0 ) :
                mp . pop ( arr [ i ] )
        else :
            largestElement = max ( largestElement , arr [ i ] )
    return largestElement
array = [ 5 , 12 , 33 , 4 , 56 , 12 , 20 ]
m = len ( array )
dell = [ 12 , 33 , 56 , 5 ]
n = len ( dell )
print ( findlargestAfterDel ( array , m , dell , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def countAnomalies ( arr , n , k ) :
    res = 0
    for i in range ( 0 , n ) :
        j = 0
        while j < n :
            if i != j and abs ( arr [ i ] - arr [ j ] ) <= k :
                break
            j += 1
        if j == n :
            res += 1
    return res
if __name__ == " _ _ main _ _ " :
    arr = [ 7 , 1 , 8 ]
    k = 5
    n = len ( arr )
    print ( countAnomalies ( arr , n , k ) )

Index/key variables: i, j
Accumulator variables: res
Iterator variables: i
Python program:
def majorityInMatrix ( arr ) :
    mp = { i : 0 for i in range ( 7 ) }
    for i in range ( len ( arr ) ) :
        for j in range ( len ( arr ) ) :
            mp [ arr [ i ] [ j ] ] += 1
    countMajority = 0
    for key , value in mp . items ( ) :
        if ( value >= ( int ( ( N * M ) / 2 ) ) ) :
            countMajority += 1
    return countMajority
if __name__ == ' _ _ main _ _ ' :
    mat = [ [ 1 , 2 , 2 ] , [ 1 , 3 , 2 ] , [ 1 , 2 , 6 ] ]
    print ( majorityInMatrix ( mat ) )

Index/key variables: i, j
Accumulator variables: countMajority
Iterator variables: i, j, key, value