dhyuti-n/xlcost-variable-roles huggingface dataset:
Python program:
def maxWater ( arr , n ) :
    size = n - 1
    prev = arr [ 0 ]
    prev_index = 0
    water = 0
    temp = 0
    for i in range ( 1 , size + 1 ) :
        if ( arr [ i ] >= prev ) :
            prev = arr [ i ]
            prev_index = i
            temp = 0
        else :
            water += prev - arr [ i ]
            temp += prev - arr [ i ]
    if ( prev_index < size ) :
        water -= temp
        prev = arr [ size ]
        for i in range ( size , prev_index - 1 , - 1 ) :
            if ( arr [ i ] >= prev ) :
                prev = arr [ i ]
            else :
                water += prev - arr [ i ]
    return water
arr = [ 0 , 1 , 0 , 2 , 1 , 0 , 1 , 3 , 2 , 1 , 2 , 1 ]
n = len ( arr )
print ( maxWater ( arr , n ) )

Index/key variables: i, size
Accumulator variables: temp, water
Iterator variables: i
Python program:
def maxWater ( height ) :
    stack = [ ]
    n = len ( height )
    ans = 0
    for i in range ( n ) :
        while ( len ( stack ) != 0 and ( height [ stack [ - 1 ] ] < height [ i ] ) ) :
            pop_height = height [ stack [ - 1 ] ]
            stack . pop ( )
            if ( len ( stack ) == 0 ) :
                break
            distance = i - stack [ - 1 ] - 1
            min_height = min ( height [ stack [ - 1 ] ] , height [ i ] ) - pop_height
            ans += distance * min_height
        stack . append ( i )
    return ans
arr = [ 0 , 1 , 0 , 2 , 1 , 0 , 1 , 3 , 2 , 1 , 2 , 1 ]
print ( maxWater ( arr ) )

Index/key variables: i
Accumulator variables: ans, stack
Iterator variables: i
Python program:
def maxWater ( arr , n ) :
    left = 0
    right = n - 1
    l_max = 0
    r_max = 0
    result = 0
    while ( left <= right ) :
        if r_max <= l_max :
            result += max ( 0 , r_max - arr [ right ] )
            r_max = max ( r_max , arr [ right ] )
            right -= 1
        else :
            result += max ( 0 , l_max - arr [ left ] )
            l_max = max ( l_max , arr [ left ] )
            left += 1
    return result
arr = [ 0 , 1 , 0 , 2 , 1 , 0 , 1 , 3 , 2 , 1 , 2 , 1 ]
n = len ( arr )
print ( maxWater ( arr , n ) )

Index/key variables: left, right
Accumulator variables: result
Python program:
median = 0
i = 0
j = 0
def maximum ( a , b ) :
    return a if a > b else b
def minimum ( a , b ) :
    return a if a < b else b
def findMedianSortedArrays ( a , n , b , m ) :
    global median , i , j
    min_index = 0
    max_index = n
    while ( min_index <= max_index ) :
        i = int ( ( min_index + max_index ) / 2 )
        j = int ( ( ( n + m + 1 ) / 2 ) - i )
        if ( i < n and j > 0 and b [ j - 1 ] > a [ i ] ) :
            min_index = i + 1
        elif ( i > 0 and j < m and b [ j ] < a [ i - 1 ] ) :
            max_index = i - 1
        else :
            if ( i == 0 ) :
                median = b [ j - 1 ]
            elif ( j == 0 ) :
                median = a [ i - 1 ]
            else :
                median = maximum ( a [ i - 1 ] , b [ j - 1 ] )
            break
    if ( ( n + m ) % 2 == 1 ) :
        return median
    if ( i == n ) :
        return ( ( median + b [ j ] ) / 2.0 )
    if ( j == m ) :
        return ( ( median + a [ i ] ) / 2.0 )
    return ( ( median + minimum ( a [ i ] , b [ j ] ) ) / 2.0 )
a = [ 900 ]
b = [ 10 , 13 , 14 ]
n = len ( a )
m = len ( b )
if ( n < m ) :
    print ( " The ▁ median ▁ is ▁ : ▁ { } " . format ( findMedianSortedArrays ( a , n , b , m ) ) )
else :
    echo ( " The ▁ median ▁ is ▁ : ▁ { } " . format ( findMedianSortedArrays ( b , m , a , n ) ) )

Index/key variables: i, j
Python program:
def findMedianSortedArrays ( a , n , b , m ) :
    min_index = 0
    max_index = n
    while ( min_index <= max_index ) :
        i = ( min_index + max_index ) // 2
        j = ( ( n + m + 1 ) // 2 ) - i
        if ( i < n and j > 0 and b [ j - 1 ] > a [ i ] ) :
            min_index = i + 1
        elif ( i > 0 and j < m and b [ j ] < a [ i - 1 ] ) :
            max_index = i - 1
        else :
            if ( i == 0 ) :
                return b [ j - 1 ]
            if ( j == 0 ) :
                return a [ i - 1 ]
            else :
                return maximum ( a [ i - 1 ] , b [ j - 1 ] )
    print ( " ERROR ! ! ! ▁ " ,   " returning " )
    return 0
def maximum ( a , b ) :
    return a if a > b else b
if __name__ == " _ _ main _ _ " :
    a = [ 900 ]
    b = [ 10 , 13 , 14 ]
    n = len ( a )
    m = len ( b )
    if ( n < m ) :
        print ( " The ▁ median ▁ is : ▁ " , findMedianSortedArrays ( a , n , b , m ) )
    else :
        print ( " The ▁ median ▁ is : ▁ " , findMedianSortedArrays ( b , m , a , n ) )

Index/key variables: i, j
Python program:
def printUncommon ( arr1 , arr2 , n1 , n2 ) :
    i = 0
    j = 0
    k = 0
    while ( i < n1 and j < n2 ) :
        if ( arr1 [ i ] < arr2 [ j ] ) :
            print ( arr1 [ i ] , end = " ▁ " )
            i = i + 1
            k = k + 1
        elif ( arr2 [ j ] < arr1 [ i ] ) :
            print ( arr2 [ j ] , end = " ▁ " )
            k = k + 1
            j = j + 1
        else :
            i = i + 1
            j = j + 1
    while ( i < n1 ) :
        print ( arr1 [ i ] , end = " ▁ " )
        i = i + 1
        k = k + 1
    while ( j < n2 ) :
        print ( arr2 [ j ] , end = " ▁ " )
        j = j + 1
        k = k + 1
arr1 = [ 10 , 20 , 30 ]
arr2 = [ 20 , 25 , 30 , 40 , 50 ]
n1 = len ( arr1 )
n2 = len ( arr2 )
printUncommon ( arr1 , arr2 , n1 , n2 )

Index/key variables: i, j
Python program:
def leastFrequent ( arr , n ) :
    arr . sort ( )
    min_count = n + 1
    res = - 1
    curr_count = 1
    for i in range ( 1 , n ) :
        if ( arr [ i ] == arr [ i - 1 ] ) :
            curr_count = curr_count + 1
        else :
            if ( curr_count < min_count ) :
                min_count = curr_count
                res = arr [ i - 1 ]
            curr_count = 1
    if ( curr_count < min_count ) :
        min_count = curr_count
        res = arr [ n - 1 ]
    return res
arr = [ 1 , 3 , 2 , 1 , 2 , 2 , 3 , 1 ]
n = len ( arr )
print ( leastFrequent ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
import math as mt
def leastFrequent ( arr , n ) :
    Hash = dict ( )
    for i in range ( n ) :
        if arr [ i ] in Hash . keys ( ) :
            Hash [ arr [ i ] ] += 1
        else :
            Hash [ arr [ i ] ] = 1
    min_count = n + 1
    res = - 1
    for i in Hash :
        if ( min_count >= Hash [ i ] ) :
            res = i
            min_count = Hash [ i ]
    return res
arr = [ 1 , 3 , 2 , 1 , 2 , 2 , 3 , 1 ]
n = len ( arr )
print ( leastFrequent ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
M = 4 ;
def maximumSum ( a , n ) :
    global M ;
    for i in range ( 0 , n ) :
        a [ i ] . sort ( ) ;
    sum = a [ n - 1 ] [ M - 1 ] ;
    prev = a [ n - 1 ] [ M - 1 ] ;
    for i in range ( n - 2 , - 1 , - 1 ) :
        for j in range ( M - 1 , - 1 , - 1 ) :
            if ( a [ i ] [ j ] < prev ) :
                prev = a [ i ] [ j ] ;
                sum += prev ;
                break ;
        if ( j == - 1 ) :
            return 0 ;
    return sum ;
arr = [ [ 1 , 7 , 3 , 4 ] , [ 4 , 2 , 5 , 1 ] , [ 9 , 5 , 1 , 8 ] ] ;
n = len ( arr ) ;
print ( maximumSum ( arr , n ) ) ;

Index/key variables: i, j
Accumulator variables: sum
Iterator variables: i, j
Python program:
M = 4
def maximumSum ( a , n ) :
    prev = max ( max ( a ) )
    Sum = prev
    for i in range ( n - 2 , - 1 , - 1 ) :
        max_smaller = - 10 ** 9
        for j in range ( M - 1 , - 1 , - 1 ) :
            if ( a [ i ] [ j ] < prev and a [ i ] [ j ] > max_smaller ) :
                max_smaller = a [ i ] [ j ]
        if ( max_smaller == - 10 ** 9 ) :
            return 0
        prev = max_smaller
        Sum += max_smaller
    return Sum
arr = [ [ 1 , 7 , 3 , 4 ] , [ 4 , 2 , 5 , 1 ] , [ 9 , 5 , 1 , 8 ] ]
n = len ( arr )
print ( maximumSum ( arr , n ) )

Index/key variables: i, j
Accumulator variables: Sum
Iterator variables: i, j
Python program:
import math
def countPairs ( A , n , k ) :
    ans = 0
    A . sort ( )
    for i in range ( 0 , n ) :
        for j in range ( i + 1 , n ) :
            x = 0
            while ( ( A [ i ] * math . pow ( k , x ) ) <= A [ j ] ) :
                if ( ( A [ i ] * math . pow ( k , x ) ) == A [ j ] ) :
                    ans += 1
                    break
                x += 1
    return ans
A = [ 3 , 8 , 9 , 12 , 18 , 4 , 24 , 2 , 6 ]
n = len ( A )
k = 3
print ( countPairs ( A , n , k ) )

Index/key variables: i, j
Accumulator variables: ans, x
Iterator variables: i, j
Python program:
def minDistance ( arr , n ) :
    maximum_element = arr [ 0 ]
    min_dis = n
    index = 0
    for i in range ( 1 , n ) :
        if ( maximum_element == arr [ i ] ) :
            min_dis = min ( min_dis , ( i - index ) )
            index = i
        elif ( maximum_element < arr [ i ] ) :
            maximum_element = arr [ i ]
            min_dis = n
            index = i
        else :
            continue
    return min_dis
arr = [ 6 , 3 , 1 , 3 , 6 , 4 , 6 ]
n = len ( arr )
print ( " Minimum ▁ distance ▁ = " , minDistance ( arr , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def findValue ( arr , n , k ) :
    for i in range ( n ) :
        if ( arr [ i ] == k ) :
            k = k * 2
    return k
arr = [ 2 , 3 , 4 , 10 , 8 , 1 ]
k = 2
n = len ( arr )
print ( findValue ( arr , n , k ) )

Index/key variables: i
Iterator variables: i
Python program:
def findSmallest ( a , n ) :
    for i in range ( 0 , n ) :
        for j in range ( 0 , n ) :
            if ( ( a [ j ] % a [ i ] ) >= 1 ) :
                break
        if ( j == n - 1 ) :
            return a [ i ]
    return - 1
a = [ 25 , 20 , 5 , 10 , 100 ]
n = len ( a )
print ( findSmallest ( a , n ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def min_element ( a ) :
    m = 10000000
    for i in range ( 0 , len ( a ) ) :
        if ( a [ i ] < m ) :
            m = a [ i ]
    return m
def findSmallest ( a , n ) :
    smallest = min_element ( a )
    for i in range ( 1 , n ) :
        if ( a [ i ] % smallest >= 1 ) :
            return - 1
    return smallest
a = [ 25 , 20 , 5 , 10 , 100 ]
n = len ( a )
print ( findSmallest ( a , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def findIndex ( arr ) :
    maxIndex = 0
    for i in range ( 0 , len ( arr ) ) :
        if ( arr [ i ] > arr [ maxIndex ] ) :
            maxIndex = i
    for i in range ( 0 , len ( arr ) ) :
        if ( maxIndex != i and arr [ maxIndex ] < ( 2 * arr [ i ] ) ) :
            return - 1
    return maxIndex
arr = [ 3 , 6 , 1 , 0 ]
print ( findIndex ( arr ) )

Index/key variables: i, maxIndex
Iterator variables: i
Python program:
import math
def find_consecutive_steps ( arr , len ) :
    count = 0 ; maximum = 0
    for index in range ( 1 , len ) :
        if ( arr [ index ] > arr [ index - 1 ] ) :
            count += 1
        else :
            maximum = max ( maximum , count )
            count = 0
    return max ( maximum , count )
arr = [ 1 , 2 , 3 , 4 ]
len = len ( arr )
print ( find_consecutive_steps ( arr , len ) )

Index/key variables: index
Accumulator variables: count
Iterator variables: index
Python program:
def calculate ( a , n ) :
    a . sort ( ) ;
    s = [ ] ;
    i = 0 ;
    j = n - 1 ;
    while ( i < j ) :
        s . append ( ( a [ i ] + a [ j ] ) ) ;
        i += 1 ;
        j -= 1 ;
    mini = min ( s ) ;
    maxi = max ( s ) ;
    return abs ( maxi - mini ) ;
a = [ 2 , 6 , 4 , 3 ] ;
n = len ( a ) ;
print ( calculate ( a , n ) ) ;

Index/key variables: i, j
Accumulator variables: s
Python program:
def printMinDiffPairs ( arr , n ) :
    if n <= 1 : return
    arr . sort ( )
    minDiff = arr [ 1 ] - arr [ 0 ]
    for i in range ( 2 , n ) :
        minDiff = min ( minDiff , arr [ i ] - arr [ i - 1 ] )
    for i in range ( 1 , n ) :
        if ( arr [ i ] - arr [ i - 1 ] ) == minDiff :
            print ( " ( " + str ( arr [ i - 1 ] ) + " , ▁ " + str ( arr [ i ] ) + " ) , ▁ " , end = ' ' )
arr = [ 5 , 3 , 2 , 4 , 1 ]
n = len ( arr )
printMinDiffPairs ( arr , n )

Index/key variables: i
Iterator variables: i
Python program:
def calculateDiff ( i , j , arr ) :
    return abs ( arr [ i ] - arr [ j ] ) + abs ( i - j )
def maxDistance ( arr , n ) :
    result = 0
    for i in range ( 0 , n ) :
        for j in range ( i , n ) :
            if ( calculateDiff ( i , j , arr ) > result ) :
                result = calculateDiff ( i , j , arr )
    return result
arr = [ - 70 , - 64 , - 6 , - 56 , 64 , 61 , - 57 , 16 , 48 , - 98 ]
n = len ( arr )
print ( maxDistance ( arr , n ) )

Index/key variables: i, j
Iterator variables: i, j
Python program:
def maxDistance ( array ) :
    max1 = - 2147483648
    min1 = + 2147483647
    max2 = - 2147483648
    min2 = + 2147483647
    for i in range ( len ( array ) ) :
        max1 = max ( max1 , array [ i ] + i )
        min1 = min ( min1 , array [ i ] + i )
        max2 = max ( max2 , array [ i ] - i )
        min2 = min ( min2 , array [ i ] - i )
    return max ( max1 - min1 , max2 - min2 )
array = [ - 70 , - 64 , - 6 , - 56 , 64 , 61 , - 57 , 16 , 48 , - 98 ]
print ( maxDistance ( array ) )

Index/key variables: i
Iterator variables: i
Python program:
def extrema ( a , n ) :
    count = 0
    for i in range ( 1 , n - 1 ) :
        count += ( a [ i ] > a [ i - 1 ] and a [ i ] > a [ i + 1 ] ) ;
        count += ( a [ i ] < a [ i - 1 ] and a [ i ] < a [ i + 1 ] ) ;
    return count
a = [ 1 , 0 , 2 , 1 ]
n = len ( a )
print ( extrema ( a , n ) )

Index/key variables: i
Accumulator variables: count
Iterator variables: i
Python program:
def findClosest ( arr , n , target ) :
    if ( target <= arr [ 0 ] ) :
        return arr [ 0 ]
    if ( target >= arr [ n - 1 ] ) :
        return arr [ n - 1 ]
    i = 0 ; j = n ; mid = 0
    while ( i < j ) :
        mid = ( i + j ) // 2
        if ( arr [ mid ] == target ) :
            return arr [ mid ]
        if ( target < arr [ mid ] ) :
            if ( mid > 0 and target > arr [ mid - 1 ] ) :
                return getClosest ( arr [ mid - 1 ] , arr [ mid ] , target )
            j = mid
        else :
            if ( mid < n - 1 and target < arr [ mid + 1 ] ) :
                return getClosest ( arr [ mid ] , arr [ mid + 1 ] , target )
            i = mid + 1
    return arr [ mid ]
def getClosest ( val1 , val2 , target ) :
    if ( target - val1 >= val2 - target ) :
        return val2
    else :
        return val1
arr = [ 1 , 2 , 4 , 5 , 6 , 6 , 8 , 9 ]
n = len ( arr )
target = 11
print ( findClosest ( arr , n , target ) )

Index/key variables: mid
Python program:
def _sum ( a , n ) :
    maxSum = - 9999999
    for i in range ( n ) :
        for j in range ( n ) :
            maxSum = max ( maxSum , a [ i ] + a [ j ] )
    c = 0
    for i in range ( n ) :
        for j in range ( i + 1 , n ) :
            if a [ i ] + a [ j ] == maxSum :
                c += 1
    return c
array = [ 1 , 1 , 1 , 2 , 2 , 2 ]
n = len ( array )
print ( _sum ( array , n ) )

Index/key variables: i, j
Accumulator variables: c
Iterator variables: i, j
Python program:
import sys
def sum ( a , n ) :
    maxVal = a [ 0 ] ; maxCount = 1
    secondMax = sys . maxsize
    for i in range ( 1 , n ) :
        if ( a [ i ] == maxVal ) :
            maxCount += 1
        elif ( a [ i ] > maxVal ) :
            secondMax = maxVal
            secondMaxCount = maxCount
            maxVal = a [ i ]
            maxCount = 1
        elif ( a [ i ] == secondMax ) :
            secondMax = a [ i ]
            secondMaxCount += 1
        elif ( a [ i ] > secondMax ) :
            secondMax = a [ i ]
            secondMaxCount = 1
    if ( maxCount > 1 ) :
        return maxCount * ( maxCount - 1 ) / 2
    return secondMaxCount
array = [ 1 , 1 , 1 , 2 , 2 , 2 , 3 ]
n = len ( array )
print ( sum ( array , n ) )

Index/key variables: i
Accumulator variables: maxCount, secondMaxCount
Iterator variables: i
Python program:
def printKMissing ( arr , n , k ) :
    arr . sort ( )
    i = 0
    while ( i < n and arr [ i ] <= 0 ) :
        i = i + 1
    count = 0
    curr = 1
    while ( count < k and i < n ) :
        if ( arr [ i ] != curr ) :
            print ( str ( curr ) + " ▁ " , end = ' ' )
            count = count + 1
        else :
            i = i + 1
        curr = curr + 1
    while ( count < k ) :
        print ( str ( curr ) + " ▁ " , end = ' ' )
        curr = curr + 1
        count = count + 1
arr = [ 2 , 3 , 4 ]
n = len ( arr )
k = 3
printKMissing ( arr , n , k ) ;

Index/key variables: i
Python program:
def printmissingk ( arr , n , k ) :
    d = { }
    for i in range ( len ( arr ) ) :
        d [ arr [ i ] ] = arr [ i ]
    cnt = 1
    fl = 0
    for i in range ( n + k ) :
        if cnt not in d :
            fl += 1
            print ( cnt , end = " ▁ " )
            if fl == k :
                break
        cnt += 1
    print ( )
arr = [ 1 , 4 , 3 ]
n = len ( arr )
k = 3
printmissingk ( arr , n , k )

Index/key variables: i
Accumulator variables: cnt, fl
Iterator variables: i
Python program:
def nobleInteger ( arr , size ) :
    for i in range ( 0 , size ) :
        count = 0
        for j in range ( 0 , size ) :
            if ( arr [ i ] < arr [ j ] ) :
                count += 1
        if ( count == arr [ i ] ) :
            return arr [ i ]
    return - 1
arr = [ 10 , 3 , 20 , 40 , 2 ]
size = len ( arr )
res = nobleInteger ( arr , size )
if ( res != - 1 ) :
    print ( " The ▁ noble ▁ integer ▁ is ▁ " , res )
else :
    print ( " No ▁ Noble ▁ Integer ▁ Found " )

Index/key variables: i, j
Accumulator variables: count
Iterator variables: i, j
Python program:
def nobleInteger ( arr ) :
    arr . sort ( )
    n = len ( arr )
    for i in range ( n - 1 ) :
        if arr [ i ] == arr [ i + 1 ] :
            continue
        if arr [ i ] == n - i - 1 :
            return arr [ i ]
    if arr [ n - 1 ] == 0 :
        return arr [ n - 1 ]
    return - 1
arr = [ 10 , 3 , 20 , 40 , 2 ]
res = nobleInteger ( arr )
if res != - 1 :
    print ( " The ▁ noble ▁ integer ▁ is " , res )
else :
    print ( " No ▁ Noble ▁ Integer ▁ Found " )

Index/key variables: i
Iterator variables: i
Python program:
def findMinSum ( a , b , n ) :
    a . sort ( )
    b . sort ( )
    sum = 0
    for i in range ( n ) :
        sum = sum + abs ( a [ i ] - b [ i ] )
    return sum
a = [ 4 , 1 , 8 , 7 ]
b = [ 2 , 3 , 6 , 5 ]
n = len ( a )
print ( findMinSum ( a , b , n ) )

Index/key variables: i
Iterator variables: i
Python program:
def minProductSubset ( a , n ) :
    if ( n == 1 ) :
        return a [ 0 ]
    max_neg = float ( ' - inf ' )
    min_pos = float ( ' inf ' )
    count_neg = 0
    count_zero = 0
    prod = 1
    for i in range ( 0 , n ) :
        if ( a [ i ] == 0 ) :
            count_zero = count_zero + 1
            continue
        if ( a [ i ] < 0 ) :
            count_neg = count_neg + 1
            max_neg = max ( max_neg , a [ i ] )
        if ( a [ i ] > 0 ) :
            min_pos = min ( min_pos , a [ i ] )
        prod = prod * a [ i ]
    if ( count_zero == n or ( count_neg == 0 and count_zero > 0 ) ) :
        return 0
    if ( count_neg == 0 ) :
        return min_pos
    if ( ( count_neg & 1 ) == 0 and count_neg != 0 ) :
        prod = int ( prod / max_neg )
    return prod
a = [ - 1 , - 1 , - 2 , 4 , 3 ]
n = len ( a )
print ( minProductSubset ( a , n ) )

Index/key variables: i
Iterator variables: i
Python program:
Mod = 1000000007
def findSum ( arr , n ) :
    sum = 0
    arr . sort ( )
    i = 0
    while i < n and arr [ i ] < 0 :
        if i != n - 1 and arr [ i + 1 ] <= 0 :
            sum = ( sum + ( arr [ i ] * arr [ i + 1 ] ) % Mod ) % Mod
            i += 2
        else :
            break
    j = n - 1
    while j >= 0 and arr [ j ] > 0 :
        if j != 0 and arr [ j - 1 ] > 0 :
            sum = ( sum + ( arr [ j ] * arr [ j - 1 ] ) % Mod ) % Mod
            j -= 2
        else :
            break
    if j > i :
        sum = ( sum + ( arr [ i ] * arr [ j ] ) % Mod ) % Mod
    elif i == j :
        sum = ( sum + arr [ i ] ) % Mod
    return sum
arr = [ - 1 , 9 , 4 , 5 , - 4 , 7 ]
n = len ( arr )
print ( findSum ( arr , n ) )

Index/key variables: i, j
Python program:
class Node :
    def __init__ ( self , d ) :
        self . data = d
        self . next = None
class LinkedList :
    def __init__ ( self ) :
        self . head = None
    def areIdentical ( self , listb ) :
        a = self . head
        b = listb . head
        while ( a != None and b != None ) :
            if ( a . data != b . data ) :
                return False
            a = a . next
            b = b . next
        return ( a == None and b == None )
    def push ( self , new_data ) :
        new_node = Node ( new_data )
        new_node . next = self . head
        self . head = new_node
llist1 = LinkedList ( )
llist2 = LinkedList ( )
llist1 . push ( 1 )
llist1 . push ( 2 )
llist1 . push ( 3 )
llist2 . push ( 1 )
llist2 . push ( 2 )
llist2 . push ( 3 )
if ( llist1 . areIdentical ( llist2 ) == True ) :
    print ( " Identical ▁ " )
else :
    print ( " Not ▁ identical ▁ " )

Class/struct names: LinkedList, Node
Python program:
class Node :
    def __init__ ( self ) :
        self . data = 0
        self . next = None
def rotate ( head_ref , k ) :
    if ( k == 0 ) :
        return
    current = head_ref
    while ( current . next != None ) :
        current = current . next
    current . next = head_ref
    current = head_ref
    for i in range ( k - 1 ) :
        current = current . next
    head_ref = current . next
    current . next = None
    return head_ref
def push ( head_ref , new_data ) :
    new_node = Node ( )
    new_node . data = new_data
    new_node . next = ( head_ref )
    ( head_ref ) = new_node
    return head_ref
def printList ( node ) :
    while ( node != None ) :
        print ( node . data , end = ' ▁ ' )
        node = node . next
if __name__ == ' _ _ main _ _ ' :
    head = None
    for i in range ( 60 , 0 , - 10 ) :
        head = push ( head , i )
    print ( " Given ▁ linked ▁ list ▁ " )
    printList ( head )
    head = rotate ( head , 4 )
    print ( " Rotated Linked list   " )
    printList ( head )

Iterator variables: i
Class/struct names: Node
Python program:
class Node :
    def __init__ ( self , data ) :
        self . data = data
        self . next = None
        self . child = None

Class/struct names: Node
Python program:
class Node :
    def __init__ ( self , d ) :
        self . data = d
        self . next = None
class LinkedList :
    def __init__ ( self ) :
        self . head = None
    def newNode ( self , key ) :
        temp = Node ( key )
        self . next = None
        return temp
    def rearrangeEvenOdd ( self , head ) :
        if ( self . head == None ) :
            return None
        odd = self . head
        even = self . head . next
        evenFirst = even
        while ( 1 == 1 ) :
            if ( odd == None or even == None or ( even . next ) == None ) :
                odd . next = evenFirst
                break
            odd . next = even . next
            odd = even . next
            if ( odd . next == None ) :
                even . next = None
                odd . next = evenFirst
                break
            even . next = odd . next
            even = odd . next
        return head
    def printlist ( self , node ) :
        while ( node != None ) :
            print ( node . data , end = " " )
            print ( " - > " , end = " " )
            node = node . next
        print ( " NULL " )
    def push ( self , new_data ) :
        new_node = Node ( new_data )
        new_node . next = self . head
        self . head = new_node
ll = LinkedList ( )
ll . push ( 5 )
ll . push ( 4 )
ll . push ( 3 )
ll . push ( 2 )
ll . push ( 1 )
print ( " Given ▁ Linked ▁ List " )
ll . printlist ( ll . head )
start = ll . rearrangeEvenOdd ( ll . head )
print ( " Modified Linked List " )
ll . printlist ( start )

Class/struct names: LinkedList, Node