dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findDiff ( int arr [ ] , int n ) { unordered_map < int , int > hm ; for ( int i = 0 ; i < n ; i ++ ) hm [ arr [ i ] ] ++ ; int max_count = 0 , min_count = n ; for ( auto x : hm ) { max_count = max ( max_count , x . second ) ; min_count = min ( min_count , x . second ) ; } 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: i, stdc
Iterator variables: i, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; bool areIdentical ( Node * root1 , Node * root2 ) { if ( root1 == NULL && root2 == NULL ) return true ; if ( root1 == NULL ) return false ; if ( root2 == NULL ) return false ; queue < Node * > q1 , q2 ; q1 . push ( root1 ) ; q2 . push ( root2 ) ; while ( ! q1 . empty ( ) && ! q2 . empty ( ) ) { Node * n1 = q1 . front ( ) ; Node * n2 = q2 . front ( ) ; if ( n1 -> data != n2 -> data ) return false ; q1 . pop ( ) , q2 . pop ( ) ; if ( n1 -> left && n2 -> left ) { q1 . push ( n1 -> left ) ; q2 . push ( n2 -> left ) ; } else if ( n1 -> left n2 -> left ) return false ; if ( n1 -> right && n2 -> right ) { q1 . push ( n1 -> right ) ; q2 . push ( n2 -> right ) ; } else if ( n1 -> right n2 -> right ) return false ; } return true ; } Node * newNode ( int data ) { Node * temp = new Node ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } int main ( ) { Node * root1 = newNode ( 1 ) ; root1 -> left = newNode ( 2 ) ; root1 -> right = newNode ( 3 ) ; root1 -> left -> left = newNode ( 4 ) ; root1 -> left -> right = newNode ( 5 ) ; Node * root2 = newNode ( 1 ) ; root2 -> left = newNode ( 2 ) ; root2 -> right = newNode ( 3 ) ; root2 -> left -> left = newNode ( 4 ) ; root2 -> left -> right = newNode ( 5 ) ; areIdentical ( root1 , root2 ) ? cout << " Yes " : cout << " No " ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX_NODES  100005
int parent [ MAX_NODES ] ; int size_set [ MAX_NODES ] ; void make_set ( int v ) { parent [ v ] = v ; size_set [ v ] = 1 ; } int find_set ( int v ) { if ( v == parent [ v ] ) return v ; return parent [ v ] = find_set ( parent [ v ] ) ; } void union_set ( int a , int b ) { a = find_set ( a ) ; b = find_set ( b ) ; if ( a != b ) { if ( size_set [ a ] < size_set [ b ] ) swap ( a , b ) ; parent [ b ] = a ; size_set [ a ] += size_set [ b ] ; } } string check ( int a , int b ) { a = find_set ( a ) ; b = find_set ( b ) ; return ( a == b ) ? " Yes " : " No " ; } int main ( ) { int n = 5 , m = 3 ; make_set ( 1 ) ; make_set ( 2 ) ; make_set ( 3 ) ; make_set ( 4 ) ; make_set ( 5 ) ; union_set ( 1 , 3 ) ; union_set ( 3 , 4 ) ; union_set ( 3 , 5 ) ; int q = 3 ; cout << check ( 1 , 5 ) << endl ; cout << check ( 3 , 2 ) << endl ; cout << check ( 5 , 2 ) << endl ; return 0 ; }

Index/key variables: MAX_NODES, a, b, v
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; long count ( int N , int A , int B ) { if ( N == 1 ) { return 9 / B + 1 ; } int max_sum = 9 * N ; int odd_count = N / 2 + N % 2 ; int even_count = N - odd_count ; long dp [ even_count ] [ max_sum + 1 ] = { 0 } ; for ( int i = 0 ; i <= 9 ; i ++ ) dp [ 0 ] [ i % A ] ++ ; for ( int i = 1 ; i < even_count ; i ++ ) { for ( int j = 0 ; j <= 9 ; j ++ ) { for ( int k = 0 ; k <= max_sum ; k ++ ) { if ( dp [ i - 1 ] [ k ] > 0 ) dp [ i ] [ ( j + k ) % A ] += dp [ i - 1 ] [ k ] ; } } } long dp1 [ odd_count ] [ max_sum + 1 ] = { 0 } ; for ( int i = 1 ; i <= 9 ; i ++ ) dp1 [ 0 ] [ i % B ] ++ ; for ( int i = 1 ; i < odd_count ; i ++ ) { for ( int j = 0 ; j <= 9 ; j ++ ) { for ( int k = 0 ; k <= max_sum ; k ++ ) { if ( dp1 [ i - 1 ] [ k ] > 0 ) dp1 [ i ] [ ( j + k ) % B ] += dp1 [ i - 1 ] [ k ] ; } } } return dp [ even_count - 1 ] [ 0 ] * dp1 [ odd_count - 1 ] [ 0 ] ; } int main ( ) { int N = 2 , A = 2 , B = 5 ; cout << count ( N , A , B ) ; }

Index/key variables: even_count, i, k, odd_count
Accumulator variables: i, j, k, stdc
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxDiff ( int arr [ ] , int n ) { int SubsetSum_1 = 0 , SubsetSum_2 = 0 ; for ( int i = 0 ; i <= n - 1 ; i ++ ) { bool isSingleOccurance = true ; for ( int j = i + 1 ; j <= n - 1 ; j ++ ) { if ( arr [ i ] == arr [ j ] ) { isSingleOccurance = false ; arr [ i ] = arr [ j ] = 0 ; break ; } } if ( isSingleOccurance ) { if ( arr [ i ] > 0 ) SubsetSum_1 += arr [ i ] ; else SubsetSum_2 += arr [ i ] ; } } return abs ( SubsetSum_1 - SubsetSum_2 ) ; } int main ( ) { int arr [ ] = { 4 , 2 , -3 , 3 , -2 , -2 , 8 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Maximum ▁ Difference ▁ = ▁ " << maxDiff ( arr , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: SubsetSum_1, SubsetSum_2, i, j, stdc
Iterator variables: i, j
Boolean variables: isSingleOccurance
C++ program:
#include <bits/stdc++.h>
#define int  long long int
using namespace std ; const int NN = 3e5 ; vector < int > G [ NN + 1 ] ; int dfs ( int node , int A , int * subtree_size , int * visited , int * check_subtree ) { visited [ node ] = true ; subtree_size [ node ] = 1 ; if ( node == A ) { check_subtree [ node ] = true ; } else check_subtree [ node ] = false ; for ( int v : G [ node ] ) { if ( ! visited [ v ] ) { subtree_size [ node ] += dfs ( v , A , subtree_size , visited , check_subtree ) ; check_subtree [ node ] = check_subtree [ node ] | check_subtree [ v ] ; } } return subtree_size [ node ] ; } void addedge ( int node1 , int node2 ) { G [ node1 ] . push_back ( node2 ) ; G [ node2 ] . push_back ( node1 ) ; } int numberOfPairs ( int N , int B , int A ) { int subtree_size [ N + 1 ] ; int visited [ N + 1 ] ; memset ( visited , 0 , sizeof ( visited ) ) ; int check_subtree [ N + 1 ] ; dfs ( B , A , subtree_size , visited , check_subtree ) ; int difference ; for ( int v : G [ B ] ) { if ( check_subtree [ v ] ) { difference = N - subtree_size [ v ] ; break ; } } return ( N * ( N - 1 ) ) - difference * ( subtree_size [ A ] ) ; } int32_t main ( ) { int N = 9 ; int X = 5 , Y = 3 ; addedge ( 0 , 2 ) ; addedge ( 1 , 2 ) ; addedge ( 2 , 3 ) ; addedge ( 3 , 4 ) ; addedge ( 4 , 6 ) ; addedge ( 4 , 5 ) ; addedge ( 5 , 7 ) ; addedge ( 5 , 8 ) ; cout << numberOfPairs ( N , Y , X ) ; return 0 ; }

Index/key variables: A, B, node, node1, node2, v
Accumulator variables: stdc
Iterator variables: v
C++ program:
#include <bits/stdc++.h>
using namespace std ; int equalXORandOR ( int n ) { int m = 0 ; int MSB = ( int ) log2 ( n ) ; for ( int i = 0 ; i <= MSB ; i ++ ) { if ( ! ( n & ( 1 << i ) ) ) { m += ( 1 << i ) ; } } return m ; } int main ( ) { int n = 14 ; cout << equalXORandOR ( n ) ; return 0 ; }

Accumulator variables: i, m, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxDiff ( int arr [ ] , int n ) { int result = 0 ; sort ( arr , arr + n ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( arr [ i ] != arr [ i + 1 ] ) result += abs ( arr [ i ] ) ; else i ++ ; } if ( arr [ n - 2 ] != arr [ n - 1 ] ) result += abs ( arr [ n - 1 ] ) ; return result ; } int main ( ) { int arr [ ] = { 4 , 2 , -3 , 3 , -2 , -2 , 8 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Maximum ▁ Difference ▁ = ▁ " << maxDiff ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, result, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; long long findNewString ( string s ) { long long ans = 0 ; int freq [ 26 ] ; int n = s . length ( ) ; memset ( freq , 0 , sizeof freq ) ; for ( int i = 0 ; i < ( int ) s . length ( ) ; ++ i ) { ans += freq [ s [ i ] - ' a ' ] ; freq [ s [ i ] - ' a ' ] ++ ; } return ans ; } int main ( ) { string s = " aaabaaa " ; cout << findNewString ( s ) << ' ' ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxDiff ( int arr [ ] , int n ) { unordered_map < int , int > hashPositive ; unordered_map < int , int > hashNegative ; int SubsetSum_1 = 0 , SubsetSum_2 = 0 ; for ( int i = 0 ; i <= n - 1 ; i ++ ) if ( arr [ i ] > 0 ) hashPositive [ arr [ i ] ] ++ ; for ( int i = 0 ; i <= n - 1 ; i ++ ) if ( arr [ i ] > 0 && hashPositive [ arr [ i ] ] == 1 ) SubsetSum_1 += arr [ i ] ; for ( int i = 0 ; i <= n - 1 ; i ++ ) if ( arr [ i ] < 0 ) hashNegative [ abs ( arr [ i ] ) ] ++ ; for ( int i = 0 ; i <= n - 1 ; i ++ ) if ( arr [ i ] < 0 && hashNegative [ abs ( arr [ i ] ) ] == 1 ) SubsetSum_2 += arr [ i ] ; return abs ( SubsetSum_1 - SubsetSum_2 ) ; } int main ( ) { int arr [ ] = { 4 , 2 , -3 , 3 , -2 , -2 , 8 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Maximum ▁ Difference ▁ = ▁ " << maxDiff ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: SubsetSum_1, SubsetSum_2, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string proofreadSpell ( string & str ) { vector < char > result ; for ( char c : str ) { result . push_back ( c ) ; int n = result . size ( ) ; if ( n >= 3 ) { if ( result [ n - 1 ] == result [ n - 2 ] && result [ n - 1 ] == result [ n - 3 ] ) { result . pop_back ( ) ; } } n = result . size ( ) ; if ( n >= 4 ) { if ( result [ n - 1 ] == result [ n - 2 ] && result [ n - 3 ] == result [ n - 4 ] ) { result . pop_back ( ) ; } } } string resultStr = " " ; for ( char c : result ) { resultStr += c ; } return resultStr ; } int main ( ) { string str = " hello " ; cout << proofreadSpell ( str ) ; }

Accumulator variables: resultStr, stdc
Iterator variables: c
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minRange ( int arr [ ] , int n , int k ) { int l = 0 , r = n ; for ( int i = 0 ; i < n ; i ++ ) { unordered_set < int > s ; int j ; for ( j = i ; j < n ; j ++ ) { s . insert ( arr [ j ] ) ; if ( s . size ( ) == k ) { if ( ( j - i ) < ( r - l ) ) { r = j ; l = i ; } break ; } } if ( j == n ) break ; } if ( l == 0 && r == n ) cout << " Invalid ▁ k " ; else cout << l << " ▁ " << r ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 3 ; minRange ( 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 ; void minRange ( int arr [ ] , int n , int k ) { int l = 0 , r = n ; int j = -1 ; map < int , int > hm ; for ( int i = 0 ; i < n ; i ++ ) { while ( j < n ) { j ++ ; if ( hm . size ( ) < k ) hm [ arr [ j ] ] ++ ; if ( hm . size ( ) == k && ( ( r - l ) >= ( j - i ) ) ) { l = i ; r = j ; break ; } } if ( hm . size ( ) < k ) break ; while ( hm . size ( ) == k ) { if ( hm [ arr [ i ] ] == 1 ) hm . erase ( arr [ i ] ) ; else hm [ arr [ i ] ] -- ; i ++ ; if ( hm . size ( ) == k && ( r - l ) >= ( j - i ) ) { l = i ; r = j ; } } if ( hm [ arr [ i ] ] == 1 ) hm . erase ( arr [ i ] ) ; else hm [ arr [ i ] ] -- ; } if ( l == 0 && r == n ) cout << " Invalid ▁ k " << endl ; else cout << l << " ▁ " << r << endl ; } int main ( ) { int arr [ ] = { 1 , 1 , 2 , 2 , 3 , 3 , 4 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 3 ; minRange ( arr , n , k ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int sum ( int a [ ] , int n ) { unordered_map < int , int > cnt ; int ans = 0 , pre_sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ans += ( i * a [ i ] ) - pre_sum ; pre_sum += a [ i ] ; if ( cnt [ a [ i ] - 1 ] ) ans -= cnt [ a [ i ] - 1 ] ; if ( cnt [ a [ i ] + 1 ] ) ans += cnt [ a [ i ] + 1 ] ; cnt [ a [ i ] ] ++ ; } return ans ; } int main ( ) { int a [ ] = { 1 , 2 , 3 , 1 , 3 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << sum ( a , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, i, pre_sum, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minDistance ( int a [ ] , int n ) { int maximum = -1 , minimum = INT_MAX ; int min_index = -1 , max_index = -1 ; int min_dist = n + 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] > maximum ) maximum = a [ i ] ; if ( a [ i ] < minimum ) minimum = a [ i ] ; } for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == minimum ) min_index = i ; if ( a [ i ] == maximum ) max_index = i ; if ( min_index != -1 && max_index != -1 ) min_dist = min ( min_dist , abs ( min_index - max_index ) ) ; } return min_dist ; } int main ( ) { int a [ ] = { 3 , 2 , 1 , 2 , 1 , 4 , 5 , 8 , 6 , 7 , 8 , 2 } ; int n = sizeof a / sizeof a [ 0 ] ; cout << minDistance ( a , n ) ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printDiagonal ( int K , int N , vector < vector < int > > & M ) { int startrow , startcol ; if ( K - 1 < N ) { startrow = K - 1 ; startcol = 0 ; } else { startrow = N - 1 ; startcol = K - N ; } for ( ; startrow >= 0 && startcol < N ; startrow -- , startcol ++ ) { cout << M [ startrow ] [ startcol ] << " ▁ " ; } } int main ( ) { int N = 3 , K = 4 ; vector < vector < int > > M = { { 4 , 7 , 8 } , { 9 , 2 , 3 } , { 0 , 4 , 1 } } ; printDiagonal ( K , N , M ) ; return 0 ; }

Index/key variables: startcol, startrow
Accumulator variables: startcol, startrow, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int longestSubstring ( string str , char X , char Y ) { int N = str . length ( ) ; int start = 0 ; int end = N - 1 ; int xPos = 0 ; int yPos = 0 ; while ( true ) { if ( str [ start ] == X ) { xPos = start ; break ; } start ++ ; } while ( true ) { if ( str [ end ] == Y ) { yPos = end ; break ; } end -- ; } int length = ( yPos - xPos ) + 1 ; cout << length ; } int main ( ) { string str = " HASFJGHOGAKZZFEGA " ; char X = ' A ' , Y = ' Z ' ; longestSubstring ( str , X , Y ) ; return 0 ; }

Index/key variables: end, start
Accumulator variables: end, start, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findParent ( int height , int node ) { int start = 1 ; int end = pow ( 2 , height ) - 1 ; if ( end == node ) return -1 ; while ( node >= 1 ) { end = end - 1 ; int mid = start + ( end - start ) / 2 ; if ( mid == node end == node ) { return ( end + 1 ) ; } else if ( node < mid ) { end = mid ; } else { start = mid ; } } } int main ( ) { int height = 4 ; int node = 6 ; int k = findParent ( height , node ) ; cout << k ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countSubarrWithEqualZeroAndOne ( int arr [ ] , int n ) { unordered_map < int , int > um ; int curr_sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { curr_sum += ( arr [ i ] == 0 ) ? -1 : arr [ i ] ; um [ curr_sum ] ++ ; } int count = 0 ; for ( auto itr = um . begin ( ) ; itr != um . end ( ) ; itr ++ ) { if ( itr -> second > 1 ) count += ( ( itr -> second * ( itr -> second - 1 ) ) / 2 ) ; } if ( um . find ( 0 ) != um . end ( ) ) count += um [ 0 ] ; return count ; } int main ( ) { int arr [ ] = { 1 , 0 , 0 , 1 , 0 , 1 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Count ▁ = ▁ " << countSubarrWithEqualZeroAndOne ( arr , n ) ; return 0 ; }

Index/key variables: curr_sum, i
Accumulator variables: count, curr_sum, i, itr, stdc
Iterator variables: i, itr
C++ program:
#include <bits/stdc++.h>
using namespace std ; int lenOfLongSubarr ( int arr [ ] , int n ) { unordered_map < int , int > um ; int sum = 0 , maxLen = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] == 0 ? -1 : 1 ; if ( sum == 1 ) maxLen = i + 1 ; else if ( um . find ( sum ) == um . end ( ) ) um [ sum ] = i ; if ( um . find ( sum - 1 ) != um . end ( ) ) { if ( maxLen < ( i - um [ sum - 1 ] ) ) maxLen = i - um [ sum - 1 ] ; } } return maxLen ; } int main ( ) { int arr [ ] = { 0 , 1 , 1 , 0 , 0 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Length ▁ = ▁ " << lenOfLongSubarr ( arr , n ) ; return 0 ; }

Index/key variables: i, sum
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxSubarraySum ( int arr [ ] , int N , int K ) { set < int > cum_set ; cum_set . insert ( 0 ) ; int max_sum = INT_MIN , cSum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { cSum += arr [ i ] ; set < int > :: iterator sit = cum_set . lower_bound ( cSum - K ) ; if ( sit != cum_set . end ( ) ) max_sum = max ( max_sum , cSum - * sit ) ; cum_set . insert ( cSum ) ; } return max_sum ; } int main ( ) { int arr [ ] = { 5 , -2 , 6 , 3 , -5 } ; int K = 15 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maxSubarraySum ( arr , N , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cSum, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printAllAPTriplets ( int arr [ ] , int n ) { unordered_set < int > s ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { int diff = arr [ j ] - arr [ i ] ; if ( s . find ( arr [ i ] - diff ) != s . end ( ) ) cout << arr [ i ] - diff << " ▁ " << arr [ i ] << " ▁ " << arr [ j ] << endl ; } s . insert ( arr [ i ] ) ; } } int main ( ) { int arr [ ] = { 2 , 6 , 9 , 12 , 17 , 22 , 31 , 32 , 35 , 42 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; printAllAPTriplets ( arr , n ) ; 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 ; void printAllAPTriplets ( int arr [ ] , int n ) { for ( int i = 1 ; i < n - 1 ; i ++ ) { for ( int j = i - 1 , k = i + 1 ; j >= 0 && k < n ; ) { if ( arr [ j ] + arr [ k ] == 2 * arr [ i ] ) { cout << arr [ j ] << " ▁ " << arr [ i ] << " ▁ " << arr [ k ] << endl ; k ++ ; j -- ; } else if ( arr [ j ] + arr [ k ] < 2 * arr [ i ] ) k ++ ; else j -- ; } } } int main ( ) { int arr [ ] = { 2 , 6 , 9 , 12 , 17 , 22 , 31 , 32 , 35 , 42 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; printAllAPTriplets ( arr , n ) ; return 0 ; }

Index/key variables: i, j, k
Accumulator variables: i, j, k, stdc
Iterator variables: i, j
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 = new Node ; node -> data = data ; node -> left = node -> right = NULL ; return ( node ) ; } bool existPathUtil ( struct Node * root , int arr [ ] , int n , int index ) { if ( root == NULL or index == n ) return false ; if ( root -> left == NULL && root -> right == NULL ) { if ( ( root -> data == arr [ index ] ) && ( index == n - 1 ) ) return true ; return false ; } return ( ( index < n ) && ( root -> data == arr [ index ] ) && ( existPathUtil ( root -> left , arr , n , index + 1 ) || existPathUtil ( root -> right , arr , n , index + 1 ) ) ) ; } bool existPath ( struct Node * root , int arr [ ] , int n , int index ) { if ( ! root ) return ( n == 0 ) ; return existPathUtil ( root , arr , n , 0 ) ; } int main ( ) { int arr [ ] = { 5 , 8 , 6 , 7 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; struct Node * root = newnode ( 5 ) ; root -> left = newnode ( 3 ) ; root -> right = newnode ( 8 ) ; root -> left -> left = newnode ( 2 ) ; root -> left -> right = newnode ( 4 ) ; root -> left -> left -> left = newnode ( 1 ) ; root -> right -> left = newnode ( 6 ) ; root -> right -> left -> right = newnode ( 7 ) ; existPath ( root , arr , n , 0 ) ? cout << " Path ▁ Exists " : cout << " Path ▁ does ▁ not ▁ Exist " ; return 0 ; }

Index/key variables: index
Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findTriplets ( int a [ ] , int n , int sum ) { int i ; sort ( a , a + n ) ; bool flag = false ; for ( i = 0 ; i < n - 2 ; i ++ ) { if ( i == 0 a [ i ] > a [ i - 1 ] ) { int start = i + 1 ; int end = n - 1 ; int target = sum - a [ i ] ; while ( start < end ) { if ( start > i + 1 && a [ start ] == a [ start - 1 ] ) { start ++ ; continue ; } if ( end < n - 1 && a [ end ] == a [ end + 1 ] ) { end -- ; continue ; } if ( target == a [ start ] + a [ end ] ) { cout << " [ " << a [ i ] << " , " << a [ start ] << " , " << a [ end ] << " ] ▁ " ; flag = true ; start ++ ; end -- ; } else if ( target > ( a [ start ] + a [ end ] ) ) { start ++ ; } else { end -- ; } } } } if ( flag == false ) { cout << " No ▁ Such ▁ Triplets ▁ Exist " << " STRNEWLINE " ; } } int main ( ) { int a [ ] = { 12 , 3 , 6 , 1 , 6 , 9 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; int sum = 24 ; findTriplets ( a , n , sum ) ; return 0 ; }

Index/key variables: end, i, start
Accumulator variables: end, i, start, stdc
Iterator variables: i
Boolean variables: flag
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int m = 6 , n = 4 ; int linearCheck ( int ar [ ] [ n ] , int arr [ ] ) { for ( int i = 0 ; i < m ; i ++ ) { bool matched = true ; for ( int j = 0 ; j < n ; j ++ ) { if ( ar [ i ] [ j ] != arr [ j ] ) { matched = false ; break ; } } if ( matched ) return i + 1 ; } return -1 ; } int main ( ) { int mat [ m ] [ n ] = { { 0 , 0 , 1 , 0 } , { 10 , 9 , 22 , 23 } , { 40 , 40 , 40 , 40 } , { 43 , 44 , 55 , 68 } , { 81 , 73 , 100 , 132 } , { 100 , 75 , 125 , 133 } } ; int row [ n ] = { 10 , 9 , 22 , 23 } ; cout << linearCheck ( mat , row ) ; return 0 ; }

Index/key variables: i, j, m, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
Boolean variables: matched
C++ program:
#include <iostream>
using namespace std ; int countTriplets ( int arr [ ] , int n , int m ) { int count = 0 ; for ( int i = 0 ; i < n - 2 ; i ++ ) for ( int j = i + 1 ; j < n - 1 ; j ++ ) for ( int k = j + 1 ; k < n ; k ++ ) if ( arr [ i ] * arr [ j ] * arr [ k ] == m ) count ++ ; return count ; } int main ( ) { int arr [ ] = { 1 , 4 , 6 , 2 , 3 , 8 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int m = 24 ; cout << countTriplets ( arr , n , m ) ; return 0 ; }

Index/key variables: i, j, k
Accumulator variables: count, i, j, k
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countTriplets ( int arr [ ] , int n , int m ) { unordered_map < int , int > occ ; for ( int i = 0 ; i < n ; i ++ ) occ [ arr [ i ] ] = i ; int count = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( ( arr [ i ] * arr [ j ] <= m ) && ( arr [ i ] * arr [ j ] != 0 ) && ( m % ( arr [ i ] * arr [ j ] ) == 0 ) ) { int check = m / ( arr [ i ] * arr [ j ] ) ; auto it = occ . find ( check ) ; if ( check != arr [ i ] && check != arr [ j ] && it != occ . end ( ) && it -> second > i && it -> second > j ) count ++ ; } } } return count ; } int main ( ) { int arr [ ] = { 1 , 4 , 6 , 2 , 3 , 8 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int m = 24 ; cout << countTriplets ( arr , n , m ) ; return 0 ; }

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

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