dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; long long int findSubarraySum ( int arr [ ] , int n ) { int i , j ; long long int cArray [ n + 1 ] = { 0 } ; for ( i = 0 ; i < n ; i ++ ) cArray [ i + 1 ] = cArray [ i ] + arr [ i ] ; vector < long long int > subArrSum ; for ( i = 1 ; i <= n ; i ++ ) for ( j = i ; j <= n ; j ++ ) subArrSum . push_back ( cArray [ j ] - cArray [ i - 1 ] ) ; sort ( subArrSum . begin ( ) , subArrSum . end ( ) ) ; long long totalSum = 0 ; for ( i = 0 ; i < subArrSum . size ( ) - 1 ; i ++ ) { if ( subArrSum [ i ] == subArrSum [ i + 1 ] ) { j = i + 1 ; while ( subArrSum [ j ] == subArrSum [ i ] && j < subArrSum . size ( ) ) { subArrSum [ j ] = 0 ; j ++ ; } subArrSum [ i ] = 0 ; } } for ( i = 0 ; i < subArrSum . size ( ) ; i ++ ) totalSum += subArrSum [ i ] ; return totalSum ; } int main ( ) { int arr [ ] = { 3 , 2 , 3 , 1 , 4 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findSubarraySum ( arr , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc, totalSum
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countMaxSetBits ( int left , int right ) { int max_count = -1 , num ; for ( int i = left ; i <= right ; ++ i ) { int temp = i , cnt = 0 ; while ( temp ) { if ( temp & 1 ) ++ cnt ; temp >>= 1 ; } if ( cnt > max_count ) { max_count = cnt ; num = i ; } } return num ; } int main ( ) { int l = 1 , r = 5 ; cout << countMaxSetBits ( l , r ) << " STRNEWLINE " ; l = 1 , r = 10 ; cout << countMaxSetBits ( l , r ) ; return 0 ; }

Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; long long int findSubarraySum ( int arr [ ] , int n ) { int res = 0 ; unordered_map < int , int > m ; for ( int i = 0 ; i < n ; i ++ ) { int sum = 0 ; for ( int j = i ; j < n ; j ++ ) { sum += arr [ j ] ; m [ sum ] ++ ; } } for ( auto x : m ) if ( x . second == 1 ) res += x . first ; return res ; } int main ( ) { int arr [ ] = { 3 , 2 , 3 , 1 , 4 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findSubarraySum ( arr , n ) ; return 0 ; }

Index/key variables: j, sum
Accumulator variables: i, j, res, stdc, sum
Iterator variables: i, j, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; int partition ( int arr [ ] , int l , int r ) { int x = arr [ r ] , i = l ; for ( int j = l ; j <= r - 1 ; j ++ ) { if ( arr [ j ] <= x ) { swap ( arr [ i ] , arr [ j ] ) ; i ++ ; } } swap ( arr [ i ] , arr [ r ] ) ; return i ; } int kthSmallest ( int arr [ ] , int l , int r , int k ) { if ( k > 0 && k <= r - l + 1 ) { int index = partition ( arr , l , r ) ; if ( index - l == k - 1 ) return arr [ index ] ; if ( index - l > k - 1 ) return kthSmallest ( arr , l , index - 1 , k ) ; return kthSmallest ( arr , index + 1 , r , k - index + l - 1 ) ; } return INT_MAX ; } int main ( ) { int arr [ ] = { 10 , 4 , 5 , 8 , 6 , 11 , 26 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 3 ; cout << " K - th ▁ smallest ▁ element ▁ is ▁ " << kthSmallest ( arr , 0 , n - 1 , k ) ; return 0 ; }

Index/key variables: i, index, j, r
Accumulator variables: i, j, stdc
Iterator variables: j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int recaman ( int n ) { int arr [ n ] ; arr [ 0 ] = 0 ; printf ( " % d , ▁ " , arr [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) { int curr = arr [ i - 1 ] - i ; int j ; for ( j = 0 ; j < i ; j ++ ) { if ( ( arr [ j ] == curr ) curr < 0 ) { curr = arr [ i - 1 ] + i ; break ; } } arr [ i ] = curr ; printf ( " % d , ▁ " , arr [ i ] ) ; } } int main ( ) { int n = 17 ; recaman ( n ) ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left , * right ; } ; struct Node * newNode ( int data ) { struct Node * node = new Node ; node -> data = data ; node -> left = node -> right = NULL ; return ( node ) ; } int height ( Node * root , int & ans , Node * ( & k ) , int & lh , int & rh , int & f ) { if ( root == NULL ) return 0 ; int left_height = height ( root -> left , ans , k , lh , rh , f ) ; int right_height = height ( root -> right , ans , k , lh , rh , f ) ; if ( ans < 1 + left_height + right_height ) { ans = 1 + left_height + right_height ; k = root ; lh = left_height ; rh = right_height ; } return 1 + max ( left_height , right_height ) ; } void printArray ( int ints [ ] , int len , int f ) { int i ; if ( f == 0 ) { for ( i = len - 1 ; i >= 0 ; i -- ) { printf ( " % d ▁ " , ints [ i ] ) ; } } else if ( f == 1 ) { for ( i = 0 ; i < len ; i ++ ) { printf ( " % d ▁ " , ints [ i ] ) ; } } } void printPathsRecur ( Node * node , int path [ ] , int pathLen , int max , int & f ) { if ( node == NULL ) return ; path [ pathLen ] = node -> data ; pathLen ++ ; if ( node -> left == NULL && node -> right == NULL ) { if ( pathLen == max && ( f == 0 f == 1 ) ) { printArray ( path , pathLen , f ) ; f = 2 ; } } else { printPathsRecur ( node -> left , path , pathLen , max , f ) ; printPathsRecur ( node -> right , path , pathLen , max , f ) ; } } void diameter ( Node * root ) { if ( root == NULL ) return ; int ans = INT_MIN , lh = 0 , rh = 0 ; int f = 0 ; Node * k ; int height_of_tree = height ( root , ans , k , lh , rh , f ) ; int lPath [ 100 ] , pathlen = 0 ; printPathsRecur ( k -> left , lPath , pathlen , lh , f ) ; printf ( " % d ▁ " , k -> data ) ; int rPath [ 100 ] ; f = 1 ; printPathsRecur ( k -> right , rPath , pathlen , rh , f ) ; } int main ( ) { struct Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; root -> left -> right -> left = newNode ( 6 ) ; root -> left -> right -> right = newNode ( 7 ) ; root -> left -> left -> right = newNode ( 8 ) ; root -> left -> left -> right -> left = newNode ( 9 ) ; diameter ( root ) ; return 0 ; }

Index/key variables: i, pathLen
Accumulator variables: i, pathLen, stdc
Iterator variables: i
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void recaman ( int n ) { if ( n <= 0 ) return ; printf ( " % d , ▁ " , 0 ) ; unordered_set < int > s ; s . insert ( 0 ) ; int prev = 0 ; for ( int i = 1 ; i < n ; i ++ ) { int curr = prev - i ; if ( curr < 0 || s . find ( curr ) != s . end ( ) ) curr = prev + i ; s . insert ( curr ) ; printf ( " % d , ▁ " , curr ) ; prev = curr ; } } int main ( ) { int n = 17 ; recaman ( n ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int sum ( int arr [ ] , int n ) { int summ = 0 ; for ( int i = 0 ; i < n ; i ++ ) { summ += arr [ i ] ; } return summ ; } int indexOf ( int arr [ ] , int element , int n ) { for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == element ) { return i ; } } return -1 ; } int find_extra_element_index ( int arrA [ ] , int arrB [ ] , int n , int m ) { int extra_element = sum ( arrA , n ) - sum ( arrB , m ) ; return indexOf ( arrA , extra_element , n ) ; } int main ( ) { int arrA [ ] = { 2 , 4 , 6 , 8 , 10 , 12 , 13 } ; int arrB [ ] = { 2 , 4 , 6 , 8 , 10 , 12 } ; int n = sizeof ( arrA ) / sizeof ( arrA [ 0 ] ) ; int m = sizeof ( arrB ) / sizeof ( arrB [ 0 ] ) ; cout << find_extra_element_index ( arrA , arrB , n , m ) ; }

Index/key variables: i
Accumulator variables: i, stdc, summ
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findFibSubset ( int arr [ ] , int n ) { int max = * std :: max_element ( arr , arr + n ) ; int a = 0 , b = 1 ; unordered_set < int > hash ; hash . insert ( a ) ; hash . insert ( b ) ; while ( b < max ) { int c = a + b ; a = b ; b = c ; hash . insert ( b ) ; } for ( int i = 0 ; i < n ; i ++ ) if ( hash . find ( arr [ i ] ) != hash . end ( ) ) printf ( " % d ▁ " , arr [ i ] ) ; } int main ( ) { int arr [ ] = { 4 , 2 , 8 , 5 , 20 , 1 , 40 , 13 , 23 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findFibSubset ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int sumOfDiv ( int x ) { int sum = 1 ; for ( int i = 2 ; i <= sqrt ( x ) ; i ++ ) { if ( x % i == 0 ) { sum += i ; if ( x / i != i ) sum += x / i ; } } return sum ; } bool isAmicable ( int a , int b ) { return ( sumOfDiv ( a ) == b && sumOfDiv ( b ) == a ) ; } int countPairs ( int arr [ ] , int n ) { unordered_set < int > s ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) s . insert ( arr [ i ] ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . find ( sumOfDiv ( arr [ i ] ) ) != s . end ( ) ) { int sum = sumOfDiv ( arr [ i ] ) ; if ( isAmicable ( arr [ i ] , sum ) ) count ++ ; } } return count / 2 ; } int main ( ) { int arr1 [ ] = { 220 , 284 , 1184 , 1210 , 2 , 5 } ; int n1 = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; cout << countPairs ( arr1 , n1 ) << endl ; int arr2 [ ] = { 2620 , 2924 , 5020 , 5564 , 6232 , 6368 } ; int n2 = sizeof ( arr2 ) / sizeof ( arr2 [ 0 ] ) ; cout << countPairs ( arr2 , n2 ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minimumDeletion ( string s , int n ) { map < char , int > countMap ; for ( int i = 0 ; i < n ; i ++ ) { countMap [ s [ i ] ] ++ ; } multiset < int > countMultiset ; for ( auto it : countMap ) { countMultiset . insert ( it . second ) ; } int ans = INT_MAX ; int i = 0 ; int m = countMultiset . size ( ) ; for ( auto j : countMultiset ) { ans = min ( ans , n - ( m - i ) * j ) ; i ++ ; } return ans ; } int main ( ) { string S = " geeksforgeeks " ; int N = S . length ( ) ; cout << minimumDeletion ( S , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i, it, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findMinimumDistinct ( int A [ ] , int N , int K ) { unordered_map < int , int > mp ; for ( int i = 0 ; i < N ; i ++ ) mp [ A [ i ] ] ++ ; int count = 0 ; int len = 0 ; vector < int > counts ; for ( auto i : mp ) counts . push_back ( i . second ) ; sort ( counts . begin ( ) , counts . end ( ) , greater < int > ( ) ) ; for ( int i = 0 ; i < counts . size ( ) ; i ++ ) { if ( len >= K ) break ; len += counts [ i ] ; count ++ ; } cout << count ; } int main ( ) { int A [ ] = { 3 , 1 , 3 , 2 , 3 , 4 , 5 , 4 } ; int K = 4 ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; findMinimumDistinct ( A , N , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, len, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int calculateDistance ( int arr [ ] , int N ) { vector < pair < int , int > > v ; for ( int i = 0 ; i < N ; i ++ ) v . push_back ( { arr [ i ] , i } ) ; sort ( v . begin ( ) , v . end ( ) ) ; int ans = 0 ; int last = 0 ; for ( auto j : v ) { ans += abs ( j . second - last ) ; last = j . second ; } return ans ; } int main ( ) { int arr [ ] = { 4 , 3 , 2 , 5 , 1 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << calculateDistance ( arr , N ) ; }

Index/key variables: i
Accumulator variables: ans, i, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void sortArr ( int arr [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { string s = to_string ( arr [ i ] ) ; sort ( s . begin ( ) , s . end ( ) , greater < char > ( ) ) ; arr [ i ] = stoi ( s ) ; int sr = sqrt ( arr [ i ] ) ; int a = sr * sr ; int b = ( sr + 1 ) * ( sr + 1 ) ; if ( ( arr [ i ] - a ) < ( b - arr [ i ] ) ) arr [ i ] = a ; else arr [ i ] = b ; } sort ( arr , arr + N ) ; for ( int i = 0 ; i < N ; i ++ ) { cout << arr [ i ] << " ▁ " ; } } int main ( ) { int arr [ ] = { 29 , 43 , 28 , 12 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sortArr ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minCost ( int arr [ ] , int N , int X ) { sort ( arr , arr + N ) ; int sum = 0 ; int cost = 0 ; int min_cost = INT_MAX ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] < 0 ) { cost = abs ( arr [ i ] ) * X + ( sum - abs ( arr [ i ] ) * i ) ; sum += abs ( arr [ i ] ) ; min_cost = min ( min_cost , cost ) ; } } cout << min_cost ; } int main ( ) { int arr [ ] = { -1 , -3 , -2 , 4 , -1 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int X = 2 ; minCost ( arr , N , X ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int ans = 0 ; void countArraysUtil ( vector < int > & arr , int X , int K , int xorVal ) { if ( X == 0 ) { int cnt = 0 ; for ( int i = 0 ; i < arr . size ( ) ; i ++ ) { if ( arr [ i ] > xorVal ) cnt ++ ; } if ( cnt >= K ) ans ++ ; return ; } int temp = arr [ 0 ] ; arr . erase ( arr . begin ( ) ) ; countArraysUtil ( arr , X - 1 , K , xorVal ) ; arr . insert ( arr . begin ( ) , temp ) ; temp = arr . back ( ) ; arr . pop_back ( ) ; countArraysUtil ( arr , X - 1 , K , xorVal ) ; arr . push_back ( temp ) ; arr [ 0 ] ++ ; countArraysUtil ( arr , X - 1 , K , xorVal ) ; arr [ 0 ] -- ; arr [ arr . size ( ) - 1 ] ++ ; countArraysUtil ( arr , X - 1 , K , xorVal ) ; arr [ arr . size ( ) - 1 ] -- ; } void countArrays ( vector < int > & arr , int X , int K ) { int xorVal = 0 ; for ( int i = 0 ; i < arr . size ( ) ; i ++ ) xorVal = xorVal ^ arr [ i ] ; countArraysUtil ( arr , X , K , xorVal ) ; cout << ans ; } int main ( ) { vector < int > arr = { 10 , 2 , 10 , 5 } ; int X = 3 , K = 3 ; countArrays ( arr , X , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, cnt, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int hashFunction ( int N ) { int prime [ 10 ] = { 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 } ; int value = 1 , r ; while ( N != 0 ) { r = N % 10 ; value = value * prime [ r ] ; N = N / 10 ; } return value ; } void findDiff ( int arr [ ] , int n ) { map < int , vector < int > > m ; int h , min , max ; for ( int i = 0 ; i < n ; i ++ ) { h = hashFunction ( arr [ i ] ) ; m [ h ] . push_back ( arr [ i ] ) ; } for ( auto i = 0 ; i != m . size ( ) ; i ++ ) { if ( m [ i ] . size ( ) > 1 ) { min = * min_element ( m [ i ] . begin ( ) , m [ i ] . end ( ) ) ; max = * max_element ( m [ i ] . begin ( ) , m [ i ] . end ( ) ) ; cout << max - min ; break ; } else if ( i == m . size ( ) - 1 ) cout << -1 ; } } int main ( ) { int arr [ ] = { 121 , 312 , 234 , 211 , 112 , 102 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findDiff ( arr , N ) ; return 0 ; }

Index/key variables: h, i, r
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int cntMaxApples ( vector < int > apples , vector < int > days ) { typedef pair < int , int > P ; priority_queue < P , vector < p > , greater < p > > pq ; int i = 0 ; int n = apples . size ( ) ; int total_apples = 0 ; while ( i < n || ! pq . empty ( ) ) { if ( i < n && apples [ i ] != 0 ) { pq . push ( { i + days [ i ] - 1 , apples [ i ] } ) ; } while ( ! pq . empty ( ) && pq . top ( ) . first < i ) { pq . pop ( ) ; } if ( ! pq . empty ( ) ) { auto curr = pq . top ( ) ; pq . pop ( ) ; if ( curr . second > 1 ) { pq . push ( { curr . first , curr . second - 1 } ) ; } ++ total_apples ; } ++ i ; } return total_apples ; } int main ( ) { vector < int > apples = { 1 , 2 , 3 , 5 , 2 } ; vector < int > days = { 3 , 2 , 1 , 4 , 2 } ; cout << cntMaxApples ( apples , days ) ; return 0 ; }

Index/key variables: i
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findArea ( int arr [ ] , int n ) { sort ( arr , arr + n , greater < int > ( ) ) ; int dimension [ 2 ] = { 0 , 0 } ; for ( int i = 0 , j = 0 ; i < n - 1 && j < 2 ; i ++ ) if ( arr [ i ] == arr [ i + 1 ] ) dimension [ j ++ ] = arr [ i ++ ] ; return ( dimension [ 0 ] * dimension [ 1 ] ) ; } int main ( ) { int arr [ ] = { 4 , 2 , 1 , 4 , 6 , 6 , 2 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findArea ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findSumLength ( vector < int > arr , int n ) { map < int , int > freq ; for ( int i : arr ) freq [ i ] += 1 ; map < int , int > freq_2 ; for ( auto i : freq ) { if ( freq [ i . first ] >= 2 ) freq_2 [ i . first ] = freq [ i . first ] ; } vector < int > arr1 ; for ( auto i : freq_2 ) arr1 . push_back ( ( i . first ) * ( freq_2 [ ( i . first ) ] / 2 ) * 2 ) ; sort ( arr1 . begin ( ) , arr1 . end ( ) ) ; int summ = 0 ; for ( int i : arr1 ) summ += i ; cout << summ ; } int main ( ) { vector < int > arr = { 5 , 3 , 2 , 3 , 6 , 4 , 4 , 4 , 5 , 5 , 5 } ; int n = arr . size ( ) ; findSumLength ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: stdc, summ
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findArea ( int arr [ ] , int n ) { unordered_set < int > s ; int first = 0 , second = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . find ( arr [ i ] ) == s . end ( ) ) { s . insert ( arr [ i ] ) ; continue ; } if ( arr [ i ] > first ) { second = first ; first = arr [ i ] ; } else if ( arr [ i ] > second ) second = arr [ i ] ; } return ( first * second ) ; } int main ( ) { int arr [ ] = { 4 , 2 , 1 , 4 , 6 , 6 , 2 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findArea ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; Node * newNode ( int data ) { Node * node = new Node ; node -> data = data ; node -> left = node -> right = NULL ; return node ; } void printTopToBottomPath ( Node * curr , map < Node * , Node * > parent ) { stack < Node * > stk ; while ( curr ) { stk . push ( curr ) ; curr = parent [ curr ] ; } while ( ! stk . empty ( ) ) { curr = stk . top ( ) ; stk . pop ( ) ; cout << curr -> data << " ▁ " ; } cout << endl ; } void printRootToLeaf ( Node * root ) { if ( root == NULL ) return ; stack < Node * > nodeStack ; nodeStack . push ( root ) ; map < Node * , Node * > parent ; parent [ root ] = NULL ; while ( ! nodeStack . empty ( ) ) { Node * current = nodeStack . top ( ) ; nodeStack . pop ( ) ; if ( ! ( current -> left ) && ! ( current -> right ) ) printTopToBottomPath ( current , parent ) ; if ( current -> right ) { parent [ current -> right ] = current ; nodeStack . push ( current -> right ) ; } if ( current -> left ) { parent [ current -> left ] = current ; nodeStack . push ( current -> left ) ; } } } int main ( ) { Node * root = newNode ( 10 ) ; root -> left = newNode ( 8 ) ; root -> right = newNode ( 2 ) ; root -> left -> left = newNode ( 3 ) ; root -> left -> right = newNode ( 5 ) ; root -> right -> left = newNode ( 2 ) ; printRootToLeaf ( root ) ; return 0 ; }

Index/key variables: curr, root
Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int playGame ( int arr [ ] , int n ) { unordered_set < int > hash ; for ( int i = 0 ; i < n ; i ++ ) hash . insert ( arr [ i ] ) ; return ( hash . size ( ) % 2 == 0 ? 1 : 2 ) ; } int main ( ) { int arr [ ] = { 1 , 1 , 2 , 2 , 2 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Player ▁ " << playGame ( arr , n ) << " ▁ Wins " << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int longLenStrictBitonicSub ( int arr [ ] , int n ) { unordered_map < int , int > inc , dcr ; int len_inc [ n ] , len_dcr [ n ] ; int longLen = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int len = 0 ; if ( inc . find ( arr [ i ] - 1 ) != inc . end ( ) ) len = inc [ arr [ i ] - 1 ] ; inc [ arr [ i ] ] = len_inc [ i ] = len + 1 ; } for ( int i = n - 1 ; i >= 0 ; i -- ) { int len = 0 ; if ( dcr . find ( arr [ i ] - 1 ) != dcr . end ( ) ) len = dcr [ arr [ i ] - 1 ] ; dcr [ arr [ i ] ] = len_dcr [ i ] = len + 1 ; } for ( int i = 0 ; i < n ; i ++ ) if ( longLen < ( len_inc [ i ] + len_dcr [ i ] - 1 ) ) longLen = len_inc [ i ] + len_dcr [ i ] - 1 ; return longLen ; } int main ( ) { int arr [ ] = { 1 , 5 , 2 , 3 , 4 , 5 , 3 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Longest ▁ length ▁ strict ▁ bitonic ▁ subsequence ▁ = ▁ " << longLenStrictBitonicSub ( arr , n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; void Selection_Sort ( int arr [ ] , int n ) { for ( int i = 0 ; i < n - 1 ; ++ i ) { int min_index = i ; for ( int j = i + 1 ; j < n ; ++ j ) { if ( arr [ j ] < arr [ min_index ] ) min_index = j ; } swap ( arr [ i ] , arr [ min_index ] ) ; } } int main ( ) { int n = 5 ; int arr [ 5 ] = { 2 , 0 , 1 , 4 , 3 } ; Selection_Sort ( arr , n ) ; cout << " The ▁ Sorted ▁ Array ▁ by ▁ using ▁ Selection ▁ Sort ▁ is ▁ : ▁ " ; for ( int i = 0 ; i < n ; ++ i ) cout << arr [ i ] << " ▁ " ; return 0 ; }

Index/key variables: i, j, min_index
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int lastSeenElement ( int a [ ] , int n ) { unordered_map < int , int > hash ; for ( int i = 0 ; i < n ; i ++ ) hash [ a [ i ] ] = i ; int res_ind = INT_MAX , res ; for ( auto x : hash ) { if ( x . second < res_ind ) { res_ind = x . second ; res = x . first ; } } return res ; } int main ( ) { int a [ ] = { 2 , 1 , 2 , 2 , 4 , 1 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << lastSeenElement ( a , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i, x
C++ program:
#include <iostream>
using namespace std ; void Bubble_Sort ( int arr [ ] , int n ) { for ( int i = 1 ; i < n ; ++ i ) { for ( int j = 0 ; j <= ( n - i - 1 ) ; ++ j ) { if ( arr [ j ] > arr [ j + 1 ] ) swap ( arr [ j ] , arr [ j + 1 ] ) ; } } } int main ( ) { int n = 5 ; int arr [ 5 ] = { 2 , 0 , 1 , 4 , 3 } ; Bubble_Sort ( arr , n ) ; cout << " The ▁ Sorted ▁ Array ▁ by ▁ using ▁ Bubble ▁ Sort ▁ is ▁ : ▁ " ; for ( int i = 0 ; i < n ; ++ i ) cout << arr [ i ] << " ▁ " ; return 0 ; }

Index/key variables: i, j
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minimum_possible_sum ( int arr [ ] , int n , int k ) { if ( n == 0 ) { return 0 ; } if ( n == 1 ) { return arr [ 0 ] ; } multiset < int > ms ; for ( int i = 0 ; i < n ; i ++ ) { ms . insert ( arr [ i ] ) ; } for ( int i = 0 ; i < k ; i ++ ) { int smallest_element = * ms . begin ( ) ; int largest_element = * ms . rbegin ( ) ; int a = smallest_element * 2 ; int b = largest_element / 2 ; if ( a + b < smallest_element + largest_element ) { ms . erase ( ms . begin ( ) ) ; ms . erase ( prev ( ms . end ( ) ) ) ; ms . insert ( a ) ; ms . insert ( b ) ; } } int ans = 0 ; for ( int x : ms ) { ans += x ; } return ans ; } int main ( ) { int arr [ ] = { 50 , 1 , 100 , 100 , 1 } ; int K = 2 ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << minimum_possible_sum ( arr , n , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, i, stdc
Iterator variables: i, x