dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int mindist ( vector < int > & left , vector < int > & right ) { int res = INT_MAX ; for ( int i = 0 ; i < left . size ( ) ; ++ i ) { int num = left [ i ] ; int index = lower_bound ( right . begin ( ) , right . end ( ) , num ) - right . begin ( ) ; if ( index == 0 ) res = min ( res , abs ( num - right [ index ] ) ) ; else if ( index == right . size ( ) ) res = min ( res , abs ( num - right [ index - 1 ] ) ) ; else res = min ( res , min ( abs ( num - right [ index - 1 ] ) , abs ( num - right [ index ] ) ) ) ; } return res ; } int specialPairs ( vector < int > & nums ) { map < int , set < int > > m ; vector < int > vals ; for ( int i = 0 ; i < nums . size ( ) ; ++ i ) { m [ nums [ i ] ] . insert ( i ) ; } for ( auto p : m ) { vals . push_back ( p . first ) ; } int res = INT_MAX ; for ( int i = 0 ; i < vals . size ( ) ; ++ i ) { vector < int > vec ( m [ vals [ i ] ] . begin ( ) , m [ vals [ i ] ] . end ( ) ) ; for ( int i = 1 ; i < vec . size ( ) ; ++ i ) res = min ( res , abs ( vec [ i ] - vec [ i - 1 ] ) ) ; if ( i ) { int a = vals [ i ] ; vector < int > left ( m [ a ] . begin ( ) , m [ a ] . end ( ) ) ; int b = vals [ i - 1 ] ; vector < int > right ( m [ b ] . begin ( ) , m [ b ] . end ( ) ) ; res = min ( res , mindist ( left , right ) ) ; } } return res ; } int main ( ) { vector < int > arr { 0 , -10 , 5 , -5 , 1 } ; cout << specialPairs ( arr ) ; return 0 ; }

Index/key variables: a, b, i, index
Accumulator variables: stdc
Iterator variables: i, p
C++ program:
#include <bits/stdc++.h>
using ll = long long int ; using namespace std ; void maximumOccurringString ( string s , ll K ) { map < deque < char > , ll > M ; ll i ; deque < char > D ; for ( i = 0 ; i < K ; i ++ ) { D . push_back ( s [ i ] ) ; } M [ D ] ++ ; D . pop_front ( ) ; for ( ll j = i ; j < s . size ( ) ; j ++ ) { D . push_back ( s [ j ] ) ; M [ D ] ++ ; D . pop_front ( ) ; } ll maxi = INT_MIN ; deque < char > ans ; for ( auto it : M ) { if ( it . second > maxi ) { maxi = it . second ; ans = it . first ; } } for ( ll i = 0 ; i < ans . size ( ) ; i ++ ) { cout << ans [ i ] ; } } int main ( ) { string s = " bbbbbaaaaabbabababa " ; ll K = 5 ; maximumOccurringString ( s , K ) ; return 0 ; }

Index/key variables: D, i, j
Accumulator variables: i, j, stdc
Iterator variables: i, it, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; unordered_map < int , bool > mp ; struct Node { int key ; struct Node * left , * right ; } ; Node * newNode ( int key ) { Node * temp = new Node ; temp -> key = key ; temp -> left = temp -> right = NULL ; return ( temp ) ; } void calculateMin ( Node * root , vector < int > & levelMin ) { queue < Node * > qt ; qt . push ( root ) ; int count = 1 ; int min_v = INT_MAX ; while ( ! qt . empty ( ) ) { Node * temp = qt . front ( ) ; min_v = min ( min_v , temp -> key ) ; qt . pop ( ) ; if ( temp -> left ) { qt . push ( temp -> left ) ; } if ( temp -> right ) { qt . push ( temp -> right ) ; } count -- ; if ( count == 0 ) { levelMin . push_back ( min_v ) ; min_v = INT_MAX ; count = qt . size ( ) ; } } } void findNodes ( Node * root , vector < int > & levelMin , vector < int > & levelResult , int level ) { if ( root == NULL ) return ; findNodes ( root -> left , levelMin , levelResult , level + 1 ) ; findNodes ( root -> right , levelMin , levelResult , level + 1 ) ; for ( int i = 0 ; i < level ; i ++ ) { if ( root -> key <= levelMin [ i ] ) { levelResult [ i ] += 1 ; } } } void printNodes ( Node * root ) { vector < int > levelMin ; calculateMin ( root , levelMin ) ; int numLevels = levelMin . size ( ) ; vector < int > levelResult ( numLevels , 0 ) ; findNodes ( root , levelMin , levelResult , 0 ) ; for ( int i = 0 ; i < numLevels ; i ++ ) { cout << levelResult [ i ] << " ▁ " ; } } int main ( ) { Node * root = newNode ( 4 ) ; root -> left = newNode ( 3 ) ; root -> right = newNode ( 5 ) ; root -> right -> left = newNode ( 3 ) ; root -> right -> right = newNode ( 1 ) ; root -> left -> left = newNode ( 10 ) ; root -> left -> right = newNode ( 2 ) ; printNodes ( root ) ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; class myStructure { vector < int > arr ; map < int , int > Map ; public : void add ( int x ) { if ( Map . find ( x ) != Map . end ( ) ) return ; int index = arr . size ( ) ; arr . push_back ( x ) ; Map . insert ( std :: pair < int , int > ( x , index ) ) ; } void remove ( int x ) { if ( Map . find ( x ) == Map . end ( ) ) return ; int index = Map . at ( x ) ; Map . erase ( x ) ; int last = arr . size ( ) - 1 ; swap ( arr [ index ] , arr [ last ] ) ; arr . pop_back ( ) ; Map . at ( arr [ index ] ) = index ; } int getRandom ( ) { srand ( time ( NULL ) ) ; int random_index = rand ( ) % arr . size ( ) ; return arr . at ( random_index ) ; } int search ( int x ) { if ( Map . find ( x ) != Map . end ( ) ) return Map . at ( x ) ; return -1 ; } } ; int main ( ) { myStructure ds ; ds . add ( 10 ) ; ds . add ( 20 ) ; ds . add ( 30 ) ; ds . add ( 40 ) ; cout << ds . search ( 30 ) << endl ; ds . remove ( 20 ) ; ds . add ( 50 ) ; cout << ds . search ( 50 ) << endl ; cout << ds . getRandom ( ) << endl ; }

Index/key variables: index, last
Accumulator variables: stdc
Class/struct names: myStructure
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countSubArray ( int arr [ ] , int n ) { if ( n < 2 ) return n ; int i = max_element ( arr , arr + n ) - arr ; int j = min_element ( arr , arr + n ) - arr ; if ( i > j ) swap ( i , j ) ; return ( i + 1 ) * ( n - j ) ; } int main ( ) { int arr [ ] = { 4 , 1 , 2 , 3 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countSubArray ( arr , n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left , * right ; Node ( int item ) { data = item ; left = right = NULL ; } } ; int result = 0 ; vector < int > dfs ( Node * root , int distance ) { if ( root == NULL ) { vector < int > res ( distance + 1 , 0 ) ; return res ; } if ( root -> left == NULL && root -> right == NULL ) { vector < int > res ( distance + 1 , 0 ) ; res [ 1 ] ++ ; return res ; } vector < int > left = dfs ( root -> left , distance ) ; vector < int > right = dfs ( root -> right , distance ) ; vector < int > res ( distance + 1 , 0 ) ; for ( int i = res . size ( ) - 2 ; i >= 1 ; i -- ) res [ i + 1 ] = left [ i ] + right [ i ] ; for ( int l = 1 ; l < left . size ( ) ; l ++ ) { for ( int r = 0 ; r < right . size ( ) ; r ++ ) { if ( l + r <= distance ) { result += left [ l ] * right [ r ] ; } } } return res ; } int main ( ) { Node * root = new Node ( 1 ) ; root -> left = new Node ( 2 ) ; root -> right = new Node ( 3 ) ; root -> left -> left = new Node ( 4 ) ; int K = 3 ; dfs ( root , K ) ; cout << result ; }

Index/key variables: i, l, r
Accumulator variables: i, l, r, result, stdc
Iterator variables: i, l, r
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int right_angled ( int n ) { set < pair < int , pair < int , int > > > s ; for ( int x = 1 ; x <= n ; x ++ ) { for ( int y = 1 ; y <= n ; y ++ ) { if ( x * x + y * y <= n * n ) { int z = sqrt ( x * x + y * y ) ; if ( z * z != ( x * x + y * y ) ) continue ; vector < int > v ; v . push_back ( x ) ; v . push_back ( y ) ; v . push_back ( sqrt ( x * x + y * y ) ) ; sort ( v . begin ( ) , v . end ( ) ) ; s . insert ( { v [ 0 ] , { v [ 1 ] , v [ 2 ] } } ) ; } else break ; } } return s . size ( ) ; } int main ( ) { int n = 5 ; cout << right_angled ( n ) ; return 0 ; }

Accumulator variables: stdc, x, y
Iterator variables: x, y
C++ program:
#include <bits/stdc++.h>
using namespace std ; void maxAbsDiffLevelSum ( int N , int M , vector < int > cost , int Edges [ ] [ 2 ] ) { vector < int > adj [ N ] ; for ( int i = 0 ; i < M ; i ++ ) { int u = Edges [ i ] [ 0 ] ; int v = Edges [ i ] [ 1 ] ; adj [ u ] . push_back ( v ) ; } int maxSum = cost [ 0 ] , minSum = cost [ 0 ] ; queue < int > q ; q . push ( 0 ) ; while ( ! q . empty ( ) ) { int count = q . size ( ) ; int sum = 0 ; while ( count -- ) { int temp = q . front ( ) ; q . pop ( ) ; sum = sum + cost [ temp ] ; for ( int i = 0 ; i < adj [ temp ] . size ( ) ; i ++ ) { q . push ( adj [ temp ] [ i ] ) ; } } maxSum = max ( sum , maxSum ) ; minSum = min ( sum , minSum ) ; } cout << abs ( maxSum - minSum ) ; } int main ( ) { int N = 10 , M = 9 ; int Edges [ ] [ 2 ] = { { 0 , 1 } , { 0 , 2 } , { 0 , 3 } , { 1 , 4 } , { 1 , 5 } , { 3 , 6 } , { 6 , 7 } , { 6 , 8 } , { 6 , 9 } } ; vector < int > cost = { 1 , 2 , -1 , 3 , 4 , 5 , 8 , 6 , 12 , 7 } ; maxAbsDiffLevelSum ( N , M , cost , Edges ) ; return 0 ; }

Index/key variables: N, i, temp, u
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
#define ll  long long
using namespace std ; int findMinCost ( vector < int > & a , int k ) { int n = ( int ) a . size ( ) ; int max_ele = * max_element ( a . begin ( ) , a . end ( ) ) ; ll dp [ n + 1 ] ; for ( int i = 1 ; i <= n ; ++ i ) dp [ i ] = INT_MAX ; dp [ 0 ] = 0 ; for ( int i = 0 ; i < n ; ++ i ) { int freq [ max_ele + 1 ] ; memset ( freq , 0 , sizeof freq ) ; for ( int j = i ; j < n ; ++ j ) { freq [ a [ j ] ] ++ ; int cost = 0 ; for ( int x = 0 ; x <= max_ele ; ++ x ) { cost += ( freq [ x ] == 1 ) ? 0 : freq [ x ] ; } dp [ j + 1 ] = min ( dp [ i ] + cost + k , dp [ j + 1 ] ) ; } } return dp [ n ] ; } int main ( ) { vector < int > arr = { 1 , 2 , 1 , 1 , 1 } ; int K = 2 ; cout << findMinCost ( arr , K ) ; return 0 ; }

Index/key variables: i, j, n, x
Accumulator variables: cost, stdc
Iterator variables: i, j, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; void subArraySum ( int arr [ ] , int n , int sum ) { unordered_map < int , int > map ; int curr_sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { curr_sum = curr_sum + arr [ i ] ; if ( curr_sum == sum ) { cout << " Sum ▁ found ▁ between ▁ indexes ▁ " << 0 << " ▁ to ▁ " << i << endl ; return ; } if ( map . find ( curr_sum - sum ) != map . end ( ) ) { cout << " Sum ▁ found ▁ between ▁ indexes ▁ " << map [ curr_sum - sum ] + 1 << " ▁ to ▁ " << i << endl ; return ; } map [ curr_sum ] = i ; } cout << " No ▁ subarray ▁ with ▁ given ▁ sum ▁ exists " ; } int main ( ) { int arr [ ] = { 10 , 2 , -2 , -20 , 10 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int sum = -10 ; subArraySum ( arr , n , sum ) ; return 0 ; }

Index/key variables: curr_sum, i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; class node { public : int data ; node * left ; node * right ; } ; node * newNode ( int data ) { node * Node = new node ( ) ; Node -> data = data ; Node -> left = NULL ; Node -> right = NULL ; return ( Node ) ; } int identicalTrees ( node * a , node * b ) { if ( a == NULL && b == NULL ) return 1 ; if ( a != NULL && b != NULL ) { return ( a -> data == b -> data && identicalTrees ( a -> left , b -> left ) && identicalTrees ( a -> right , b -> right ) ) ; } return 0 ; } int main ( ) { node * root1 = newNode ( 1 ) ; node * root2 = newNode ( 1 ) ; root1 -> left = newNode ( 2 ) ; root1 -> right = newNode ( 3 ) ; root1 -> left -> left = newNode ( 4 ) ; root1 -> left -> right = newNode ( 5 ) ; root2 -> left = newNode ( 2 ) ; root2 -> right = newNode ( 3 ) ; root2 -> left -> left = newNode ( 4 ) ; root2 -> left -> right = newNode ( 5 ) ; if ( identicalTrees ( root1 , root2 ) ) cout << " Both ▁ tree ▁ are ▁ identical . " ; else cout << " Trees ▁ are ▁ not ▁ identical . " ; return 0 ; }

Accumulator variables: stdc
Class/struct names: node
C++ program:
#include " bits / stdc + + . h "
using namespace std ; const int maxn = 100005 ; int BITree [ 26 ] [ maxn ] ; int N ; void update_BITree ( int index , char C , int val ) { while ( index <= N ) { BITree [ C - ' a ' ] [ index ] += val ; index += ( index & - index ) ; } } int sum_BITree ( int index , char C ) { int s = 0 ; while ( index ) { s += BITree [ C - ' a ' ] [ index ] ; index -= ( index & - index ) ; } return s ; } void buildTree ( string str ) { for ( int i = 1 ; i <= N ; i ++ ) { update_BITree ( i , str [ i ] , 1 ) ; } cout << endl ; } char printCharacter ( string str , int l , int r , int k ) { int count = 0 ; char ans ; for ( char C = ' z ' ; C >= ' a ' ; C -- ) { int times = sum_BITree ( r , C ) - sum_BITree ( l - 1 , C ) ; count += times ; if ( count >= k ) { ans = C ; break ; } } return ans ; } void updateTree ( string str , int pos , char s ) { int index = pos ; update_BITree ( index , str [ index ] , -1 ) ; str [ index ] = s ; update_BITree ( index , s , 1 ) ; } int main ( ) { string str = " abcddef " ; N = str . size ( ) ; str = ' # ' + str ; int Q = 3 ; buildTree ( str ) ; cout << printCharacter ( str , 1 , 2 , 2 ) << endl ; updateTree ( str , 4 , ' g ' ) ; cout << printCharacter ( str , 1 , 5 , 4 ) << endl ; return 0 ; }

Index/key variables: i, index, maxn
Accumulator variables: C, count, i, index, s
Iterator variables: C, i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string generatePassword ( vector < string > arr , char T ) { string result ; for ( auto s : arr ) { int index ; for ( int i = 0 ; i < s . size ( ) ; i ++ ) { if ( s [ i ] == ' : ' ) { index = i ; break ; } } string name = s . substr ( 0 , index ) ; string number = s . substr ( index + 1 , s . size ( ) - index - 1 ) ; int n = name . length ( ) ; int max = 0 ; for ( int i = 0 ; i < number . length ( ) ; i ++ ) { int temp = number [ i ] - '0' ; if ( temp > max && temp <= n ) max = temp ; } if ( max == 0 ) result . push_back ( T ) ; else result . push_back ( name [ max - 1 ] ) ; } return result ; } int main ( ) { vector < string > arr = { " Geeks : 89167" , " gfg : 68795" } ; char T = ' X ' ; cout << ( generatePassword ( arr , T ) ) ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i, s
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > vec [ 100001 ] ; bool vis [ 100001 ] ; int cc = 1 ; void dfs ( int node ) { vis [ node ] = true ; for ( auto x : vec [ node ] ) { if ( ! vis [ x ] ) { cc ++ ; dfs ( x ) ; } } } void addEdge ( int u , int v ) { vec [ u ] . push_back ( v ) ; vec [ v ] . push_back ( u ) ; } void minEdgeRemoved ( int N , int M , int Edges [ ] [ 2 ] ) { for ( int i = 0 ; i < M ; i ++ ) { addEdge ( Edges [ i ] [ 0 ] , Edges [ i ] [ 1 ] ) ; } memset ( vis , false , sizeof ( vis ) ) ; int k = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( ! vis [ i ] ) { cc = 1 ; dfs ( i ) ; k ++ ; } } cout << M - N + k << endl ; } int main ( ) { int N = 3 , M = 2 ; int Edges [ ] [ 2 ] = { { 1 , 2 } , { 2 , 3 } } ; minEdgeRemoved ( N , M , Edges ) ; }

Index/key variables: i, node, u, v, x
Accumulator variables: cc, i, k, stdc
Iterator variables: i, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int ALPHA = 26 ; string getDiffString ( string str ) { string shift = " " ; for ( int i = 1 ; i < str . length ( ) ; i ++ ) { int dif = str [ i ] - str [ i - 1 ] ; if ( dif < 0 ) dif += ALPHA ; shift += ( dif + ' a ' ) ; } return shift ; } void groupShiftedString ( string str [ ] , int n ) { map < string , vector < int > > groupMap ; for ( int i = 0 ; i < n ; i ++ ) { string diffStr = getDiffString ( str [ i ] ) ; groupMap [ diffStr ] . push_back ( i ) ; } for ( auto it = groupMap . begin ( ) ; it != groupMap . end ( ) ; it ++ ) { vector < int > v = it -> second ; for ( int i = 0 ; i < v . size ( ) ; i ++ ) cout << str [ v [ i ] ] << " ▁ " ; cout << endl ; } } int main ( ) { string str [ ] = { " acd " , " dfg " , " wyz " , " yab " , " mop " , " bdfh " , " a " , " x " , " moqs " } ; int n = sizeof ( str ) / sizeof ( str [ 0 ] ) ; groupShiftedString ( str , n ) ; return 0 ; }

Index/key variables: diffStr, i
Accumulator variables: dif, i, it, shift, stdc
Iterator variables: i, it
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool pairFound = false ; struct Node { int data ; Node * left , * right ; } ; Node * newNode ( int data ) { Node * temp = new Node ( ) ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } void pairSum ( Node * root , int target , unordered_set < int > & S ) { if ( ! root ) return ; if ( ! root -> left and ! root -> right ) { if ( S . count ( target - root -> data ) ) { cout << target - root -> data << " ▁ " << root -> data ; pairFound = true ; return ; } else S . insert ( root -> data ) ; } pairSum ( root -> left , target , S ) ; pairSum ( root -> right , target , S ) ; } int main ( ) { Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; root -> right = newNode ( 3 ) ; root -> right -> left = newNode ( 6 ) ; root -> right -> right = newNode ( 7 ) ; root -> right -> right -> right = newNode ( 8 ) ; unordered_set < int > S ; int K = 13 ; pairSum ( root , K , S ) ; if ( pairFound == false ) cout << " - 1" ; return 0 ; }

Accumulator variables: stdc
Boolean variables: pairFound
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void countRooks ( int n , int k , int pos [ 2 ] [ 2 ] ) { int row [ n ] = { 0 } ; int col [ n ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) { row [ i ] = 0 ; col [ i ] = 0 ; } for ( int i = 0 ; i < k ; i ++ ) { row [ pos [ i ] [ 0 ] - 1 ] = 1 ; col [ pos [ i ] [ 1 ] - 1 ] = 1 ; } int res = n - k ; cout << res << " ▁ " << endl ; int ri = 0 , ci = 0 ; while ( res -- > 0 ) { while ( row [ ri ] == 1 ) { ri ++ ; } while ( col [ ci ] == 1 ) { ci ++ ; } cout << ( ri + 1 ) << " ▁ " << ( ci + 1 ) << " ▁ " << endl ; ri ++ ; ci ++ ; } } int main ( ) { int N = 4 ; int K = 2 ; int pos [ 2 ] [ 2 ] = { { 1 , 4 } , { 2 , 2 } } ; countRooks ( N , K , pos ) ; }

Index/key variables: ci, i, n, ri
Accumulator variables: ci, i, res, ri, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minInsertion ( string str ) { int n = str . length ( ) ; int res = 0 ; int count [ 26 ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) count [ str [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < 26 ; i ++ ) if ( count [ i ] % 2 == 1 ) res ++ ; return ( res == 0 ) ? 0 : res - 1 ; } int main ( ) { string str = " geeksforgeeks " ; cout << minInsertion ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, res, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool IsPalindrome ( string & str ) { int n = strlen ( str ) ; for ( int i = 0 ; i < n / 2 ; i ++ ) if ( str [ i ] != str [ n - 1 - i ] ) return false ; return true ; } void Query ( string & str , int Q ) { int i1 , i2 ; char ch ; for ( int q = 1 ; q <= Q ; q ++ ) { cin >> i1 >> i2 >> ch ; str [ i1 ] = str [ i2 ] = ch ; ( isPalindrome ( str ) == true ) ? cout << " YES " << endl : cout << " NO " << endl ; } } int main ( ) { char str [ ] = " geeks " ; int Q = 2 ; Query ( str , Q ) ; return 0 ; }

Index/key variables: i, i1, i2
Accumulator variables: i, q, stdc
Iterator variables: i, q
C++ program:
#include <bits/stdc++.h>
#define ll  long long
using namespace std ; bool check ( string ans , vector < string > & s , int n , int m ) { for ( int i = 1 ; i < n ; ++ i ) { int count = 0 ; for ( int j = 0 ; j < m ; ++ j ) { if ( ans [ j ] != s [ i ] [ j ] ) count ++ ; } if ( count > 1 ) return false ; } return true ; } string findString ( vector < string > & s ) { int n = s . size ( ) ; int m = s [ 0 ] . size ( ) ; string ans = s [ 0 ] ; int flag = 0 ; for ( int i = 0 ; i < m ; ++ i ) { for ( int j = 0 ; j < 26 ; ++ j ) { string x = ans ; x [ i ] = ( j + ' a ' ) ; if ( check ( x , s , n , m ) ) { ans = x ; flag = 1 ; break ; } } if ( flag == 1 ) break ; } if ( flag == 0 ) return " - 1" ; else return ans ; } int main ( ) { vector < string > s = { " geeks " , " teeds " } ; cout << findString ( s ) << endl ; }

Index/key variables: i, j
Accumulator variables: count, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getMinOps ( int arr [ ] , int n ) { int ans = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { ans += max ( arr [ i ] - arr [ i + 1 ] , 0 ) ; } return ans ; } int main ( ) { int arr [ ] = { 1 , 3 , 1 , 2 , 4 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << ( getMinOps ( arr , n ) ) ; }

Index/key variables: i
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxdiff ( int arr [ ] , int n ) { unordered_map < int , int > freq ; for ( int i = 0 ; i < n ; i ++ ) freq [ arr [ i ] ] ++ ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( freq [ arr [ i ] ] > freq [ arr [ j ] ] && arr [ i ] > arr [ j ] ) ans = max ( ans , freq [ arr [ i ] ] - freq [ arr [ j ] ] ) ; else if ( freq [ arr [ i ] ] < freq [ arr [ j ] ] && arr [ i ] < arr [ j ] ) ans = max ( ans , freq [ arr [ j ] ] - freq [ arr [ i ] ] ) ; } } return ans ; } int main ( ) { int arr [ ] = { 3 , 1 , 3 , 2 , 3 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maxdiff ( arr , n ) << 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 ; int maxdiff ( int arr [ ] , int n ) { unordered_map < int , int > freq ; int dist [ n ] ; int j = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( freq . find ( arr [ i ] ) == freq . end ( ) ) dist [ j ++ ] = arr [ i ] ; freq [ arr [ i ] ] ++ ; } sort ( dist , dist + j ) ; int min_freq = n + 1 ; int ans = 0 ; for ( int i = 0 ; i < j ; i ++ ) { int cur_freq = freq [ dist [ i ] ] ; ans = max ( ans , cur_freq - min_freq ) ; min_freq = min ( min_freq , cur_freq ) ; } return ans ; } int main ( ) { int arr [ ] = { 3 , 1 , 3 , 2 , 3 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maxdiff ( arr , n ) << endl ; return 0 ; }

Index/key variables: i, n
Accumulator variables: i, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int n , m , X ; int maxSum ( vector < vector < int > > grid ) { vector < vector < int > > prefsum ( n , vector < int > ( m ) ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int x = 0 ; x < m ; x ++ ) { if ( x == 0 ) prefsum [ i ] [ x ] = grid [ i ] [ x ] ; else prefsum [ i ] [ x ] = prefsum [ i ] [ x - 1 ] + grid [ i ] [ x ] ; } } vector < vector < int > > dp ( n , vector < int > ( X + 1 , INT_MIN ) ) ; for ( int i = 0 ; i < n ; i ++ ) dp [ i ] [ 0 ] = 0 ; for ( int i = 1 ; i <= min ( m , X ) ; ++ i ) { dp [ 0 ] [ i ] = dp [ 0 ] [ i - 1 ] + grid [ 0 ] [ i - 1 ] ; } for ( int i = 1 ; i < n ; ++ i ) { for ( int j = 1 ; j <= X ; ++ j ) { dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ; for ( int x = 1 ; x <= min ( j , m ) ; x ++ ) { dp [ i ] [ j ] = max ( dp [ i ] [ j ] , dp [ i - 1 ] [ j - x ] + prefsum [ i ] [ x - 1 ] ) ; } } } return dp [ n - 1 ] [ X ] ; } int main ( ) { n = 4 ; m = 4 ; X = 6 ; vector < vector < int > > grid = { { 3 , 2 , 6 , 1 } , { 1 , 9 , 2 , 4 } , { 4 , 1 , 3 , 9 } , { 3 , 8 , 2 , 1 } } ; int ans = maxSum ( grid ) ; cout << ( ans ) ; return 0 ; }

Index/key variables: X, i, j, x
Accumulator variables: i, stdc, x
Iterator variables: i, j, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findDiff ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; int count = 0 , max_count = 0 , min_count = n ; for ( int i = 0 ; i < ( n - 1 ) ; i ++ ) { if ( arr [ i ] == arr [ i + 1 ] ) { count += 1 ; continue ; } else { max_count = max ( max_count , count ) ; min_count = min ( min_count , count ) ; count = 0 ; } } return ( max_count - min_count ) ; } int main ( ) { int arr [ ] = { 7 , 8 , 4 , 5 , 4 , 1 , 1 , 7 , 7 , 2 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findDiff ( arr , n ) << " STRNEWLINE " ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int min_operations ( vector < int > & A ) { if ( A . size ( ) == 0 ) return 0 ; int ans = A [ 0 ] ; for ( int i = 1 ; i < A . size ( ) ; i ++ ) { ans += max ( A [ i ] - A [ i - 1 ] , 0 ) ; } return ans ; } int main ( ) { vector < int > A { 1 , 2 , 3 , 2 , 1 } ; cout << min_operations ( A ) << " STRNEWLINE " ; return 0 ; }

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