dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maximumIntersections ( int arr [ ] [ 2 ] , int N ) { int count = 0 ; int L [ N ] , R [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { L [ i ] = arr [ i ] [ 0 ] ; R [ i ] = arr [ i ] [ 1 ] ; } sort ( L , L + N ) ; sort ( R , R + N ) ; for ( int i = 0 ; i < N ; i ++ ) { int l = arr [ i ] [ 0 ] ; int r = arr [ i ] [ 1 ] ; int x = lower_bound ( R , R + N , l ) - R ; int y = N - ( upper_bound ( L , L + N , r ) - L ) ; int cnt = x + y ; cnt = N - cnt - 1 ; count = max ( count , cnt ) ; } return count ; } int main ( ) { int arr [ ] [ 2 ] = { { 1 , 6 } , { 5 , 5 } , { 2 , 3 } } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maximumIntersections ( arr , N ) ; return 0 ; }

Index/key variables: N, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; class Node { public : int data ; Node * next ; Node ( int x ) { data = x ; next = NULL ; } } ; Node * intersectingNode ( Node * headA , Node * headB ) { Node * a = headA ; while ( a ) { a -> data *= -1 ; a = a -> next ; } Node * b = headB ; while ( b ) { if ( b -> data < 0 ) break ; b = b -> next ; } return b ; } void formLinkList ( Node * & head1 , Node * & head2 ) { head1 = new Node ( 3 ) ; head1 -> next = new Node ( 6 ) ; head1 -> next -> next = new Node ( 9 ) ; head1 -> next -> next -> next = new Node ( 15 ) ; head1 -> next -> next -> next -> next = new Node ( 30 ) ; head2 = new Node ( 10 ) ; head2 -> next = head1 -> next -> next -> next ; return ; } int main ( ) { Node * head1 ; Node * head2 ; formLinkList ( head1 , head2 ) ; cout << abs ( intersectingNode ( head1 , head2 ) -> data ) ; return 0 ; }

Accumulator variables: data, stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct TreeNode { int val ; TreeNode * left , * right ; TreeNode ( int v ) { val = v ; left = NULL ; right = NULL ; } } ; bool isInc ( TreeNode * root ) { queue < TreeNode * > que ; que . push ( root ) ; while ( true ) { int length = que . size ( ) ; if ( length == 0 ) break ; auto pre = que . front ( ) ; while ( length > 0 ) { auto temp = que . front ( ) ; que . pop ( ) ; if ( pre -> val > temp -> val ) return false ; pre = temp ; if ( temp -> left ) que . push ( temp -> left ) ; if ( temp -> right ) que . push ( temp -> right ) ; length -= 1 ; } } return true ; } void levelOrder ( TreeNode * root ) { queue < TreeNode * > que ; que . push ( root ) ; while ( true ) { int length = que . size ( ) ; if ( length == 0 ) break ; while ( length ) { auto temp = que . front ( ) ; que . pop ( ) ; cout << temp -> val << " ▁ " ; if ( temp -> left ) que . push ( temp -> left ) ; if ( temp -> right ) que . push ( temp -> right ) ; length -= 1 ; } cout << endl ; } cout << endl ; } void makeInc ( TreeNode * root ) { queue < TreeNode * > que ; que . push ( root ) ; while ( true ) { int length = que . size ( ) ; if ( length == 0 ) break ; int prev = -1 ; while ( length > 0 ) { auto temp = que . front ( ) ; que . pop ( ) ; auto optEle = temp -> val ; auto strEle = to_string ( temp -> val ) ; bool flag = true ; int yy = strEle . size ( ) ; for ( int idx = 0 ; idx < strEle . size ( ) ; idx ++ ) { int ls = stoi ( strEle . substr ( idx , yy ) + strEle . substr ( 0 , idx ) ) ; if ( ls >= prev and flag ) { optEle = ls ; flag = false ; } if ( ls >= prev ) optEle = min ( optEle , ls ) ; } temp -> val = optEle ; prev = temp -> val ; if ( temp -> left ) que . push ( temp -> left ) ; if ( temp -> right ) que . push ( temp -> right ) ; length -= 1 ; } } if ( isInc ( root ) ) levelOrder ( root ) ; else cout << ( -1 ) ; } int main ( ) { TreeNode * root = new TreeNode ( 341 ) ; root -> left = new TreeNode ( 241 ) ; root -> right = new TreeNode ( 123 ) ; root -> left -> left = new TreeNode ( 324 ) ; root -> left -> right = new TreeNode ( 235 ) ; root -> right -> right = new TreeNode ( 161 ) ; makeInc ( root ) ; }

Accumulator variables: idx, length, stdc
Iterator variables: idx
Boolean variables: flag
Class/struct names: TreeNode
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct node { int data ; struct node * left ; struct node * right ; } ; void reverseLevelOrder ( node * root ) { stack < node * > S ; queue < node * > Q ; Q . push ( root ) ; while ( Q . empty ( ) == false ) { root = Q . front ( ) ; Q . pop ( ) ; S . push ( root ) ; if ( root -> right ) Q . push ( root -> right ) ; if ( root -> left ) Q . push ( root -> left ) ; } while ( S . empty ( ) == false ) { root = S . top ( ) ; cout << root -> data << " ▁ " ; S . pop ( ) ; } } node * newNode ( int data ) { node * temp = new node ; temp -> data = data ; temp -> left = NULL ; temp -> right = NULL ; return ( temp ) ; } 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 -> right -> left = newNode ( 6 ) ; root -> right -> right = newNode ( 7 ) ; cout << " Level ▁ Order ▁ traversal ▁ of ▁ binary ▁ tree ▁ is ▁ STRNEWLINE " ; reverseLevelOrder ( root ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void removeDuplicateCharacters ( vector < string > arr ) { unordered_set < char > cset ; int n = arr . size ( ) ; vector < string > out ; for ( auto str : arr ) { string out_curr = " " ; for ( auto ch : str ) { if ( cset . find ( ch ) != cset . end ( ) ) continue ; out_curr += ch ; cset . insert ( ch ) ; } if ( out_curr . size ( ) ) out . push_back ( out_curr ) ; } for ( int i = 0 ; i < out . size ( ) ; i ++ ) { cout << out [ i ] << " ▁ " ; } } int main ( ) { vector < string > arr = { " Geeks " , " For " , " Geeks " , " Post " } ; removeDuplicateCharacters ( arr ) ; }

Index/key variables: i
Accumulator variables: i, out_curr, stdc
Iterator variables: ch, i, str
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPrime ( int n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } void primeFactorSum ( int arr [ ] , int n , int k ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( k % arr [ i ] == 0 && isPrime ( arr [ i ] ) ) { sum = sum + arr [ i ] ; } } cout << sum ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 5 , 6 , 7 , 15 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 35 ; primeFactorSum ( arr , N , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; static int minOperations ( int nums [ ] , int N , int x ) { int sum = 0 ; for ( int i = 0 ; i < x ; i ++ ) sum += nums [ i ] ; if ( sum < x ) return -1 ; int ans = INT_MAX ; int l = N - 1 , r = N ; x -= sum ; while ( l >= 0 ) { if ( x <= 0 ) { x += nums [ l ] ; l -= 1 ; } if ( x > 0 ) { r -= 1 ; x -= nums [ r ] ; } if ( x == 0 ) { ans = min ( ans , ( l + 1 ) + ( N - r ) ) ; } } if ( ans < INT_MAX ) return ans ; else return -1 ; } int main ( ) { int nums [ ] = { 1 , 1 , 4 , 2 , 3 } ; int N = sizeof ( nums ) / sizeof ( nums [ 0 ] ) ; int x = 5 ; cout << minOperations ( nums , N , x ) ; return 0 ; }

Index/key variables: i, l, r
Accumulator variables: i, l, r, stdc, sum, x
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX  1e5
void primeFactors ( vector < int > & v , int n ) { for ( int i = 2 ; i * i <= n ; i ++ ) { while ( n % i == 0 ) { v [ i ] ++ ; v [ i ] %= 3 ; n /= i ; } } if ( n != 1 ) { v [ n ] ++ ; v [ n ] %= 3 ; } } void countSubarrays ( int arr [ ] , int n ) { int ans = 0 ; vector < int > v ( MAX , 0 ) ; map < vector < int > , int > mp ; mp [ v ] ++ ; for ( int i = 0 ; i < n ; i ++ ) { primeFactors ( v , arr [ i ] ) ; ans += mp [ v ] ; mp [ v ] ++ ; } cout << ans ; } int main ( ) { int arr [ ] = { 1 , 8 , 4 , 2 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; countSubarrays ( arr , N ) ; return 0 ; }

Index/key variables: i, n, v
Accumulator variables: ans, i, n, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; void evenproduct ( int arr [ ] , int length ) { int total_subarray = length * ( length + 1 ) / 2 ; int total_odd = 0 ; int count_odd = 0 ; for ( int i = 0 ; i < length ; ++ i ) { if ( arr [ i ] % 2 == 0 ) { count_odd = 0 ; } else { ++ count_odd ; total_odd += count_odd ; } } cout << ( total_subarray - total_odd ) << endl ; } int main ( ) { int arr [ ] = { 7 , 5 , 4 , 9 } ; int length = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; evenproduct ( arr , length ) ; return 0 ; }

Index/key variables: i
Accumulator variables: total_odd
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkGroup ( vector < int > arr ) { if ( arr . size ( ) <= 2 ) return true ; int corner = arr [ 0 ] + arr [ ( int ) arr . size ( ) - 1 ] ; int xorSum = 0 ; for ( int i = 0 ; i < arr . size ( ) - 1 ; i ++ ) xorSum += ( arr [ i ] ^ arr [ i + 1 ] ) ; if ( ! corner ) if ( xorSum > 2 ) return false ; else if ( corner == 1 ) if ( xorSum > 1 ) return false ; else if ( xorSum > 0 ) return false ; return true ; } bool isInGroupUtil ( vector < vector < int > > mat ) { for ( auto i : mat ) { if ( ! checkGroup ( i ) ) return false ; } return true ; } void isInGroup ( vector < vector < int > > mat ) { bool ans = isInGroupUtil ( mat ) ; if ( ans ) printf ( " Yes " ) ; else printf ( " No " ) ; } int main ( ) { vector < vector < int > > mat = { { 0 , 1 , 1 , 0 } , { 1 , 1 , 0 , 0 } , { 0 , 0 , 0 , 1 } , { 1 , 1 , 1 , 0 } } ; isInGroup ( mat ) ; }

Index/key variables: i
Accumulator variables: i, stdc, xorSum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int productOfDigits ( int N ) { int product = 1 ; while ( N != 0 ) { product = product * ( N % 10 ) ; N = N / 10 ; } return product ; } void productOfDigitsK ( int N , int K ) { int flag = 0 ; for ( int i = 1 ; i <= N ; ++ i ) { if ( K == productOfDigits ( i ) ) { cout << i << " ▁ " ; flag = 1 ; } } if ( flag == 0 ) cout << " - 1" ; } int main ( ) { int N = 500 , K = 10 ; productOfDigitsK ( N , K ) ; }

Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minimiseDifference ( vector < int > & arr , int K ) { int N = arr . size ( ) ; int maxSuffix [ N + 1 ] , minSuffix [ N + 1 ] ; maxSuffix [ N ] = -1e9 ; minSuffix [ N ] = 1e9 ; maxSuffix [ N - 1 ] = arr [ N - 1 ] ; minSuffix [ N - 1 ] = arr [ N - 1 ] ; for ( int i = N - 2 ; i >= 0 ; -- i ) { maxSuffix [ i ] = max ( maxSuffix [ i + 1 ] , arr [ i ] ) ; minSuffix [ i ] = min ( minSuffix [ i + 1 ] , arr [ i ] ) ; } int maxPrefix = arr [ 0 ] ; int minPrefix = arr [ 0 ] ; int minDiff = maxSuffix [ K ] - minSuffix [ K ] ; for ( int i = 1 ; i < N ; ++ i ) { if ( i + K <= N ) { int maximum = max ( maxSuffix [ i + K ] , maxPrefix ) ; int minimum = min ( minSuffix [ i + K ] , minPrefix ) ; minDiff = min ( minDiff , maximum - minimum ) ; } maxPrefix = max ( maxPrefix , arr [ i ] ) ; minPrefix = min ( minPrefix , arr [ i ] ) ; } cout << minDiff << " STRNEWLINE " ; } int main ( ) { vector < int > arr = { 4 , 5 , 8 , 9 , 1 , 2 } ; int K = 2 ; minimiseDifference ( arr , K ) ; return 0 ; }

Index/key variables: K, N, i
Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minSegments ( pair < int , int > segments [ ] , int n ) { int startPoints [ n ] , endPoints [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { startPoints [ i ] = segments [ i ] . first ; endPoints [ i ] = segments [ i ] . second ; } sort ( startPoints , startPoints + n ) ; sort ( endPoints , endPoints + n ) ; int ans = n - 1 ; for ( int i = 0 ; i < n ; i ++ ) { int f = segments [ i ] . first ; int s = segments [ i ] . second ; int leftDelete = lower_bound ( endPoints , endPoints + n , f ) - endPoints ; int rightDelete = max ( 0 , n - ( int ) ( upper_bound ( startPoints , startPoints + n , s ) - startPoints ) ) ; ans = min ( ans , leftDelete + rightDelete ) ; } cout << ans ; } int main ( ) { pair < int , int > arr [ ] = { { 1 , 2 } , { 5 , 6 } , { 6 , 7 } , { 7 , 10 } , { 8 , 9 } } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; minSegments ( arr , N ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int longestSubstring ( string s , int k ) { int ans = 0 ; int freq [ 26 ] = { 0 } ; int n = s . size ( ) ; for ( int i = 0 ; i < n ; i ++ ) freq [ s [ i ] - ' a ' ] ++ ; int unique = 0 ; for ( int i = 0 ; i < 26 ; i ++ ) if ( freq [ i ] != 0 ) unique ++ ; for ( int curr_unique = 1 ; curr_unique <= unique ; curr_unique ++ ) { memset ( freq , 0 , sizeof ( freq ) ) ; int start = 0 , end = 0 ; int cnt = 0 , count_k = 0 ; while ( end < n ) { if ( cnt <= curr_unique ) { int ind = s [ end ] - ' a ' ; if ( freq [ ind ] == 0 ) cnt ++ ; freq [ ind ] ++ ; if ( freq [ ind ] == k ) count_k ++ ; end ++ ; } else { int ind = s [ start ] - ' a ' ; if ( freq [ ind ] == k ) count_k -- ; freq [ ind ] -- ; if ( freq [ ind ] == 0 ) cnt -- ; start ++ ; } if ( cnt == curr_unique && count_k == curr_unique ) ans = max ( ans , end - start ) ; } } cout << ans ; } int main ( ) { string S = " aabbba " ; int K = 3 ; longestSubstring ( S , K ) ; return 0 ; }

Index/key variables: end, i, ind, start
Accumulator variables: cnt, count_k, curr_unique, end, i, start, stdc, unique
Iterator variables: curr_unique, i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool compare ( pair < int , int > f , pair < int , int > s ) { return f . second < s . second ; } struct hash_pair { template < class T1 , class T2 > size_t operator() ( const pair < T1 , T2 > & p ) const { auto hash1 = hash < T1 > { } ( p . first ) ; auto hash2 = hash < T2 > { } ( p . second ) ; return hash1 ^ hash2 ; } } ; void findMaxIntervals ( vector < pair < int , int > > v , int n ) { unordered_map < pair < int , int > , int , hash_pair > um ; sort ( v . begin ( ) , v . end ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { um [ v [ i ] ] = 0 ; int start = v [ i ] . first ; int end = v [ i ] . second ; int low = i + 1 ; int high = n - 1 ; int ans = -1 ; while ( low <= high ) { int mid = low + ( high - low ) / 2 ; if ( v [ mid ] . first > end ) { ans = mid ; high = mid - 1 ; } else { low = mid + 1 ; } } if ( ans != -1 ) um [ v [ i ] ] = n - ans ; } sort ( v . begin ( ) , v . end ( ) , compare ) ; for ( int i = 0 ; i < n ; i ++ ) { int start = v [ i ] . first ; int end = v [ i ] . second ; int low = 0 ; int high = i - 1 ; int ans = -1 ; while ( low <= high ) { int mid = low + ( high - low ) / 2 ; if ( v [ mid ] . second < start ) { ans = mid ; low = mid + 1 ; } else { high = mid - 1 ; } } if ( ans != -1 ) um [ v [ i ] ] += ( ans + 1 ) ; } int res = 0 ; for ( auto it = um . begin ( ) ; it != um . end ( ) ; it ++ ) { res = max ( res , n - it -> second ) ; } cout << res ; } int main ( ) { vector < pair < int , int > > arr = { { 1 , 2 } , { 3 , 4 } , { 2 , 5 } } ; int N = arr . size ( ) ; findMaxIntervals ( arr , N ) ; return 0 ; }

Index/key variables: i, mid
Accumulator variables: i, it, stdc
Iterator variables: i, it
Class/struct names: T1, T2, hash_pair
C++ program:
#include <bits/stdc++.h>
using namespace std ; int dRow [ ] = { -1 , 0 , 1 , 0 } ; int dCol [ ] = { 0 , 1 , 0 , -1 } ; bool isValid ( vector < vector < bool > > & vis , int row , int col , int COL , int ROW ) { if ( row < 0 col < 0 col > COL - 1 row > ROW - 1 ) return false ; if ( vis [ row ] [ col ] == true ) return false ; return true ; } void DFSUtil ( int row , int col , vector < vector < int > > grid , vector < vector < bool > > & vis , int M , int N ) { vis [ row ] [ col ] = true ; cout << grid [ row ] [ col ] << " ▁ " ; for ( int i = 0 ; i < 4 ; i ++ ) { int x = row + dRow [ i ] ; int y = col + dCol [ i ] ; if ( isValid ( vis , x , y , M , N ) ) DFSUtil ( x , y , grid , vis , M , N ) ; } } void DFS ( int row , int col , vector < vector < int > > grid , int M , int N ) { vector < vector < bool > > vis ( M + 1 , vector < bool > ( N + 1 , false ) ) ; DFSUtil ( 0 , 0 , grid , vis , M , N ) ; } int main ( ) { vector < vector < int > > grid { { 1 , 2 , 3 , 4 } , { 5 , 6 , 7 , 8 } , { 9 , 10 , 11 , 12 } , { 13 , 14 , 15 , 16 } } ; int M = grid . size ( ) ; int N = grid [ 0 ] . size ( ) ; DFS ( 0 , 0 , grid , M , N ) ; return 0 ; }

Index/key variables: col, i, row
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int dRow [ ] = { -1 , 0 , 1 , 0 } ; int dCol [ ] = { 0 , 1 , 0 , -1 } ; bool isValid ( vector < vector < bool > > & vis , int row , int col , int COL , int ROW ) { if ( row < 0 col < 0 col > COL - 1 row > ROW - 1 ) return false ; if ( vis [ row ] [ col ] == true ) return false ; return true ; } void DFS_iterative ( vector < vector < int > > grid , int M , int N ) { vector < vector < bool > > vis ( M + 5 , vector < bool > ( N + 5 , false ) ) ; stack < pair < int , int > > st ; st . push ( { 0 , 0 } ) ; vis [ 0 ] [ 0 ] = true ; while ( ! st . empty ( ) ) { pair < int , int > p = st . top ( ) ; st . pop ( ) ; int row = p . first ; int col = p . second ; cout << grid [ row ] [ col ] << " ▁ " ; for ( int i = 0 ; i < 4 ; i ++ ) { int x = row + dRow [ i ] ; int y = col + dCol [ i ] ; if ( isValid ( vis , x , y , M , N ) ) { st . push ( { x , y } ) ; vis [ x ] [ y ] = true ; } } } } int main ( ) { vector < vector < int > > grid { { 1 , 2 , 3 , 4 } , { 5 , 6 , 7 , 8 } , { 9 , 10 , 11 , 12 } , { 13 , 14 , 15 , 16 } } ; int M = grid . size ( ) ; int N = grid [ 0 ] . size ( ) ; DFS_iterative ( grid , M , N ) ; return 0 ; }

Index/key variables: col, i, row, x, y
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #include <bits/stdc++.h>
using namespace std ; void minOps ( string s , int N ) { int ans = 0 ; for ( int i = 1 ; i < N ; i ++ ) { if ( s [ i ] != s [ i - 1 ] ) { ans ++ ; } } if ( ans % 2 == 1 ) { cout << ( ans - 1 ) / 2 << endl ; return ; } cout << ( ans / 2 ) ; } int main ( ) { string str = "01011100" ; int N = str . size ( ) ; minOps ( str , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX  1000001
bool prime [ MAX ] ; int cntTriplet [ MAX ] ; void primeTriplet ( long N ) { memset ( prime , true , sizeof ( prime ) ) ; prime [ 0 ] = prime [ 1 ] = false ; for ( int i = 2 ; i * i <= N ; i ++ ) { if ( prime [ i ] ) { for ( int j = i * i ; j <= N ; j += i ) { prime [ j ] = false ; } } } for ( int i = 3 ; i <= N ; i ++ ) { if ( prime [ i ] && prime [ i - 2 ] ) { cntTriplet [ i ] = cntTriplet [ i - 1 ] + 1 ; } else { cntTriplet [ i ] = cntTriplet [ i - 1 ] ; } } cout << cntTriplet [ N ] ; } int main ( ) { long N = 7 ; primeTriplet ( N ) ; return 0 ; }

Index/key variables: MAX, N, i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int OddOneOut ( int arr [ ] , int N ) { multimap < int , int > e , o ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] % 2 == 0 ) { e . insert ( { arr [ i ] , i } ) ; } else { o . insert ( { arr [ i ] , i } ) ; } } if ( e . size ( ) == 1 ) { cout << e . begin ( ) -> second ; } else { cout << o . begin ( ) -> second ; } } int main ( ) { int arr [ ] = { 2 , 4 , 7 , 8 , 10 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; OddOneOut ( 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 count ( int a [ ] , int n ) { if ( n == 1 ) { cout << 0 ; return ; } int pre [ n - 1 ] , suf [ n - 1 ] ; int max = a [ 0 ] ; int ans = 0 , i ; pre [ 0 ] = a [ 0 ] ; for ( i = 1 ; i < n - 1 ; i ++ ) { if ( a [ i ] > max ) max = a [ i ] ; pre [ i ] = max ; } max = a [ n - 1 ] ; suf [ n - 2 ] = a [ n - 1 ] ; for ( i = n - 2 ; i >= 1 ; i -- ) { if ( a [ i ] > max ) max = a [ i ] ; suf [ i - 1 ] = max ; } for ( i = 0 ; i < n - 1 ; i ++ ) { if ( pre [ i ] < suf [ i ] ) ans ++ ; } cout << ans ; } int main ( ) { int arr [ ] = { 2 , 3 , 4 , 8 , 1 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; count ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int xorSubsequence ( int a [ ] , int n , int k ) { int ans = 0 ; map < int , int > map ; int dp [ n ] = { 0 } ; map [ a [ 0 ] ] = 1 ; dp [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { int dpj ; if ( map . find ( a [ i ] ^ k ) != map . end ( ) ) { dpj = map [ a [ i ] ^ k ] ; } else { dpj = -1 ; } if ( dpj != 0 ) dp [ i ] = max ( dp [ i ] , dpj + 1 ) ; ans = max ( ans , dp [ i ] ) ; if ( map . find ( a [ i ] ) != map . end ( ) ) { map [ a [ i ] ] = max ( map [ a [ i ] ] + 1 , dp [ i ] ) ; } else { map [ a [ i ] ] = max ( 1 , dp [ i ] ) ; } } return ans >= 2 ? ans : 0 ; } int main ( ) { int arr [ ] = { 3 , 2 , 4 , 3 , 5 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 1 ; cout << ( xorSubsequence ( arr , N , K ) ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; class TreeNode { public : int data ; TreeNode * left ; TreeNode * right ; } ; TreeNode * newNode ( int data ) { TreeNode * Node = new TreeNode ( ) ; Node -> data = data ; Node -> left = NULL ; Node -> right = NULL ; return ( Node ) ; } pair < int , int > sumofsubtree ( TreeNode * root , int & ans ) { pair < int , int > p = make_pair ( 1 , 0 ) ; if ( root -> left ) { pair < int , int > ptemp = sumofsubtree ( root -> left , ans ) ; p . second += ptemp . first + ptemp . second ; p . first += ptemp . first ; } if ( root -> right ) { pair < int , int > ptemp = sumofsubtree ( root -> right , ans ) ; p . second += ptemp . first + ptemp . second ; p . first += ptemp . first ; } ans += p . second ; return p ; } int main ( ) { TreeNode * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; root -> right -> left = newNode ( 6 ) ; root -> right -> right = newNode ( 7 ) ; root -> left -> left -> left = newNode ( 8 ) ; root -> left -> left -> right = newNode ( 9 ) ; int ans = 0 ; sumofsubtree ( root , ans ) ; cout << ans ; return 0 ; }

Accumulator variables: ans, first, second, stdc
Class/struct names: TreeNode
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minTime ( vector < int > arr , int N , int K ) { queue < int > q ; vector < bool > vis ( N + 1 , false ) ; int time = 0 ; for ( int i = 0 ; i < K ; i ++ ) { q . push ( arr [ i ] ) ; vis [ arr [ i ] ] = true ; } while ( q . size ( ) > 0 ) { for ( int i = 0 ; i < q . size ( ) ; i ++ ) { int curr = q . front ( ) ; q . pop ( ) ; if ( curr - 1 >= 1 && ! vis [ curr - 1 ] ) { vis [ curr - 1 ] = true ; q . push ( curr - 1 ) ; } if ( curr + 1 <= N && ! vis [ curr + 1 ] ) { vis [ curr + 1 ] = true ; q . push ( curr + 1 ) ; } } time ++ ; } cout << ( time - 1 ) ; } int main ( ) { int N = 6 ; vector < int > arr = { 2 , 6 } ; int K = arr . size ( ) ; minTime ( arr , N , K ) ; }

Index/key variables: i
Accumulator variables: i, stdc, time
Iterator variables: i