dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; class DisjointUnionSets { vector < int > rank , parent ; int n ; public : DisjointUnionSets ( int n ) { rank . resize ( n ) ; parent . resize ( n ) ; this -> n = n ; makeSet ( ) ; } void makeSet ( ) { for ( int i = 0 ; i < n ; i ++ ) parent [ i ] = i ; } int find ( int x ) { if ( parent [ x ] != x ) { return find ( parent [ x ] ) ; } return x ; } void Union ( int x , int y ) { int xRoot = find ( x ) ; int yRoot = find ( y ) ; if ( xRoot == yRoot ) return ; if ( rank [ xRoot ] < rank [ yRoot ] ) parent [ xRoot ] = yRoot ; else if ( rank [ yRoot ] < rank [ xRoot ] ) parent [ yRoot ] = xRoot ; else { parent [ yRoot ] = xRoot ; rank [ xRoot ] = rank [ xRoot ] + 1 ; } } } ; int countIslands ( vector < vector < int > > a ) { int n = a . size ( ) ; int m = a [ 0 ] . size ( ) ; DisjointUnionSets * dus = new DisjointUnionSets ( n * m ) ; for ( int j = 0 ; j < n ; j ++ ) { for ( int k = 0 ; k < m ; k ++ ) { if ( a [ j ] [ k ] == 0 ) continue ; if ( j + 1 < n && a [ j + 1 ] [ k ] == 1 ) dus -> Union ( j * ( m ) + k , ( j + 1 ) * ( m ) + k ) ; if ( j - 1 >= 0 && a [ j - 1 ] [ k ] == 1 ) dus -> Union ( j * ( m ) + k , ( j - 1 ) * ( m ) + k ) ; if ( k + 1 < m && a [ j ] [ k + 1 ] == 1 ) dus -> Union ( j * ( m ) + k , ( j ) * ( m ) + k + 1 ) ; if ( k - 1 >= 0 && a [ j ] [ k - 1 ] == 1 ) dus -> Union ( j * ( m ) + k , ( j ) * ( m ) + k - 1 ) ; if ( j + 1 < n && k + 1 < m && a [ j + 1 ] [ k + 1 ] == 1 ) dus -> Union ( j * ( m ) + k , ( j + 1 ) * ( m ) + k + 1 ) ; if ( j + 1 < n && k - 1 >= 0 && a [ j + 1 ] [ k - 1 ] == 1 ) dus -> Union ( j * m + k , ( j + 1 ) * ( m ) + k - 1 ) ; if ( j - 1 >= 0 && k + 1 < m && a [ j - 1 ] [ k + 1 ] == 1 ) dus -> Union ( j * m + k , ( j - 1 ) * m + k + 1 ) ; if ( j - 1 >= 0 && k - 1 >= 0 && a [ j - 1 ] [ k - 1 ] == 1 ) dus -> Union ( j * m + k , ( j - 1 ) * m + k - 1 ) ; } } int * c = new int [ n * m ] ; int numberOfIslands = 0 ; for ( int j = 0 ; j < n ; j ++ ) { for ( int k = 0 ; k < m ; k ++ ) { if ( a [ j ] [ k ] == 1 ) { int x = dus -> find ( j * m + k ) ; if ( c [ x ] == 0 ) { numberOfIslands ++ ; c [ x ] ++ ; } else c [ x ] ++ ; } } } return numberOfIslands ; } int main ( void ) { vector < vector < int > > a = { { 1 , 1 , 0 , 0 , 0 } , { 0 , 1 , 0 , 0 , 1 } , { 1 , 0 , 0 , 1 , 1 } , { 0 , 0 , 0 , 0 , 0 } , { 1 , 0 , 1 , 0 , 1 } } ; cout << " Number ▁ of ▁ Islands ▁ is : ▁ " << countIslands ( a ) << endl ; }

Index/key variables: i, j, k, x, xRoot, yRoot
Accumulator variables: i, j, k, numberOfIslands, stdc
Iterator variables: i, j, k
Class/struct names: DisjointUnionSets
C++ program:
#include <bits/stdc++.h>
using namespace std ; int squareSum ( int N ) { int sum = ( int ) ( N * ( N + 1 ) * ( 2 * N + 1 ) ) / 6 ; return sum ; } int findMaxN ( int X ) { int N = sqrt ( X ) ; for ( int i = 1 ; i <= N ; i ++ ) { if ( squareSum ( i ) > X ) return i - 1 ; } return -1L ; } int main ( ) { int X = 25 ; cout << findMaxN ( X ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int max_min ( int a [ ] , int n ) { if ( n <= 1 ) return INT_MAX ; int f_min = a [ 0 ] , s_min = INT_MAX ; int f_max = a [ 0 ] , s_max = INT_MIN ; for ( int i = 1 ; i < n ; i ++ ) { if ( a [ i ] <= f_min ) { s_min = f_min ; f_min = a [ i ] ; } else if ( a [ i ] < s_min ) { s_min = a [ i ] ; } if ( a [ i ] >= f_max ) { s_max = f_max ; f_max = a [ i ] ; } else if ( a [ i ] > s_max ) { s_max = a [ i ] ; } } return min ( ( f_max - s_min ) , ( s_max - f_min ) ) ; } int main ( ) { int a [ ] = { 1 , 3 , 3 , 7 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << max_min ( a , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minimal ( int a [ ] , int n ) { int lo = 0 , hi = n - 1 ; while ( lo < hi ) { int mid = ( lo + hi ) >> 1 ; if ( a [ mid ] < a [ mid + 1 ] ) { hi = mid ; } else { lo = mid + 1 ; } } return lo ; } int main ( ) { int a [ ] = { 8 , 5 , 4 , 3 , 4 , 10 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; int ind = minimal ( a , n ) ; cout << a [ ind ] ; }

Index/key variables: ind, mid
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findIndices ( int arr [ ] , int n ) { int leftMin = 0 , rightMin = 0 ; int leftMax = 0 , rightMax = 0 ; int min = arr [ 0 ] , max = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] < min ) { leftMin = rightMin = i ; min = arr [ i ] ; } else if ( arr [ i ] == min ) rightMin = i ; if ( arr [ i ] > max ) { leftMax = rightMax = i ; max = arr [ i ] ; } else if ( arr [ i ] == max ) rightMax = i ; } cout << " Minimum ▁ left ▁ : ▁ " << leftMin << " STRNEWLINE " ; cout << " Minimum ▁ right ▁ : ▁ " << rightMin << " STRNEWLINE " ; cout << " Maximum ▁ left ▁ : ▁ " << leftMax << " STRNEWLINE " ; cout << " Maximum ▁ right ▁ : ▁ " << rightMax << " STRNEWLINE " ; } int main ( ) { int arr [ ] = { 2 , 1 , 1 , 2 , 1 , 5 , 6 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findIndices ( arr , n ) ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void diagonalsMinMax ( int mat [ 5 ] [ 5 ] ) { int n = sizeof ( * mat ) / 4 ; if ( n == 0 ) return ; int principalMin = mat [ 0 ] [ 0 ] , principalMax = mat [ 0 ] [ 0 ] ; int secondaryMin = mat [ n - 1 ] [ 0 ] , secondaryMax = mat [ n - 1 ] [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 1 ; j < n ; j ++ ) { if ( i == j ) { if ( mat [ i ] [ j ] < principalMin ) { principalMin = mat [ i ] [ j ] ; } if ( mat [ i ] [ j ] > principalMax ) { principalMax = mat [ i ] [ j ] ; } } if ( ( i + j ) == ( n - 1 ) ) { if ( mat [ i ] [ j ] < secondaryMin ) { secondaryMin = mat [ i ] [ j ] ; } if ( mat [ i ] [ j ] > secondaryMax ) { secondaryMax = mat [ i ] [ j ] ; } } } } cout << ( " Principal ▁ Diagonal ▁ Smallest ▁ Element : ▁ " ) << principalMin << endl ; cout << ( " Principal ▁ Diagonal ▁ Greatest ▁ Element ▁ : ▁ " ) << principalMax << endl ; cout << ( " Secondary ▁ Diagonal ▁ Smallest ▁ Element : ▁ " ) << secondaryMin << endl ; cout << ( " Secondary ▁ Diagonal ▁ Greatest ▁ Element : ▁ " ) << secondaryMax << endl ; } int main ( ) { int matrix [ 5 ] [ 5 ] = { { 1 , 2 , 3 , 4 , -10 } , { 5 , 6 , 7 , 8 , 6 } , { 1 , 2 , 11 , 3 , 4 } , { 5 , 6 , 70 , 5 , 8 } , { 4 , 9 , 7 , 1 , -5 } } ; diagonalsMinMax ( matrix ) ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define ll  long long
ll int getCount ( vector < ll int > v , int n ) { sort ( ( v ) . begin ( ) , ( v ) . end ( ) ) ; ll int cnt = 0 ; for ( ll int i = 0 ; i < n ; i ++ ) { ll int tmp = v . end ( ) - 1 - upper_bound ( ( v ) . begin ( ) , ( v ) . end ( ) , v [ i ] - 1 ) ; if ( tmp == v [ i ] ) cnt ++ ; } return cnt ; } int main ( ) { ll int n ; n = 4 ; vector < ll int > v ; v . push_back ( 1 ) ; v . push_back ( 2 ) ; v . push_back ( 3 ) ; v . push_back ( 4 ) ; cout << getCount ( v , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cnt, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countSegments ( int a [ ] , int n , int x ) { bool flag = false ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] > x ) { flag = true ; } else { if ( flag ) count += 1 ; flag = false ; } } if ( flag ) count += 1 ; return count ; } int main ( ) { int a [ ] = { 8 , 25 , 10 , 19 , 19 , 18 , 20 , 11 , 18 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; int x = 13 ; cout << countSegments ( a , n , x ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
Boolean variables: flag
C++ program:
#include " iostream "
#include " unordered _ map "
using namespace std ; void findElements ( int arr [ ] , int n , int l , int r ) { unordered_map < int , int > mp ; for ( int i = 0 ; i < n ; ++ i ) { mp [ arr [ i ] ] ++ ; } for ( int i = 0 ; i < n ; ++ i ) { if ( l <= mp [ arr [ i ] ] && mp [ arr [ i ] <= r ] ) { cout << arr [ i ] << " ▁ " ; } } } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 3 , 2 , 2 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int l = 2 , r = 3 ; findElements ( arr , n , l , r ) ; return 0 ; }

Index/key variables: i
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; class gfg { public : long count_triples ( int n , int k ) ; } ; long gfg :: count_triples ( int n , int k ) { int i = 0 , j = 0 , l = 0 ; int count = 0 ; for ( i = 1 ; i <= n ; i ++ ) { for ( j = 1 ; j <= n ; j ++ ) { for ( l = 1 ; l <= n ; l ++ ) { if ( ( i + j ) % k == 0 && ( i + l ) % k == 0 && ( j + l ) % k == 0 ) count ++ ; } } } return count ; } int main ( ) { gfg g ; int n = 3 ; int k = 2 ; long ans = g . count_triples ( n , k ) ; cout << ans ; }

Accumulator variables: count, i, j, l
Iterator variables: i, j, l
Class/struct names: gfg
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define maxs  1000001
int kthSmallestLargest ( int * arr , int n , int k ) { int max_val = * max_element ( arr , arr + n ) ; int hash [ max_val + 1 ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) hash [ arr [ i ] ] ++ ; int count = 0 ; for ( int i = 0 ; i <= max_val ; i ++ ) { while ( hash [ i ] > 0 ) { count ++ ; if ( count == k ) return i ; hash [ i ] -- ; } } return -1 ; } int main ( ) { int arr [ ] = { 11 , 6 , 2 , 9 , 4 , 3 , 16 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) , k = 3 ; cout << " kth ▁ smallest ▁ number ▁ is : ▁ " << kthSmallestLargest ( arr , n , k ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findSum ( int minEle , int maxEle ) { return minEle + maxEle ; } int findProduct ( int minEle , int maxEle ) { return minEle * maxEle ; } int main ( ) { int arr [ ] = { 12 , 1234 , 45 , 67 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sort ( arr , arr + n ) ; int minEle = arr [ 0 ] ; int maxEle = arr [ n - 1 ] ; cout << " Sum ▁ = ▁ " << findSum ( minEle , maxEle ) << endl ; cout << " Product ▁ = ▁ " << findProduct ( minEle , maxEle ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <iostream>
#include <cmath>
#include <vector>
using namespace std ; int bsearch ( vector < int > A , int key_to_search ) { int n = ( int ) A . size ( ) ; int lg = log2 ( n - 1 ) + 1 ; int pos = 0 ; for ( int i = lg ; i >= 0 ; i -- ) { if ( A [ pos ] == key_to_search ) return pos ; int new_pos = pos | ( 1 << i ) ; if ( ( new_pos < n ) && ( A [ new_pos ] <= key_to_search ) ) pos = new_pos ; } return ( ( A [ pos ] == key_to_search ) ? pos : -1 ) ; } int main ( void ) { vector < int > A = { -2 , 10 , 100 , 250 , 32315 } ; cout << bsearch ( A , 10 ) << endl ; return 0 ; }

Index/key variables: new_pos, pos
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void answerQueries ( int a [ ] [ 2 ] , int n , int queries [ ] , int q ) { vector < int > v ; unordered_map < int , int > mpp ; for ( int i = 0 ; i < n ; i ++ ) { v . push_back ( a [ i ] [ 0 ] ) ; mpp [ a [ i ] [ 0 ] ] = 1 ; v . push_back ( a [ i ] [ 1 ] ) ; mpp [ a [ i ] [ 1 ] ] = 2 ; } sort ( v . begin ( ) , v . end ( ) ) ; for ( int i = 0 ; i < q ; i ++ ) { int num = queries [ i ] ; int ind = lower_bound ( v . begin ( ) , v . end ( ) , num ) - v . begin ( ) ; if ( v [ ind ] == num ) { cout << " Yes STRNEWLINE " ; } else { if ( mpp [ v [ ind ] ] == 2 ) cout << " Yes STRNEWLINE " ; cout << " No STRNEWLINE " ; } } } int main ( ) { int a [ ] [ 2 ] = { { 5 , 6 } , { 1 , 3 } , { 8 , 10 } } ; int n = 3 ; int queries [ ] = { 2 , 3 , 4 , 7 } ; int q = sizeof ( queries ) / sizeof ( queries [ 0 ] ) ; answerQueries ( a , n , queries , q ) ; return 0 ; }

Index/key variables: i, ind
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; float findmedian ( int a [ ] , int n1 , int b [ ] , int n2 ) { int i = 0 ; int j = 0 ; int k ; int m1 = -1 , m2 = -1 ; for ( k = 0 ; k <= ( n1 + n2 ) / 2 ; k ++ ) { if ( i < n1 && j < n2 ) { if ( a [ i ] < b [ j ] ) { m2 = m1 ; m1 = a [ i ] ; i ++ ; } else { m2 = m1 ; m1 = b [ j ] ; j ++ ; } } else if ( i == n1 ) { m2 = m1 ; m1 = b [ j ] ; j ++ ; } else if ( j == n2 ) { m2 = m1 ; m1 = a [ i ] ; i ++ ; } } if ( ( n1 + n2 ) % 2 == 0 ) return ( m1 + m2 ) * 1.0 / 2 ; return m1 ; } int main ( ) { int a [ ] = { 1 , 12 , 15 , 26 , 38 } ; int b [ ] = { 2 , 13 , 24 } ; int n1 = sizeof ( a ) / sizeof ( a [ 0 ] ) ; int n2 = sizeof ( b ) / sizeof ( b [ 0 ] ) ; printf ( " % f " , findmedian ( a , n1 , b , n2 ) ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, k, stdc
Iterator variables: k
C++ program:
#include " bits / stdc + + . h "
using namespace std ; void printNSE ( int arr [ ] , int n ) { int next , i , j ; for ( i = 0 ; i < n ; i ++ ) { next = -1 ; for ( j = i + 1 ; j < n ; j ++ ) { if ( arr [ i ] > arr [ j ] ) { next = arr [ j ] ; break ; } } cout << arr [ i ] << " ▁ - - ▁ " << next << endl ; } } int main ( ) { int arr [ ] = { 11 , 13 , 21 , 3 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; printNSE ( arr , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int longestSubarray ( int input [ ] , int length ) { int prev = -1 ; int current , next ; int prevCount = 0 , currentCount = 1 ; int longest = 1 ; current = input [ 0 ] ; for ( int i = 1 ; i < length ; i ++ ) { next = input [ i ] ; if ( next == current ) { currentCount ++ ; } else if ( next == prev ) { prevCount += currentCount ; prev = current ; current = next ; currentCount = 1 ; } else { longest = max ( longest , currentCount + prevCount ) ; prev = current ; prevCount = currentCount ; current = next ; currentCount = 1 ; } } return max ( longest , currentCount + prevCount ) ; } int main ( ) { int input [ ] = { 5 , 5 , 6 , 7 , 6 } ; int n = sizeof ( input ) / sizeof ( int ) ; cout << longestSubarray ( input , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: currentCount, i, prevCount, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; Node * reverseTreePathUtil ( Node * root , int data , map < int , int > & temp , int level , int & nextpos ) { if ( root == NULL ) return NULL ; if ( data == root -> data ) { temp [ level ] = root -> data ; root -> data = temp [ nextpos ] ; nextpos ++ ; return root ; } temp [ level ] = root -> data ; Node * left , * right ; left = reverseTreePathUtil ( root -> left , data , temp , level + 1 , nextpos ) ; if ( left == NULL ) right = reverseTreePathUtil ( root -> right , data , temp , level + 1 , nextpos ) ; if ( left right ) { root -> data = temp [ nextpos ] ; nextpos ++ ; return ( left ? left : right ) ; } return NULL ; } void reverseTreePath ( Node * root , int data ) { map < int , int > temp ; int nextpos = 0 ; reverseTreePathUtil ( root , data , temp , 0 , nextpos ) ; } void inorder ( Node * root ) { if ( root != NULL ) { inorder ( root -> left ) ; cout << root -> data << " ▁ " ; inorder ( root -> right ) ; } } Node * newNode ( int data ) { Node * temp = new Node ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } int main ( ) { Node * root = newNode ( 7 ) ; root -> left = newNode ( 6 ) ; root -> right = newNode ( 5 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 3 ) ; root -> right -> left = newNode ( 2 ) ; root -> right -> right = newNode ( 1 ) ; int data = 4 ; reverseTreePath ( root , data ) ; inorder ( root ) ; return 0 ; }

Index/key variables: level, nextpos
Accumulator variables: nextpos, stdc
Class/struct names: Node
C++ program:
#include <algorithm>
#include <iostream>
using namespace std ; int binarySearch ( int * searchSpace , int s , int e , int num ) { int ans ; while ( s <= e ) { int mid = ( s + e ) / 2 ; if ( searchSpace [ mid ] >= num ) { ans = mid ; e = mid - 1 ; } else s = mid + 1 ; } return ans ; } int longestSubArr ( int * arr , int n ) { int searchSpace [ n ] ; int index [ n ] ; int j = 0 ; int ans = 0 ; for ( int i = 0 ; i < n ; ++ i ) { if ( j == 0 or searchSpace [ j - 1 ] < arr [ i ] ) { searchSpace [ j ] = arr [ i ] ; index [ j ] = i ; j ++ ; } int idx = binarySearch ( searchSpace , 0 , j - 1 , arr [ i ] ) ; ans = max ( ans , i - index [ idx ] + 1 ) ; } return ans ; } int main ( int argc , char const * argv [ ] ) { int arr [ ] = { -5 , -1 , 7 , 5 , 1 , -2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << longestSubArr ( arr , n ) << endl ; return 0 ; }

Index/key variables: i, idx, j, mid, n
Accumulator variables: j
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void pairedElements ( int arr [ ] , int sum , int n ) { int low = 0 ; int high = n - 1 ; while ( low < high ) { if ( arr [ low ] + arr [ high ] == sum ) { cout << " The ▁ pair ▁ is ▁ : ▁ ( " << arr [ low ] << " , ▁ " << arr [ high ] << " ) " << endl ; } if ( arr [ low ] + arr [ high ] > sum ) { high -- ; } else { low ++ ; } } } int main ( ) { int arr [ ] = { 2 , 3 , 4 , -2 , 6 , 8 , 9 , 11 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sort ( arr , arr + n ) ; pairedElements ( arr , 6 , n ) ; }

Index/key variables: high, low
Accumulator variables: high, low, stdc
C++ program:
#include <iostream>
#include <string>
using namespace std ; bool isSuffix ( string s1 , string s2 ) { int n1 = s1 . length ( ) , n2 = s2 . length ( ) ; if ( n1 > n2 ) return false ; for ( int i = 0 ; i < n1 ; i ++ ) if ( s1 [ n1 - i - 1 ] != s2 [ n2 - i - 1 ] ) return false ; return true ; } int main ( ) { string s1 = " geeks " , s2 = " geeksforgeeks " ; bool result = isSuffix ( s1 , s2 ) ; if ( result ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Accumulator variables: i
Iterator variables: i
C++ program:
#include <iostream>
#include <string>
using namespace std ; bool checkIfAllTogether ( string s , char c ) { bool oneSeen = false ; int i = 0 , n = s . length ( ) ; while ( i < n ) { if ( s [ i ] == c ) { if ( oneSeen == true ) return false ; while ( i < n && s [ i ] == c ) i ++ ; oneSeen = true ; } else i ++ ; } return true ; } int main ( ) { string s = "110029" ; if ( checkIfAllTogether ( s , '1' ) ) cout << " Yes " << endl ; else cout << " No " << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Boolean variables: oneSeen
C++ program:
#include <iostream>
using namespace std ; bool search ( int arr [ ] , int n , int x ) { int front = 0 , back = n - 1 ; while ( front <= back ) { if ( arr [ front ] == x arr [ back ] == x ) return true ; front ++ ; back -- ; } return false ; } int main ( ) { int arr [ ] = { 10 , 20 , 80 , 30 , 60 , 50 , 110 , 100 , 130 , 170 } ; int x = 130 ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; if ( search ( arr , n , x ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: back, front
Accumulator variables: back, front
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findValue ( int X , int Y , int P ) { if ( P % 2 == 0 ) return ( max ( X , Y ) / min ( X , Y ) ) ; else return ( max ( 2 * X , Y ) / min ( 2 * X , Y ) ) ; } int main ( ) { int X = 1 , Y = 2 , P = 1 ; cout << findValue ( X , Y , P ) << endl ; X = 3 , Y = 7 , P = 2 ; cout << findValue ( X , Y , P ) << endl ; }

Accumulator variables: stdc
C++ program:
#include <climits>
#include <iostream>
using namespace std ; int sum ( int arr [ ] , int from , int to ) { int total = 0 ; for ( int i = from ; i <= to ; i ++ ) total += arr [ i ] ; return total ; } int findMax ( int arr [ ] , int n , int k ) { int dp [ k + 1 ] [ n + 1 ] = { 0 } ; for ( int i = 1 ; i <= n ; i ++ ) dp [ 1 ] [ i ] = sum ( arr , 0 , i - 1 ) ; for ( int i = 1 ; i <= k ; i ++ ) dp [ i ] [ 1 ] = arr [ 0 ] ; for ( int j = 2 ; j <= n ; j ++ ) { int best = INT_MAX ; for ( int p = 1 ; p <= j ; p ++ ) best = min ( best , max ( dp [ i - 1 ] [ p ] , sum ( arr , p , j - 1 ) ) ) ; dp [ i ] [ j ] = best ; } } return dp [ k ] [ n ] ; } int main ( ) { int arr [ ] = { 10 , 20 , 60 , 50 , 30 , 40 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 3 ; cout << findMax ( arr , n , k ) << endl ; return 0 ; }

Index/key variables: i, j, k, n, p
Accumulator variables: i, j, p, total
Iterator variables: i, j, p
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countCrossLine ( int arr [ ] , int n ) { int count_crossline = 0 ; int i , key , j ; for ( i = 1 ; i < n ; i ++ ) { key = arr [ i ] ; j = i - 1 ; while ( j >= 0 && arr [ j ] > key ) { arr [ j + 1 ] = arr [ j ] ; j = j - 1 ; count_crossline ++ ; } arr [ j + 1 ] = key ; } return count_crossline ; } int main ( ) { int arr [ ] = { 4 , 3 , 1 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countCrossLine ( arr , n ) << endl ; return 0 ; }

Index/key variables: i, j
Accumulator variables: count_crossline, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string remVowel ( string str ) { regex r ( " [ aeiouAEIOU ] " ) ; return regex_replace ( str , r , " " ) ; } int main ( ) { string str = " GeeeksforGeeks ▁ - ▁ A ▁ Computer ▁ Science ▁ Portal ▁ for ▁ Geeks " ; cout << ( remVowel ( str ) ) ; return 0 ; }

Index/key variables: aeiouAEIOU
Accumulator variables: stdc
C++ program:
#include <iostream>
#include <math.h>
#include <unordered_map>
using namespace std ; void print ( int * arr , int n ) { for ( int i = 0 ; i < n ; i ++ ) { cout << arr [ i ] << " ▁ " ; } cout << endl ; } int digit_at ( int x , int d ) { return ( int ) ( x / pow ( 10 , d - 1 ) ) % 10 ; } void MSD_sort ( int * arr , int lo , int hi , int d ) { if ( hi <= lo ) { return ; } int count [ 10 + 2 ] = { 0 } ; unordered_map < int , int > temp ; for ( int i = lo ; i <= hi ; i ++ ) { int c = digit_at ( arr [ i ] , d ) ; count ++ ; } for ( int r = 0 ; r < 10 + 1 ; r ++ ) count [ r + 1 ] += count [ r ] ; for ( int i = lo ; i <= hi ; i ++ ) { int c = digit_at ( arr [ i ] , d ) ; temp [ count ++ ] = arr [ i ] ; } for ( int i = lo ; i <= hi ; i ++ ) arr [ i ] = temp [ i - lo ] ; for ( int r = 0 ; r < 10 ; r ++ ) MSD_sort ( arr , lo + count [ r ] , lo + count [ r + 1 ] - 1 , d - 1 ) ; } int getMax ( int arr [ ] , int n ) { int mx = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) if ( arr [ i ] > mx ) mx = arr [ i ] ; return mx ; } void radixsort ( int * arr , int n ) { int m = getMax ( arr , n ) ; int d = floor ( log10 ( abs ( m ) ) ) + 1 ; MSD_sort ( arr , 0 , n - 1 , d ) ; } int main ( ) { int arr [ ] = { 9330 , 9950 , 718 , 8977 , 6790 , 95 , 9807 , 741 , 8586 , 5710 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; printf ( " Unsorted ▁ array ▁ : ▁ " ) ; print ( arr , n ) ; radixsort ( arr , n ) ; printf ( " Sorted ▁ array ▁ : ▁ " ) ; print ( arr , n ) ; return 0 ; }

Index/key variables: i, r
Accumulator variables: count, i, r
Iterator variables: i, r
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findAmountPlayers ( int arr [ ] , int N ) { sort ( arr , arr + N , greater < int > ( ) ) ; int amountA = 0 ; int amountB = 0 ; if ( N == 1 ) { amountA += arr [ 0 ] ; cout << " ( A ▁ : ▁ " << amountA << " ) , ▁ " << " ( B ▁ : ▁ " << amountB << " ) " ; return ; } amountA = arr [ 0 ] ; amountB = arr [ 1 ] ; for ( int i = 2 ; i < N ; i ++ ) { if ( i % 2 == 0 ) { amountB += arr [ i ] ; } else { amountA += arr [ i ] ; } } cout << " ( A ▁ : ▁ " << amountA << " ) STRNEWLINE " << " ( B ▁ : ▁ " << amountB << " ) " ; } int main ( ) { int arr [ ] = { 1 , 1 , 1 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findAmountPlayers ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: amountA, amountB, i, stdc
Iterator variables: i