dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; void simpleSieve ( int lmt , vector < int > & prime ) { bool Sieve [ lmt + 1 ] ; memset ( Sieve , true , sizeof ( Sieve ) ) ; Sieve [ 0 ] = Sieve [ 1 ] = false ; for ( int i = 2 ; i <= lmt ; ++ i ) { if ( Sieve [ i ] == true ) { prime . push_back ( i ) ; for ( int j = i * i ; j <= lmt ; j += i ) { Sieve [ j ] = false ; } } } } vector < bool > SegmentedSieveFn ( int low , int high ) { int lmt = floor ( sqrt ( high ) ) + 1 ; vector < int > prime ; simpleSieve ( lmt , prime ) ; int n = high - low + 1 ; vector < bool > segmentedSieve ( n + 1 , true ) ; for ( int i = 0 ; i < prime . size ( ) ; i ++ ) { int lowLim = floor ( low / prime [ i ] ) * prime [ i ] ; if ( lowLim < low ) { lowLim += prime [ i ] ; } for ( int j = lowLim ; j <= high ; j += prime [ i ] ) { if ( j != prime [ i ] ) { segmentedSieve [ j - low ] = false ; } } } return segmentedSieve ; } int countPairsWhoseSumPrimeL_R ( int L , int R ) { vector < bool > segmentedSieve = SegmentedSieveFn ( L , R ) ; int cntPairs = 0 ; for ( int i = L ; i <= R ; i ++ ) { if ( segmentedSieve [ i - L ] ) { cntPairs += i / 2 ; } } return cntPairs ; } int main ( ) { int L = 1 , R = 5 ; cout << countPairsWhoseSumPrimeL_R ( L , R ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: cntPairs, i, j, lowLim, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int count_zeroes ( int n , string str ) { int cnt = 0 ; for ( int i = 0 ; i < str . size ( ) ; i ++ ) { if ( str [ i ] == '0' ) cnt ++ ; } return cnt ; } string kReducingStringUtil ( int n , int k , string str , int no_of_zeroes ) { int zeroes_in_2k = ( ( no_of_zeroes ) * ( 2 * k ) ) / n ; int ones_in_2k = 2 * k - zeroes_in_2k ; string temp_str = " " ; for ( int i = 0 ; i < ( zeroes_in_2k ) / 2 ; i ++ ) { temp_str . push_back ( '0' ) ; } for ( int i = 0 ; i < ones_in_2k ; i ++ ) { temp_str . push_back ( '1' ) ; } for ( int i = 0 ; i < ( zeroes_in_2k ) / 2 ; i ++ ) { temp_str . push_back ( '0' ) ; } string final_str = " " ; for ( int i = 0 ; i < n / ( 2 * k ) ; i ++ ) { final_str += ( temp_str ) ; } for ( int i = 0 ; i < n % ( 2 * k ) ; i ++ ) { final_str . push_back ( temp_str [ i ] ) ; } return final_str ; } string kReducingString ( int n , int k , string str ) { int no_of_zeroes = count_zeroes ( n , str ) ; int no_of_ones = n - no_of_zeroes ; if ( no_of_zeroes == 0 no_of_zeroes == n ) { return str ; } if ( k == 1 ) { if ( no_of_zeroes == 0 no_of_zeroes == n ) { return str ; } else { return " Not ▁ Possible " ; } } bool check = 0 ; for ( int i = ( n / k ) ; i < n ; i += ( n / k ) ) { if ( no_of_zeroes == i no_of_ones == i ) { check = 1 ; break ; } } if ( check == 0 ) { return " Not ▁ Possible " ; } return kReducingStringUtil ( n , k , str , no_of_zeroes ) ; } int main ( ) { string str = "0000100001100001" ; int K = 4 ; int N = str . length ( ) ; cout << kReducingString ( N , K , str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cnt, final_str, i, stdc
Iterator variables: i
C++ program:
#include <iostream>
#include <unordered_map>
using namespace std ; int countSum ( int a [ ] , int n , int sum ) { int i , j , k ; int count = 0 ; unordered_map < int , int > m ; for ( i = 0 ; i < n - 1 ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { int temp = a [ i ] + a [ j ] ; if ( temp < sum ) count += m [ sum - temp ] ; } for ( j = 0 ; j < i ; j ++ ) { int temp = a [ i ] + a [ j ] ; if ( temp < sum ) m [ temp ] ++ ; } } return count ; } int main ( ) { int arr [ ] = { 4 , 5 , 3 , 1 , 2 , 4 } ; int S = 13 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countSum ( arr , N , S ) ; return 0 ; }

Index/key variables: i, j, temp
Accumulator variables: count, i, j
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MOD  1000000007
long long int modPower ( long long int x , long long int y ) { long long int res = 1 ; x = x % MOD ; if ( x == 0 ) return 0 ; while ( y > 0 ) { if ( y & 1 ) res = ( res * x ) % MOD ; y = y / 2 ; x = ( x * x ) % MOD ; } return res ; } int countPairs ( long long int arr [ ] , int N ) { int pairCount = 0 ; map < long long int , int > hash ; for ( int i = 0 ; i < N ; i ++ ) { hash [ arr [ i ] ] ++ ; } for ( int i = 0 ; i < N ; i ++ ) { long long int modularInverse = modPower ( arr [ i ] , MOD - 2 ) ; pairCount += hash [ modularInverse ] ; if ( arr [ i ] == modularInverse ) { pairCount -- ; } } return pairCount / 2 ; } int main ( ) { long long int arr [ ] = { 2 , 236426 , 280311812 , 500000004 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countPairs ( arr , N ) ; return 0 ; }

Index/key variables: i, modularInverse
Accumulator variables: i, pairCount, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string check ( int arr [ ] , int n ) { map < int , int > hm ; for ( int i = 0 ; i < n ; i ++ ) { hm [ arr [ i ] ] = 1 ; for ( int j = i + 1 ; j < n ; j ++ ) { hm [ arr [ j ] ] ++ ; bool flag = false ; for ( auto x : hm ) { if ( x . second == 1 ) { flag = true ; break ; } } if ( ! flag ) return " No " ; } hm . clear ( ) ; } return " Yes " ; } int main ( ) { int arr [ ] = { 1 , 2 , 1 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << check ( arr , N ) ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j, x
Boolean variables: flag
C++ program:
#include <bits/stdc++.h>
using namespace std ; int find_index ( int arr [ ] , int n , int K ) { int start = 0 ; int end = n - 1 ; while ( start <= end ) { int mid = ( start + end ) / 2 ; if ( arr [ mid ] == K ) return mid ; else if ( arr [ mid ] < K ) start = mid + 1 ; else end = mid - 1 ; } return end + 1 ; } int main ( ) { int arr [ ] = { 1 , 3 , 5 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 2 ; cout << find_index ( arr , n , K ) << endl ; return 0 ; }

Index/key variables: mid
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int computePos ( int arr [ ] , int n , int value ) { if ( value < arr [ 0 ] ) return 0 ; if ( value > arr [ n - 1 ] ) return n - 1 ; int start = 0 ; int end = n - 1 ; while ( start < end ) { int mid = ( start + end + 1 ) / 2 ; if ( arr [ mid ] >= value ) end = mid - 1 ; else start = mid ; } return start ; } void countShift ( int arr [ ] , int n , vector < vector < int > > & queries ) { for ( auto q : queries ) { int index = q [ 0 ] ; int update = q [ 1 ] ; int newElement = arr [ index ] + update ; int newIndex = computePos ( arr , n , newElement ) ; cout << abs ( newIndex - index ) << " ▁ " ; } } int main ( ) { int arr [ ] = { 2 , 3 , 4 , 5 , 6 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; vector < vector < int > > queries = { { 0 , -1 } , { 4 , -11 } } ; countShift ( arr , N , queries ) ; return 0 ; }

Index/key variables: index, mid
Accumulator variables: stdc
Iterator variables: q
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int key ; Node * left , * right ; } ; Node * newNode ( int key ) { Node * temp = new Node ; temp -> key = key ; temp -> left = temp -> right = NULL ; return temp ; } void countReqNodes ( Node * root , int minNodeVal , int & ans ) { if ( root == NULL ) return ; if ( root -> key <= minNodeVal ) { minNodeVal = root -> key ; ans ++ ; } countReqNodes ( root -> left , minNodeVal , ans ) ; countReqNodes ( root -> right , minNodeVal , ans ) ; } int main ( ) { Node * root = newNode ( 8 ) ; root -> left = newNode ( 6 ) ; root -> right = newNode ( 5 ) ; root -> left -> left = newNode ( 6 ) ; root -> left -> right = newNode ( 7 ) ; root -> right -> left = newNode ( 3 ) ; root -> right -> right = newNode ( 9 ) ; int ans = 0 , minNodeVal = INT_MAX ; countReqNodes ( root , minNodeVal , ans ) ; cout << ans ; return 0 ; }

Accumulator variables: ans, stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPalindrome ( string str ) { int i = 0 , j = str . size ( ) - 1 ; while ( i < j ) { if ( str [ i ] != str [ j ] ) return false ; i ++ ; j -- ; } return true ; } void formPalindrome ( string a , string b , int n ) { char aa [ n + 2 ] ; char bb [ n + 2 ] ; for ( int i = 0 ; i < n + 2 ; i ++ ) { aa [ i ] = ' ▁ ' ; bb [ i ] = ' ▁ ' ; } for ( int i = 1 ; i <= n ; i ++ ) { aa [ i ] = a [ i - 1 ] ; bb [ i ] = b [ i - 1 ] ; } bool ok = false ; for ( int i = 0 ; i <= n + 1 ; i ++ ) { string la = " " ; string ra = " " ; string lb = " " ; string rb = " " ; for ( int j = 1 ; j <= i - 1 ; j ++ ) { if ( aa [ j ] == ' ▁ ' ) la += " " ; else la += aa [ j ] ; if ( bb [ j ] == ' ▁ ' ) lb += " " ; else lb += bb [ j ] ; } for ( int j = i ; j <= n + 1 ; j ++ ) { if ( aa [ j ] == ' ▁ ' ) ra += " " ; else ra += aa [ j ] ; if ( bb [ j ] == ' ▁ ' ) rb += " " ; else rb += bb [ j ] ; } if ( isPalindrome ( la + rb ) || isPalindrome ( lb + ra ) ) { ok = true ; break ; } } if ( ok ) cout << ( " Yes " ) ; else cout << ( " No " ) ; } int main ( ) { string A = " bdea " ; string B = " abbb " ; int N = 4 ; formPalindrome ( A , B , N ) ; }

Index/key variables: i, j
Accumulator variables: i, j, la, lb, ra, rb, stdc
Iterator variables: i, j
Boolean variables: ok
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minElements ( int A [ ] , int B [ ] , int N , int M ) { map < int , int > map ; for ( int i = 0 ; i < N ; i ++ ) { map [ A [ i ] ] = i ; } vector < int > subseq ; int l = 0 , r = -1 ; for ( int i = 0 ; i < M ; i ++ ) { if ( map . find ( B [ i ] ) != map . end ( ) ) { int e = map [ B [ i ] ] ; while ( l <= r ) { int m = l + ( r - l ) / 2 ; if ( subseq [ m ] < e ) l = m + 1 ; else r = m - 1 ; } if ( r + 1 < subseq . size ( ) ) { subseq [ r + 1 ] = e ; } else { subseq . push_back ( e ) ; } l = 0 ; r = subseq . size ( ) - 1 ; } } return N - subseq . size ( ) ; } int main ( ) { int A [ ] = { 1 , 2 , 3 , 4 , 5 } ; int B [ ] = { 2 , 5 , 6 , 4 , 9 , 12 } ; int M = sizeof ( A ) / sizeof ( A [ 0 ] ) ; int N = sizeof ( B ) / sizeof ( B [ 0 ] ) ; cout << minElements ( A , B , M , N ) ; return 0 ; }

Index/key variables: i, m
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool sfpa ( int V , int src , int Edges [ ] [ 3 ] , int M ) { vector < pair < int , int > > g [ V ] ; for ( int i = 0 ; i < M ; i ++ ) { int u = Edges [ i ] [ 0 ] ; int v = Edges [ i ] [ 1 ] ; int w = Edges [ i ] [ 2 ] ; g [ u ] . push_back ( { v , w } ) ; } vector < int > dist ( V , INT_MAX ) ; vector < bool > inQueue ( V , false ) ; vector < int > cnt ( V , 0 ) ; dist [ src ] = 0 ; queue < int > q ; q . push ( src ) ; inQueue [ src ] = true ; while ( ! q . empty ( ) ) { int u = q . front ( ) ; q . pop ( ) ; inQueue [ u ] = false ; for ( pair < int , int > x : g [ u ] ) { int v = x . first ; int cost = x . second ; if ( dist [ v ] > dist [ u ] + cost ) { dist [ v ] = dist [ u ] + cost ; if ( ! inQueue [ v ] ) { q . push ( v ) ; inQueue [ v ] = true ; cnt [ v ] ++ ; if ( cnt [ v ] >= V ) return true ; } } } } return false ; } int main ( ) { int N = 4 ; int src = 0 ; int M = 4 ; int Edges [ ] [ 3 ] = { { 0 , 1 , 1 } , { 1 , 2 , -1 } , { 2 , 3 , -1 } , { 3 , 0 , -1 } } ; if ( sfpa ( N , src , Edges , M ) == true ) cout << " Yes " << endl ; else cout << " No " << endl ; return 0 ; }

Index/key variables: V, i, src, u, v
Accumulator variables: i, stdc
Iterator variables: i, x
C++ program:
#include <iostream>
using namespace std ; #define INF  99999
int floyd_warshall ( int * graph , int V ) { int dist [ V ] [ V ] , i , j , k ; for ( i = 0 ; i < V ; i ++ ) { for ( j = 0 ; j < V ; j ++ ) { dist [ i ] [ j ] = * ( ( graph + i * V ) + j ) ; } } for ( k = 0 ; k < V ; k ++ ) { for ( i = 0 ; i < V ; i ++ ) { for ( j = 0 ; j < V ; j ++ ) { if ( dist [ i ] [ k ] + dist [ k ] [ j ] < dist [ i ] [ j ] ) { dist [ i ] [ j ] = dist [ i ] [ k ] + dist [ k ] [ j ] ; } } } } int sum = 0 ; for ( i = 0 ; i < V ; i ++ ) { for ( j = i + 1 ; j < V ; j ++ ) { sum += dist [ i ] [ j ] ; } } return sum ; } int sumOfshortestPath ( int N , int E , int edges [ ] [ 3 ] ) { int g [ N ] [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { g [ i ] [ j ] = INF ; } } for ( int i = 0 ; i < E ; i ++ ) { int u = edges [ i ] [ 0 ] ; int v = edges [ i ] [ 1 ] ; int w = edges [ i ] [ 2 ] ; g [ u ] [ v ] = w ; g [ v ] [ u ] = w ; } return floyd_warshall ( ( int * ) g , N ) ; } int main ( ) { int N = 4 ; int E = 3 ; int Edges [ ] [ 3 ] = { { 0 , 1 , 1 } , { 1 , 2 , 2 } , { 2 , 3 , 3 } } ; cout << sumOfshortestPath ( N , E , Edges ) ; return 0 ; }

Index/key variables: N, V, i, j, k, u, v
Accumulator variables: i, j, k, sum
Iterator variables: i, j, k
C++ program:
#include <iostream>
using namespace std ; void print_kth_string ( string s , int K ) { int N = s . length ( ) ; int i ; for ( i = 0 ; i < N ; i ++ ) { if ( s [ i ] == ' ▁ ' ) K -- ; if ( K == 1 ) break ; } while ( i ++ < N && s [ i ] != ' ▁ ' ) cout << s [ i ] ; } int main ( ) { string s ( "10 ▁ 20 ▁ 30 ▁ 40" ) ; int K = 4 ; print_kth_string ( s , K ) ; }

Index/key variables: i
Accumulator variables: K, i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minPeaks ( vector < int > list ) { int n = list . size ( ) ; vector < int > result ; for ( int i = 0 ; i < n ; i ++ ) { int min = INT_MAX ; int index = -1 ; int size = list . size ( ) ; for ( int j = 0 ; j < size ; j ++ ) { if ( j == 0 && j + 1 < size ) { if ( list [ j ] > list [ j + 1 ] && min > list [ j ] ) { min = list [ j ] ; index = j ; } } else if ( j == size - 1 && j - 1 >= 0 ) { if ( list [ j ] > list [ j - 1 ] && min > list [ j ] ) { min = list [ j ] ; index = j ; } } else if ( size == 1 ) { min = list [ j ] ; index = j ; } else if ( list [ j ] > list [ j - 1 ] && list [ j ] > list [ j + 1 ] && min > list [ j ] ) { min = list [ j ] ; index = j ; } } list . erase ( list . begin ( ) + index ) ; result . push_back ( min ) ; } cout << " [ " ; for ( int i = 0 ; i < result . size ( ) ; i ++ ) { cout << result [ i ] << " , ▁ " ; } cout << " ] " ; } int main ( ) { vector < int > arr = { 1 , 9 , 7 , 8 , 2 , 6 } ; minPeaks ( arr ) ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int binarySearch ( int arr [ ] , int N , int X ) { int start = 0 ; int end = N ; while ( start <= end ) { int mid = start + ( end - start ) / 2 ; if ( X == arr [ mid ] ) { return mid ; } else if ( X < arr [ mid ] ) { start = mid + 1 ; } else { end = mid - 1 ; } } return -1 ; } int main ( ) { int arr [ ] = { 5 , 4 , 3 , 2 , 1 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int X = 5 ; cout << binarySearch ( arr , N , X ) ; return 0 ; }

Index/key variables: mid
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool check_both_present ( int arr [ ] , int N , int a , int b ) { bool f1 = false , f2 = false ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] == a ) { f1 = true ; } if ( arr [ i ] == b ) { f2 = true ; } } if ( f1 && f2 ) { return true ; } else { return false ; } } void print_array ( int ans [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { cout << ans [ i ] << " ▁ " ; } } void build_AP ( int N , int a , int b ) { int arr [ N ] , ans [ N ] ; for ( int i = 0 ; i < N ; i ++ ) ans [ i ] = INT_MAX ; int flag = 0 ; if ( a > b ) { swap ( a , b ) ; } int diff = b - a ; for ( int start = 1 ; start <= a ; start ++ ) { for ( int d = 1 ; d <= diff ; d ++ ) { arr [ 0 ] = start ; for ( int i = 1 ; i < N ; i ++ ) { arr [ i ] = arr [ i - 1 ] + d ; } if ( check_both_present ( arr , N , a , b ) && arr [ N - 1 ] < ans [ N - 1 ] ) { for ( int i = 0 ; i < N ; i ++ ) { ans [ i ] = arr [ i ] ; } } } } print_array ( ans , N ) ; } int main ( ) { int N = 5 , A = 20 , B = 50 ; build_AP ( N , A , B ) ; return 0 ; }

Index/key variables: N, i
Accumulator variables: d, i, start, stdc
Iterator variables: d, i, start
Boolean variables: f1, f2
C++ program:
#include <bits/stdc++.h>
using namespace std ; string isPrefixOfWord ( string sentence , string Word ) { stringstream ss ( sentence ) ; vector < string > v ; string temp ; while ( ss >> temp ) { v . push_back ( temp ) ; } for ( int i = 0 ; i < v . size ( ) ; i ++ ) { for ( int j = 0 ; j < v [ i ] . size ( ) ; j ++ ) { if ( v [ i ] [ j ] != Word [ j ] ) break ; else if ( j == Word . size ( ) - 1 ) return v [ i ] ; } } return " - 1" ; } int main ( ) { string s = " Welcome ▁ to ▁ Geeksforgeeks " ; string word = " Gee " ; cout << isPrefixOfWord ( s , word ) << endl ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Pair { int idx ; string psf ; int jmps ; } ; void minJumps ( int arr [ ] , int dp [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) dp [ i ] = INT_MAX ; dp [ n - 1 ] = 0 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { int steps = arr [ i ] ; int min = INT_MAX ; for ( int j = 1 ; j <= steps && i + j < n ; j ++ ) { if ( dp [ i + j ] != INT_MAX && dp [ i + j ] < min ) { min = dp [ i + j ] ; } } if ( min != INT_MAX ) dp [ i ] = min + 1 ; } } void possiblePath ( int arr [ ] , int dp [ ] , int n ) { queue < Pair > Queue ; Pair p1 = { 0 , "0" , dp [ 0 ] } ; Queue . push ( p1 ) ; while ( Queue . size ( ) > 0 ) { Pair tmp = Queue . front ( ) ; Queue . pop ( ) ; if ( tmp . jmps == 0 ) { cout << tmp . psf << " STRNEWLINE " ; continue ; } for ( int step = 1 ; step <= arr [ tmp . idx ] ; step ++ ) { if ( tmp . idx + step < n && tmp . jmps - 1 == dp [ tmp . idx + step ] ) { string s1 = tmp . psf + " ▁ - > ▁ " + to_string ( ( tmp . idx + step ) ) ; Pair p2 = { tmp . idx + step , s1 , tmp . jmps - 1 } ; Queue . push ( p2 ) ; } } } } void Solution ( int arr [ ] , int dp [ ] , int size ) { minJumps ( arr , dp , size ) ; possiblePath ( arr , dp , size ) ; } int main ( ) { int arr [ ] = { 3 , 3 , 0 , 2 , 1 , 2 , 4 , 2 , 0 , 0 } ; int size = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int dp [ size ] ; Solution ( arr , dp , size ) ; }

Index/key variables: i, size
Accumulator variables: i, j, stdc, step
Iterator variables: i, j, step
Class/struct names: Pair
C++ program:
#include <bits/stdc++.h>
using namespace std ; void EvenLIS ( int arr [ ] , int n ) { int lis [ n ] ; for ( int i = 0 ; i < n ; i ++ ) lis [ i ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( abs ( arr [ i ] ) > abs ( arr [ j ] ) && abs ( arr [ i ] ) % 2 == 0 && abs ( arr [ j ] ) % 2 == 0 && lis [ i ] < lis [ j ] + 1 ) lis [ i ] = lis [ j ] + 1 ; } } int maxlen = 0 ; for ( int i = 0 ; i < n ; i ++ ) maxlen = max ( maxlen , lis [ i ] ) ; cout << maxlen << endl ; } int main ( ) { int arr [ ] = { 11 , -22 , 43 , -54 , 66 , 5 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; EvenLIS ( arr , N ) ; }

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 ; Node * right ; Node ( int val ) { data = val ; left = right = NULL ; } } ; int Sum ( Node * root , int & res ) { if ( root == NULL ) { return 0 ; } int leftSubSum = Sum ( root -> left , res ) ; int rightSubSum = Sum ( root -> right , res ) ; if ( root -> left and root -> right && leftSubSum == rightSubSum ) res += 1 ; return root -> data + leftSubSum + rightSubSum ; } int main ( ) { Node * root = new Node ( 9 ) ; root -> left = new Node ( 2 ) ; root -> left -> left = new Node ( -1 ) ; root -> left -> right = new Node ( 3 ) ; root -> right = new Node ( 4 ) ; root -> right -> right = new Node ( 0 ) ; int res = 0 ; Sum ( root , res ) ; cout << res ; }

Accumulator variables: res, stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left ; Node * right ; Node ( int val ) { data = val ; left = right = NULL ; } } ; void PrintAlternate ( Node * root ) { queue < Node * > Q ; Q . push ( root ) ; while ( ! Q . empty ( ) ) { int N = Q . size ( ) ; for ( int i = 0 ; i < N ; i ++ ) { Node * temp = Q . front ( ) ; Q . pop ( ) ; if ( i % 2 == 0 ) { cout << temp -> data << " ▁ " ; } if ( temp -> left ) { Q . push ( temp -> left ) ; } if ( temp -> right ) { Q . push ( temp -> right ) ; } } cout << endl ; } } int main ( ) { Node * root ; root = new Node ( 71 ) ; root -> left = new Node ( 88 ) ; root -> right = new Node ( 99 ) ; root -> left -> left = new Node ( 4 ) ; root -> left -> right = new Node ( 5 ) ; root -> right -> left = new Node ( 6 ) ; root -> right -> right = new Node ( 7 ) ; root -> left -> left -> left = new Node ( 8 ) ; root -> left -> left -> right = new Node ( 9 ) ; root -> left -> right -> left = new Node ( 10 ) ; root -> left -> right -> right = new Node ( 11 ) ; root -> right -> left -> right = new Node ( 13 ) ; root -> right -> right -> left = new Node ( 14 ) ; PrintAlternate ( root ) ; }

Accumulator variables: i, stdc
Iterator variables: i
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > countingSubarray ( vector < int > arr , int n ) { vector < int > a ( n ) ; vector < int > nsml ( n , -1 ) ; vector < int > nsmr ( n , n ) ; stack < int > st ; for ( int i = n - 1 ; i >= 0 ; i -- ) { while ( ! st . empty ( ) && arr [ st . top ( ) ] >= arr [ i ] ) st . pop ( ) ; nsmr [ i ] = ( ! st . empty ( ) ) ? st . top ( ) : n ; st . push ( i ) ; } while ( ! st . empty ( ) ) st . pop ( ) ; for ( int i = 0 ; i < n ; i ++ ) { while ( ! st . empty ( ) && arr [ st . top ( ) ] >= arr [ i ] ) st . pop ( ) ; nsml [ i ] = ( ! st . empty ( ) ) ? st . top ( ) : -1 ; st . push ( i ) ; } for ( int i = 0 ; i < n ; i ++ ) { nsml [ i ] ++ ; nsmr [ i ] -- ; int r = nsmr [ i ] - i + 1 ; int l = i - nsml [ i ] + 1 ; a [ i ] = r * l ; } return a ; } int main ( ) { int N = 5 ; vector < int > arr = { 3 , 2 , 4 , 1 , 5 } ; auto a = countingSubarray ( arr , N ) ; cout << " [ " ; int n = a . size ( ) - 1 ; for ( int i = 0 ; i < n ; i ++ ) cout << a [ i ] << " , ▁ " ; cout << a [ n ] << " ] " ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string reorderString ( string A , string B ) { int size_a = A . length ( ) ; int size_b = B . length ( ) ; int freq [ 300 ] = { 0 } ; for ( int i = 0 ; i < size_b ; i ++ ) freq [ B [ i ] ] ++ ; for ( int i = 0 ; i < size_a ; i ++ ) freq [ A [ i ] ] -- ; for ( int j = ' a ' ; j <= ' z ' ; j ++ ) { if ( freq [ j ] < 0 ) return " - 1" ; } string answer ; for ( int j = ' a ' ; j < A [ 0 ] ; j ++ ) while ( freq [ j ] > 0 ) { answer . push_back ( j ) ; freq [ j ] -- ; } int first = A [ 0 ] ; for ( int j = 0 ; j < size_a ; j ++ ) { if ( A [ j ] > A [ 0 ] ) break ; if ( A [ j ] < A [ 0 ] ) { answer += A ; A . clear ( ) ; break ; } } while ( freq [ first ] > 0 ) { answer . push_back ( first ) ; -- freq [ first ] ; } answer += A ; for ( int j = ' a ' ; j <= ' z ' ; j ++ ) while ( freq [ j ] -- ) answer . push_back ( j ) ; return answer ; } int main ( ) { string A = " aa " ; string B = " ababab " ; cout << reorderString ( A , B ) ; return 0 ; }

Index/key variables: first, i, j
Accumulator variables: answer, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool cmp ( vector < int > a , vector < int > b ) { if ( a [ 0 ] != b [ 0 ] ) return a [ 0 ] < b [ 0 ] ; return a [ 1 ] - b [ 1 ] ; } void maxConcurrentMeetingSlot ( vector < vector < int > > meetings ) { sort ( meetings . begin ( ) , meetings . end ( ) , cmp ) ; priority_queue < int , vector < int > , greater < int > > pq ; pq . push ( meetings [ 0 ] [ 1 ] ) ; int max_len = 0 , max_start = 0 ; int max_end = 0 ; for ( auto k : meetings ) { while ( pq . size ( ) > 0 && k [ 0 ] >= pq . top ( ) ) pq . pop ( ) ; pq . push ( k [ 1 ] ) ; if ( pq . size ( ) > max_len ) { max_len = pq . size ( ) ; max_start = k [ 0 ] ; max_end = pq . top ( ) ; } } cout << max_start << " ▁ " << max_end ; } int main ( ) { vector < vector < int > > meetings = { { 100 , 200 } , { 50 , 300 } , { 300 , 400 } } ; maxConcurrentMeetingSlot ( meetings ) ; }

Accumulator variables: stdc
Iterator variables: k