dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getNext ( int n ) { int c = n ; int c0 = 0 ; int c1 = 0 ; while ( ( ( c & 1 ) == 0 ) && ( c != 0 ) ) { c0 ++ ; c >>= 1 ; } while ( ( c & 1 ) == 1 ) { c1 ++ ; c >>= 1 ; } if ( c0 + c1 == 31 c0 + c1 == 0 ) return -1 ; return n + ( 1 << c0 ) + ( 1 << ( c1 - 1 ) ) - 1 ; } int main ( ) { int n = 5 ; cout << getNext ( n ) ; n = 8 ; cout << endl ; cout << getNext ( n ) ; return 0 ; }

Accumulator variables: c0, c1, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int totalFlips ( char * A , char * B , char * C , int N ) { int count = 0 ; for ( int i = 0 ; i < N ; ++ i ) { if ( A [ i ] == B [ i ] && C [ i ] == '1' ) ++ count ; else if ( A [ i ] != B [ i ] && C [ i ] == '0' ) ++ count ; } return count ; } int main ( ) { int N = 5 ; char a [ ] = "10100" ; char b [ ] = "00010" ; char c [ ] = "10011" ; cout << totalFlips ( a , b , c , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
void findTwoMissingNumbers ( int arr [ ] , int n ) { int XOR = arr [ 0 ] ; for ( int i = 1 ; i < n - 2 ; i ++ ) XOR ^= arr [ i ] ; for ( int i = 1 ; i <= n ; i ++ ) XOR ^= i ; int set_bit_no = XOR & ~ ( XOR - 1 ) ; for ( int i = 0 ; i < n - 2 ; i ++ ) { if ( arr [ i ] & set_bit_no ) x = x ^ arr [ i ] ; else y = y ^ arr [ i ] ; } for ( int i = 1 ; i <= n ; i ++ ) { if ( i & set_bit_no ) x = x ^ i ; else y = y ^ i ; } printf ( " Two ▁ Missing ▁ Numbers ▁ are % d % d " , x , y ) ; } int main ( ) { int arr [ ] = { 1 , 3 , 5 , 6 } ; int n = 2 + sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findTwoMissingNumbers ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: XOR, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countSetBits ( int n ) { int count = 0 ; while ( n ) { n &= ( n - 1 ) ; count ++ ; } return count ; } char findProffesion ( int level , int pos ) { int c = countSetBits ( pos - 1 ) ; return ( c % 2 ) ? ' d ' : ' e ' ; } int main ( void ) { int level = 3 , pos = 4 ; ( findProffesion ( level , pos ) == ' e ' ) ? cout << " Engineer " : cout << " Doctor " ; return 0 ; }

Accumulator variables: count, n, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int Max_Xor ( int arr [ ] , int n , int k ) { int maxXor = INT_MIN ; for ( int i = 0 ; i < ( 1 << n ) ; i ++ ) { if ( __builtin_popcount ( i ) == k ) { int cur_xor = 0 ; for ( int j = 0 ; j < n ; j ++ ) { if ( i & ( 1 << j ) ) cur_xor = cur_xor ^ arr [ j ] ; } maxXor = max ( maxXor , cur_xor ) ; } } return maxXor ; } int main ( ) { int arr [ ] = { 2 , 5 , 4 , 1 , 3 , 7 , 6 , 8 } ; int n = sizeof ( arr ) / sizeof ( int ) ; int k = 3 ; cout << Max_Xor ( arr , n , k ) ; return 0 ; }

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

Index/key variables: i
Accumulator variables: count_even, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; int children ; Node * left , * right ; } ; Node * newNode ( int data ) { Node * temp = new Node ; temp -> data = data ; temp -> left = temp -> right = NULL ; temp -> children = 0 ; return temp ; } int getElements ( Node * root ) { if ( ! root ) return 0 ; return getElements ( root -> left ) + getElements ( root -> right ) + 1 ; } void insertChildrenCount ( Node * & root ) { if ( ! root ) return ; root -> children = getElements ( root ) - 1 ; insertChildrenCount ( root -> left ) ; insertChildrenCount ( root -> right ) ; } int children ( Node * root ) { if ( ! root ) return 0 ; return root -> children + 1 ; } int randomNodeUtil ( Node * root , int count ) { if ( ! root ) return 0 ; if ( count == children ( root -> left ) ) return root -> data ; if ( count < children ( root -> left ) ) return randomNodeUtil ( root -> left , count ) ; return randomNodeUtil ( root -> right , count - children ( root -> left ) - 1 ) ; } int randomNode ( Node * root ) { srand ( time ( 0 ) ) ; int count = rand ( ) % ( root -> children + 1 ) ; return randomNodeUtil ( root , count ) ; } int main ( ) { Node * root = newNode ( 10 ) ; root -> left = newNode ( 20 ) ; root -> right = newNode ( 30 ) ; root -> left -> right = newNode ( 40 ) ; root -> left -> right = newNode ( 50 ) ; root -> right -> left = newNode ( 60 ) ; root -> right -> right = newNode ( 70 ) ; insertChildrenCount ( root ) ; cout << " A ▁ Random ▁ Node ▁ From ▁ Tree ▁ : ▁ " << randomNode ( root ) << endl ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <iostream>
using namespace std ; int rand2 ( ) { return rand ( ) & 1 ; } int rand3 ( ) { int r = 2 * rand2 ( ) + rand2 ( ) ; if ( r < 3 ) return r ; return rand3 ( ) ; } int main ( ) { srand ( time ( NULL ) ) ; for ( int i = 0 ; i < 100 ; i ++ ) cout << rand3 ( ) ; return 0 ; }

Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; struct Node * newNode ( int data ) { struct Node * newNode = new Node ; newNode -> data = data ; newNode -> left = newNode -> right = NULL ; return ( newNode ) ; } Node * deleteLeaves ( Node * root , int x ) { if ( root == NULL ) return nullptr ; root -> left = deleteLeaves ( root -> left , x ) ; root -> right = deleteLeaves ( root -> right , x ) ; if ( root -> data == x && root -> left == NULL && root -> right == NULL ) { return nullptr ; } return root ; } void inorder ( Node * root ) { if ( root == NULL ) return ; inorder ( root -> left ) ; cout << root -> data << " ▁ " ; inorder ( root -> right ) ; } int main ( void ) { struct Node * root = newNode ( 10 ) ; root -> left = newNode ( 3 ) ; root -> right = newNode ( 10 ) ; root -> left -> left = newNode ( 3 ) ; root -> left -> right = newNode ( 1 ) ; root -> right -> right = newNode ( 3 ) ; root -> right -> right -> left = newNode ( 3 ) ; root -> right -> right -> right = newNode ( 3 ) ; deleteLeaves ( root , 3 ) ; cout << " Inorder ▁ traversal ▁ after ▁ deletion ▁ : ▁ " ; inorder ( root ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; void _deleteTree ( Node * root ) { if ( root == NULL ) return ; queue < Node * > q ; q . push ( root ) ; while ( ! q . empty ( ) ) { Node * node = q . front ( ) ; q . pop ( ) ; if ( node -> left != NULL ) q . push ( node -> left ) ; if ( node -> right != NULL ) q . push ( node -> right ) ; free ( node ) ; } } void deleteTree ( Node * * node_ref ) { _deleteTree ( * node_ref ) ; * node_ref = NULL ; } Node * newNode ( int data ) { Node * temp = new Node ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } int main ( ) { Node * root = newNode ( 15 ) ; root -> left = newNode ( 10 ) ; root -> right = newNode ( 20 ) ; root -> left -> left = newNode ( 8 ) ; root -> left -> right = newNode ( 12 ) ; root -> right -> left = newNode ( 16 ) ; root -> right -> right = newNode ( 25 ) ; deleteTree ( & root ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <iostream>
#include <queue>
using namespace std ; struct Node { int data ; Node * left , * right ; } ; Node * newNode ( int data ) { Node * temp = new Node ; temp -> data = data ; temp -> left = NULL ; temp -> right = NULL ; return temp ; } int sizeoftree ( Node * root ) { if ( root == NULL ) return 0 ; queue < Node * > q ; int count = 1 ; q . push ( root ) ; while ( ! q . empty ( ) ) { Node * temp = q . front ( ) ; if ( temp -> left ) { count ++ ; q . push ( temp -> left ) ; } if ( temp -> right ) { count ++ ; q . push ( temp -> right ) ; } q . pop ( ) ; } return count ; } int main ( ) { Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; cout << " Size ▁ of ▁ the ▁ tree ▁ is ▁ " << sizeoftree ( root ) << endl ; return 0 ; }

Accumulator variables: count
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; class node { public : int data ; node * left ; node * right ; } ; int maxDepth ( node * node ) { if ( node == NULL ) return 0 ; else { int lDepth = maxDepth ( node -> left ) ; int rDepth = maxDepth ( node -> right ) ; if ( lDepth > rDepth ) return ( lDepth + 1 ) ; else return ( rDepth + 1 ) ; } } node * newNode ( int data ) { node * Node = new node ( ) ; Node -> data = data ; Node -> left = NULL ; Node -> right = NULL ; return ( Node ) ; } int main ( ) { node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; cout << " Height ▁ of ▁ tree ▁ is ▁ " << maxDepth ( root ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findPostOrderUtil ( int pre [ ] , int n , int minval , int maxval , int & preIndex ) { if ( preIndex == n ) return ; if ( pre [ preIndex ] < minval pre [ preIndex ] > maxval ) { return ; } int val = pre [ preIndex ] ; preIndex ++ ; findPostOrderUtil ( pre , n , minval , val , preIndex ) ; findPostOrderUtil ( pre , n , val , maxval , preIndex ) ; cout << val << " ▁ " ; } void findPostOrder ( int pre [ ] , int n ) { int preIndex = 0 ; findPostOrderUtil ( pre , n , INT_MIN , INT_MAX , preIndex ) ; } int main ( ) { int pre [ ] = { 40 , 30 , 35 , 80 , 100 } ; int n = sizeof ( pre ) / sizeof ( pre [ 0 ] ) ; findPostOrder ( pre , n ) ; return 0 ; }

Index/key variables: preIndex
Accumulator variables: preIndex, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left ; struct Node * right ; } ; int heightOfTreeUtil ( Node * root , bool isEven ) { if ( ! root ) return 0 ; if ( ! root -> left && ! root -> right ) { if ( isEven ) return 1 ; else return 0 ; } int left = heightOfTreeUtil ( root -> left , ! isEven ) ; int right = heightOfTreeUtil ( root -> right , ! isEven ) ; if ( left == 0 && right == 0 ) return 0 ; return ( 1 + max ( left , right ) ) ; } struct Node * newNode ( int data ) { struct Node * node = ( struct Node * ) malloc ( sizeof ( struct Node ) ) ; node -> data = data ; node -> left = NULL ; node -> right = NULL ; return ( node ) ; } int heightOfTree ( Node * root ) { return heightOfTreeUtil ( root , false ) ; } 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 ) ; cout << " Height ▁ of ▁ tree ▁ is ▁ " << heightOfTree ( root ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void fillDepth ( int parent [ ] , int i , int depth [ ] ) { if ( depth [ i ] ) return ; if ( parent [ i ] == -1 ) { depth [ i ] = 1 ; return ; } if ( depth [ parent [ i ] ] == 0 ) fillDepth ( parent , parent [ i ] , depth ) ; depth [ i ] = depth [ parent [ i ] ] + 1 ; } int findHeight ( int parent [ ] , int n ) { int depth [ n ] ; for ( int i = 0 ; i < n ; i ++ ) depth [ i ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) fillDepth ( parent , i , depth ) ; int ht = depth [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) if ( ht < depth [ i ] ) ht = depth [ i ] ; return ht ; } int main ( ) { int parent [ ] = { -1 , 0 , 0 , 1 , 1 , 3 , 5 } ; int n = sizeof ( parent ) / sizeof ( parent [ 0 ] ) ; cout << " Height ▁ is ▁ " << findHeight ( parent , n ) ; return 0 ; }

Index/key variables: i, n
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 ; } ; int height ( node * node ) ; bool isBalanced ( node * root ) { int lh ; int rh ; if ( root == NULL ) return 1 ; lh = height ( root -> left ) ; rh = height ( root -> right ) ; if ( abs ( lh - rh ) <= 1 && isBalanced ( root -> left ) && isBalanced ( root -> right ) ) return 1 ; return 0 ; } int max ( int a , int b ) { return ( a >= b ) ? a : b ; } int height ( node * node ) { if ( node == NULL ) return 0 ; return 1 + max ( height ( node -> left ) , height ( node -> right ) ) ; } node * newNode ( int data ) { node * Node = new node ( ) ; Node -> data = data ; Node -> left = NULL ; Node -> right = NULL ; return ( Node ) ; } int main ( ) { node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; root -> left -> left -> left = newNode ( 8 ) ; if ( isBalanced ( root ) ) cout << " Tree ▁ is ▁ balanced " ; else cout << " Tree ▁ is ▁ not ▁ balanced " ; return 0 ; }

Accumulator variables: stdc
Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left , * right ; } ; Node * newNode ( int data ) { Node * node = new Node ; node -> data = data ; node -> left = NULL ; node -> right = NULL ; return node ; } bool isLeaf ( Node * node ) { return node -> left && node -> left -> right == node && node -> right && node -> right -> left == node ; } int maxDepth ( Node * node ) { if ( node == NULL ) return 0 ; if ( isLeaf ( node ) ) return 1 ; return 1 + max ( maxDepth ( node -> left ) , maxDepth ( node -> right ) ) ; } int main ( ) { Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; root -> left -> left -> left = newNode ( 6 ) ; Node * L1 = root -> left -> left -> left ; Node * L2 = root -> left -> right ; Node * L3 = root -> right ; L1 -> right = L2 , L2 -> right = L3 , L3 -> right = L1 ; L3 -> left = L2 , L2 -> left = L1 , L1 -> left = L3 ; cout << " Height ▁ of ▁ tree ▁ is ▁ " << maxDepth ( root ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct node { int data ; struct node * left , * right ; } ; struct node * newNode ( int data ) { struct node * node = ( struct node * ) malloc ( sizeof ( struct node ) ) ; node -> data = data ; node -> left = NULL ; node -> right = NULL ; return ( node ) ; } int max ( int a , int b ) { return ( a > b ) ? a : b ; } int height ( struct node * node ) { if ( node == NULL ) return 0 ; return 1 + max ( height ( node -> left ) , height ( node -> right ) ) ; } int diameter ( struct node * tree ) { if ( tree == NULL ) return 0 ; int lheight = height ( tree -> left ) ; int rheight = height ( tree -> right ) ; int ldiameter = diameter ( tree -> left ) ; int rdiameter = diameter ( tree -> right ) ; return max ( lheight + rheight + 1 , max ( ldiameter , rdiameter ) ) ; } 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 ) ; cout << " Diameter ▁ of ▁ the ▁ given ▁ binary ▁ tree ▁ is ▁ " << diameter ( root ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findpath ( int N , int a [ ] ) { if ( a [ 0 ] ) { cout << " ▁ " << N + 1 ; for ( int i = 1 ; i <= N ; i ++ ) cout << " ▁ " << i ; return ; } for ( int i = 0 ; i < N - 1 ; i ++ ) { if ( ! a [ i ] && a [ i + 1 ] ) { for ( int j = 1 ; j <= i ; j ++ ) cout << " ▁ " << j ; cout << " ▁ " << N + 1 ; for ( int j = i + 1 ; j <= N ; j ++ ) cout << " ▁ " << j ; return ; } } for ( int i = 1 ; i <= N ; i ++ ) cout << " ▁ " << i ; cout << " ▁ " << N + 1 ; } int main ( ) { int N = 3 , arr [ ] = { 0 , 1 , 0 } ; findpath ( N , arr ) ; }

Index/key variables: i
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; void balBracketSequence ( string str ) { int n = str . size ( ) ; if ( str [ 0 ] == str [ n - 1 ] ) { cout << " No " << endl ; } else { int cntForOpen = 0 , cntForClose = 0 ; int check = 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == str [ 0 ] ) cntForOpen ++ ; else if ( str [ i ] == str [ n - 1 ] ) cntForOpen -- ; else cntForOpen ++ ; if ( cntForOpen < 0 ) { check = 0 ; break ; } } if ( check && cntForOpen == 0 ) { cout << " Yes , ▁ " ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == str [ n - 1 ] ) cout << ' ) ' ; else cout << ' ( ' ; } return ; } else { for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == str [ 0 ] ) cntForClose ++ ; else cntForClose -- ; if ( cntForClose < 0 ) { check = 0 ; break ; } } if ( check && cntForClose == 0 ) { cout << " Yes , ▁ " ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == str [ 0 ] ) cout << ' ( ' ; else cout << ' ) ' ; } return ; } } cout << " No " ; } } int main ( ) { string str = "123122" ; balBracketSequence ( str ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cntForClose, cntForOpen, i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct node { int data ; struct node * left , * right ; } ; struct node * newNode ( int data ) { struct node * node = ( struct node * ) malloc ( sizeof ( struct node ) ) ; node -> data = data ; node -> left = NULL ; node -> right = NULL ; return ( node ) ; } int diameterOpt ( struct node * root , int * height ) { int lh = 0 , rh = 0 ; int ldiameter = 0 , rdiameter = 0 ; if ( root == NULL ) { * height = 0 ; return 0 ; } ldiameter = diameterOpt ( root -> left , & lh ) ; rdiameter = diameterOpt ( root -> right , & rh ) ; * height = max ( lh , rh ) + 1 ; return max ( lh + rh + 1 , max ( ldiameter , rdiameter ) ) ; } 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 ) ; int height = 0 ; cout << " Diameter ▁ of ▁ the ▁ given ▁ binary ▁ tree ▁ is ▁ " << diameterOpt ( root , & height ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left , * right ; } ; int height ( Node * root , int & ans ) { if ( root == NULL ) return 0 ; int left_height = height ( root -> left , ans ) ; int right_height = height ( root -> right , ans ) ; ans = max ( ans , 1 + left_height + right_height ) ; return 1 + max ( left_height , right_height ) ; } int diameter ( Node * root ) { if ( root == NULL ) return 0 ; int ans = INT_MIN ; height ( root , ans ) ; return ans ; } struct Node * newNode ( int data ) { struct Node * node = new Node ; node -> data = data ; node -> left = node -> right = NULL ; return ( node ) ; } 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 ) ; printf ( " Diameter ▁ is ▁ % d STRNEWLINE " , diameter ( root ) ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <iostream>
using namespace std ; void getPostOrderBST ( int pre [ ] , int N ) { int pivotPoint = 0 ; for ( int i = 1 ; i < N ; i ++ ) { if ( pre [ 0 ] <= pre [ i ] ) { pivotPoint = i ; break ; } } for ( int i = pivotPoint - 1 ; i > 0 ; i -- ) { cout << pre [ i ] << " ▁ " ; } for ( int i = N - 1 ; i >= pivotPoint ; i -- ) { cout << pre [ i ] << " ▁ " ; } cout << pre [ 0 ] ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; void countSubstrings ( string s ) { int ans = 0 ; int subs = 1 ; char pre = '0' ; for ( auto & i : s ) { if ( pre == i ) { subs += 1 ; } else { subs = 1 ; } ans += subs ; pre = i ; } cout << ans << endl ; } int main ( ) { string s = " geeksforgeeks " ; countSubstrings ( s ) ; return 0 ; }

Accumulator variables: ans, subs
C++ program:
#include <bits/stdc++.h>
using namespace std ; void find_original_array ( vector < pair < int , int > > & A ) { unordered_map < int , vector < int > > mp ; vector < int > res ; unordered_map < int , bool > visited ; for ( auto & it : A ) { mp [ it . first ] . push_back ( it . second ) ; mp [ it . second ] . push_back ( it . first ) ; } auto it = mp . begin ( ) ; for ( ; it != mp . end ( ) ; it ++ ) { if ( it -> second . size ( ) == 1 ) { break ; } } int adjacent = it -> first ; res . push_back ( it -> first ) ; visited [ it -> first ] = true ; while ( res . size ( ) != A . size ( ) + 1 ) { for ( auto & elements : mp [ adjacent ] ) { if ( ! visited [ elements ] ) { res . push_back ( elements ) ; visited [ elements ] = true ; adjacent = elements ; } } } for ( auto it : res ) { cout << it << " ▁ " ; } } int main ( ) { vector < pair < int , int > > A = { { 5 , 1 } , { 3 , 4 } , { 3 , 5 } } ; find_original_array ( A ) ; return 0 ; }

Index/key variables: adjacent, elements
Accumulator variables: it, stdc
Iterator variables: it
C++ program:
#include <bits/stdc++.h>
using namespace std ; void constructTree ( int n , int d , int h ) { if ( d == 1 ) { if ( n == 2 && h == 1 ) { cout << "1 ▁ 2" << endl ; return ; } cout << " - 1" << endl ; return ; } if ( d > 2 * h ) { cout << " - 1" << endl ; return ; } for ( int i = 1 ; i <= h ; i ++ ) cout << i << " ▁ " << i + 1 << endl ; if ( d > h ) { cout << "1" << " ▁ " << h + 2 << endl ; for ( int i = h + 2 ; i <= d ; i ++ ) { cout << i << " ▁ " << i + 1 << endl ; } } for ( int i = d + 1 ; i < n ; i ++ ) { int k = 1 ; if ( d == h ) k = 2 ; cout << k << " ▁ " << i + 1 << endl ; } } int main ( ) { int n = 5 , d = 3 , h = 2 ; constructTree ( n , d , h ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int longestsubarray ( int a [ ] , int N ) { int maxlength = 0 , sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( a [ i ] == 1 ) { sum ++ ; } else { sum = 0 ; } maxlength = max ( maxlength , sum ) ; } return maxlength ; } void solveQueries ( int arr [ ] , int n , vector < vector < int > > Q , int k ) { int cntQuery = Q . size ( ) ; for ( int i = 0 ; i < cntQuery ; i ++ ) { if ( Q [ i ] [ 0 ] == 1 ) { cout << longestsubarray ( arr , n ) << " ▁ " ; } else { arr [ Q [ i ] [ 1 ] - 1 ] ^= 1 ; } } } int main ( ) { int N = 10 ; int arr [ ] = { 1 , 1 , 0 , 1 , 1 , 1 , 0 , 0 , 1 , 1 } ; vector < vector < int > > Q = { { 1 } , { 2 , 3 } , { 1 } } ; int K = 3 ; solveQueries ( arr , N , Q , K ) ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void uniqueElements ( int arr [ ] , int start , int K , map < int , int > & mp ) { set < int > st ; for ( int i = 0 ; i < K ; i ++ ) st . insert ( arr [ start + i ] ) ; set < int > :: iterator itr = st . begin ( ) ; for ( ; itr != st . end ( ) ; itr ++ ) mp [ * itr ] ++ ; } void checkAnswer ( map < int , int > & mp , int N , int K ) { for ( int i = 1 ; i <= N ; i ++ ) { if ( mp [ i ] == ( N - K + 1 ) ) { cout << i << " ▁ " ; return ; } } cout << -1 << " ▁ " ; } void smallestPresentNumber ( int arr [ ] , int N , int K ) { map < int , int > mp ; for ( int i = 0 ; i <= N - K ; i ++ ) { uniqueElements ( arr , i , K , mp ) ; } checkAnswer ( mp , N , K ) ; } void generateK ( int arr [ ] , int N ) { for ( int k = 1 ; k <= N ; k ++ ) smallestPresentNumber ( arr , N , k ) ; } int main ( ) { int arr [ ] = { 2 , 3 , 5 , 3 , 2 , 3 , 1 , 3 , 2 , 7 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; generateK ( arr , N ) ; return ( 0 ) ; }

Index/key variables: i
Accumulator variables: i, itr, k, stdc
Iterator variables: i, k