dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int tin [ 100 ] , tout [ 100 ] , depth [ 100 ] ; int t = 0 ; void Add_edge ( int parent , int child , vector < vector < int > > & adj ) { adj [ parent ] . push_back ( child ) ; adj [ child ] . push_back ( parent ) ; } void dfs ( int node , int parent , vector < vector < int > > & adj , vector < vector < int > > & levels , int d ) { tin [ node ] = t ++ ; levels [ d ] . push_back ( tin [ node ] ) ; depth [ node ] = d ; for ( auto x : adj [ node ] ) { if ( x != parent ) dfs ( x , node , adj , levels , d + 1 ) ; } tout [ node ] = t ++ ; } void numberOfNodes ( int node , int dist , vector < vector < int > > & levels ) { dist += depth [ node ] ; int start = lower_bound ( levels [ dist ] . begin ( ) , levels [ dist ] . end ( ) , tin [ node ] ) - levels [ dist ] . begin ( ) ; int ed = lower_bound ( levels [ dist ] . begin ( ) , levels [ dist ] . end ( ) , tout [ node ] ) - levels [ dist ] . begin ( ) ; cout << ed - start << endl ; } void numberOfNodesUtil ( pair < int , int > Q [ ] , int M , int N ) { vector < vector < int > > adj ( N + 5 ) , levels ( N + 5 ) ; Add_edge ( 1 , 2 , adj ) ; Add_edge ( 1 , 3 , adj ) ; Add_edge ( 2 , 4 , adj ) ; Add_edge ( 2 , 5 , adj ) ; Add_edge ( 2 , 6 , adj ) ; t = 1 ; dfs ( 1 , 1 , adj , levels , 0 ) ; for ( int i = 0 ; i < M ; ++ i ) { numberOfNodes ( Q [ i ] . first , Q [ i ] . second , levels ) ; } } int main ( ) { int N = 6 ; pair < int , int > Q [ ] = { { 2 , 1 } , { 1 , 1 } } ; int M = sizeof ( Q ) / sizeof ( Q [ 0 ] ) ; numberOfNodesUtil ( Q , M , N ) ; }

Index/key variables: child, d, dist, i, node, parent
Accumulator variables: dist, stdc, t
Iterator variables: i, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; void numberofBoxes ( int W , int B , int O ) { int low = 0 , high = min ( W , B ) ; int ans = 0 ; while ( low <= high ) { int mid = low + ( high - low ) / 2 ; if ( ( ( W >= mid ) and ( B >= mid ) ) and ( ( W - mid ) + ( B - mid ) + O ) >= mid ) { ans = mid ; low = mid + 1 ; } else high = mid - 1 ; } cout << ans ; } int main ( ) { int W = 3 , B = 3 , O = 1 ; numberofBoxes ( W , B , O ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minSwaps ( int N , int M , vector < vector < int > > & A , vector < vector < int > > & B ) { int count01 = 0 ; int count10 = 0 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( A [ i ] [ j ] != B [ i ] [ j ] ) { if ( A [ i ] [ j ] == 1 ) count10 ++ ; else count01 ++ ; } } } if ( count01 == count10 ) return count01 ; else return -1 ; } int main ( ) { vector < vector < int > > A = { { 1 , 1 , 0 } , { 0 , 0 , 1 } , { 0 , 1 , 0 } } ; vector < vector < int > > B = { { 0 , 0 , 1 } , { 0 , 1 , 0 } , { 1 , 1 , 0 } } ; int N = A . size ( ) ; int M = B [ 0 ] . size ( ) ; cout << minSwaps ( N , M , A , B ) ; }

Index/key variables: i, j
Accumulator variables: count01, count10, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int Count ( int N , int K ) { if ( K == 0 ) return 0 ; int sum = 0 ; int res = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { sum += i ; if ( sum <= K ) res ++ ; else break ; } return res ; } int main ( ) { int N = 6 , K = 14 ; cout << Count ( N , K ) ; return 0 ; }

Accumulator variables: i, res, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string removeLastOccurrence ( string S , string W , int N , int M ) { if ( M > N ) return S ; for ( int i = N - M ; i >= 0 ; i -- ) { int flag = 0 ; for ( int j = 0 ; j < M ; j ++ ) { if ( S [ j + i ] != W [ j ] ) { flag = 1 ; break ; } } if ( flag == 0 ) { for ( int j = i ; j < N - M ; j ++ ) S [ j ] = S [ j + M ] ; S . resize ( N - M ) ; break ; } } return S ; } int main ( ) { string S = " This ▁ is ▁ GeeksForGeeks " ; string W = " Geeks " ; int N = S . length ( ) ; int M = W . length ( ) ; cout << removeLastOccurrence ( S , W , N , M ) << endl ; 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 maximumIndices ( int arr [ ] , int N ) { int temp [ N ] = { 0 } ; int maxIndices = ( N - 1 ) / 2 ; sort ( arr , arr + N ) ; for ( int i = 0 ; i < maxIndices ; i ++ ) { temp [ 2 * i + 1 ] = arr [ i ] ; } int j = 0 ; for ( int i = maxIndices ; i < N ; ) { if ( temp [ j ] == 0 ) { temp [ j ] = arr [ i ] ; i ++ ; } j ++ ; } for ( int i = 0 ; i < N ; i ++ ) { cout << temp [ i ] << " ▁ " ; } } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; maximumIndices ( arr , N ) ; return 0 ; }

Index/key variables: N, i, j
Accumulator variables: i, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool areSimilar ( string S1 , string S2 ) { int N = S1 . size ( ) ; int M = S2 . size ( ) ; if ( N == M ) { if ( S1 == S2 ) return true ; return false ; } deque < string > X , Y ; S1 . push_back ( ' ▁ ' ) ; S2 . push_back ( ' ▁ ' ) ; string temp = " " ; for ( int i = 0 ; i < N + 1 ; i ++ ) { if ( S1 [ i ] == ' ▁ ' ) { X . push_back ( temp ) ; temp = " " ; } else { temp += S1 [ i ] ; } } for ( int i = 0 ; i < M + 1 ; i ++ ) { if ( S2 [ i ] == ' ▁ ' ) { Y . push_back ( temp ) ; temp = " " ; } else { temp += S2 [ i ] ; } } while ( X . size ( ) > 0 && Y . size ( ) > 0 && X . front ( ) == Y . front ( ) ) { X . pop_front ( ) ; Y . pop_front ( ) ; } while ( X . size ( ) > 0 && Y . size ( ) > 0 && X . back ( ) == Y . back ( ) ) { X . pop_back ( ) ; Y . pop_back ( ) ; } if ( X . size ( ) == 0 || Y . size ( ) == 0 ) return true ; return false ; } int main ( ) { string S1 = " Start ▁ practicing ▁ on ▁ GeeksforGeeks " ; string S2 = " Start ▁ GeeksforGeeks " ; if ( areSimilar ( S1 , S2 ) ) cout << " True " << endl ; else cout << " False " << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, temp
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int repeatingElement ( int arr [ ] , int N ) { int M = 0 , sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += arr [ i ] ; M = max ( M , arr [ i ] ) ; } int sum1 = M * ( M + 1 ) / 2 ; int ans = ( sum - sum1 ) / ( N - M ) ; return ans ; } int main ( ) { int arr [ ] = { 2 , 6 , 4 , 3 , 1 , 5 , 2 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << repeatingElement ( arr , N ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int calculateMax ( int N , int M , int K ) { int ans = -1 ; int low = 0 , high = M ; while ( low <= high ) { int mid = ( low + high ) / 2 ; int val = 0 ; int L = K - 1 ; int R = N - K ; val += mid ; if ( mid >= L ) { val += ( L ) * ( 2 * mid - L - 1 ) / 2 ; } else { val += mid * ( mid - 1 ) / 2 + ( L - mid ) ; } if ( mid >= R ) { val += ( R ) * ( 2 * mid - R - 1 ) / 2 ; } else { val += mid * ( mid - 1 ) / 2 + ( R - mid ) ; } if ( val <= M ) { ans = max ( ans , mid ) ; low = mid + 1 ; } else high = mid - 1 ; } return ans ; } int main ( ) { int N = 7 , M = 100 , K = 6 ; cout << calculateMax ( N , M , K ) << endl ; return 0 ; }

Accumulator variables: stdc, val
C++ program:
#include <bits/stdc++.h>
using namespace std ; int ans = 0 ; vector < int > edges [ 100000 ] ; void Add_edge ( int u , int v ) { edges [ u ] . push_back ( v ) ; edges [ v ] . push_back ( u ) ; } void minTimeToColor ( int node , int parent , int arrival_time ) { int current_time = 0 ; for ( auto x : edges [ node ] ) { if ( x != parent ) { ++ current_time ; if ( current_time == arrival_time ) ++ current_time ; ans = max ( ans , current_time ) ; minTimeToColor ( x , node , current_time ) ; } } } int main ( ) { pair < int , int > A [ ] = { { 1 , 2 } , { 2 , 3 } , { 3 , 4 } } ; for ( auto i : A ) { Add_edge ( i . first , i . second ) ; } minTimeToColor ( 1 , -1 , 0 ) ; cout << ans << " STRNEWLINE " ; }

Index/key variables: node, u, v
Accumulator variables: stdc
Iterator variables: i, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; int largestNum ( vector < int > arr ) { int res = 0 ; sort ( arr . begin ( ) , arr . end ( ) ) ; int l = 0 , r = arr . size ( ) - 1 ; while ( l < r ) { int sum = arr [ l ] + arr [ r ] ; if ( sum == 0 ) { res = max ( res , max ( arr [ l ] , arr [ r ] ) ) ; return res ; } else if ( sum < 0 ) { l ++ ; } else { r -- ; } } return res ; } int main ( ) { vector < int > arr = { 3 , 2 , -2 , 5 , -3 } ; cout << ( largestNum ( arr ) ) ; }

Index/key variables: l, r
Accumulator variables: l, r, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findLarger ( int arr [ ] , int n ) { int mid = ( n + 1 ) / 2 ; int mx = * max_element ( arr , arr + n ) ; int count [ mx + 1 ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) { count [ arr [ i ] ] ++ ; } for ( int i = mx ; i >= 0 ; i -- ) { while ( count [ i ] > 0 ) { count [ i ] -- ; mid -- ; cout << i << ' ▁ ' ; if ( mid == 0 ) break ; } if ( mid == 0 ) break ; } } int main ( ) { int arr [ ] = { 10 , 4 , 2 , 8 , 9 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findLarger ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, mid, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; double probability ( vector < int > arr1 , vector < int > arr2 ) { int N = arr1 . size ( ) ; int M = arr2 . size ( ) ; double res = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int y = 0 ; for ( int j = 0 ; j < M ; j ++ ) { if ( arr2 [ j ] > arr1 [ i ] ) y ++ ; } res += y ; } res = ( double ) res / ( double ) ( N * M ) ; return res ; } int main ( ) { vector < int > arr1 = { 5 , 2 , 6 , 1 } ; vector < int > arr2 = { 1 , 6 , 10 , 1 } ; cout << probability ( arr1 , arr2 ) ; }

Index/key variables: i, j
Accumulator variables: i, j, res, stdc, y
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countGreater ( int * arr , int k ) ; float probability ( int * arr1 , int * arr2 ) { int N = 4 ; int M = 4 ; float res = 0 ; sort ( arr2 , arr2 + M ) ; for ( int i = 0 ; i < N ; i ++ ) { int y = countGreater ( arr2 , arr1 [ i ] ) ; res += y ; } res = res / ( N * M ) ; return res ; } int countGreater ( int * arr , int k ) { int n = 4 ; int l = 0 ; int r = n - 1 ; int leftGreater = n ; while ( l <= r ) { int m = l + ( r - l ) / 2 ; if ( arr [ m ] > k ) { leftGreater = m ; r = m - 1 ; } else l = m + 1 ; } return ( n - leftGreater ) ; } int main ( ) { int arr1 [ ] = { 5 , 2 , 6 , 1 } ; int arr2 [ ] = { 1 , 6 , 10 , 1 } ; cout << probability ( arr1 , arr2 ) ; return 0 ; }

Index/key variables: i, m
Accumulator variables: i, res, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minCost ( vector < vector < char > > arr , int A , int B ) { int n = arr . size ( ) ; int m = arr [ 0 ] . size ( ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( arr [ i ] [ j ] == ' * ' ) continue ; if ( j == m - 1 ) ans += A ; else { if ( arr [ i ] [ j + 1 ] == ' . ' ) { ans += min ( 2 * A , B ) ; j ++ ; } else ans += A ; } } } cout << ans ; } int main ( ) { vector < vector < char > > arr = { { ' . ' , ' . ' , ' * ' } , { ' . ' , ' * ' , ' * ' } } ; int A = 2 , B = 10 ; minCost ( arr , A , B ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: ans, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countInversions ( int arr [ ] , int n ) { vector < int > v ; for ( int i = 1 ; i <= n ; i ++ ) { v . push_back ( i ) ; } int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { auto itr = lower_bound ( v . begin ( ) , v . end ( ) , arr [ i ] ) ; ans += itr - v . begin ( ) ; v . erase ( itr ) ; } cout << ans ; return 0 ; } int main ( ) { int arr [ ] = { 2 , 3 , 1 , 5 , 4 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; countInversions ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findPairs ( int A , int B ) { for ( int i = 1 ; i <= B ; i ++ ) { int y = A ^ i ; if ( y > 0 and ( i y ) == B ) { cout << i << " ▁ " << y << endl ; } } } int main ( ) { int A = 8 , B = 10 ; findPairs ( A , B ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int binarysearch ( int array [ ] , int right , int element ) { int left = 1 ; while ( left <= right ) { int mid = ( left + right / 2 ) ; if ( array [ mid ] == element ) { return mid ; } if ( mid - 1 > 0 && array [ mid ] > element && array [ mid - 1 ] < element ) { return mid ; } else if ( array [ mid ] < element ) { left = mid + 1 ; } else { right = mid - 1 ; } } return 1 ; } void countDistinct ( vector < int > arr , int L , int R ) { int count = 0 ; int pref [ arr . size ( ) + 1 ] ; for ( int i = 1 ; i <= arr . size ( ) ; ++ i ) { count += arr [ i - 1 ] ; pref [ i ] = count ; } int left = binarysearch ( pref , arr . size ( ) + 1 , L ) ; int right = binarysearch ( pref , arr . size ( ) + 1 , R ) ; cout << right - left + 1 ; } int main ( ) { vector < int > arr { 3 , 6 , 7 , 1 , 8 } ; int L = 3 ; int R = 7 ; countDistinct ( arr , L , R ) ; }

Index/key variables: i, mid
Accumulator variables: count, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void countSubstrings ( string & s ) { int n = s . length ( ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int cnt = 0 ; for ( int j = i ; j < n ; j ++ ) { if ( s [ j ] == ' a ' ) cnt ++ ; else if ( s [ j ] == ' c ' ) cnt -- ; if ( cnt > 0 ) { ans ++ ; } } } cout << ans ; } int main ( ) { string S = " abccaab " ; countSubstrings ( S ) ; return 0 ; }

Index/key variables: j
Accumulator variables: ans, cnt, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool ischar ( char x ) { if ( ( x >= ' A ' && x <= ' Z ' ) || ( x >= ' a ' && x <= ' z ' ) ) { return 1 ; } return 0 ; } bool isnum ( char x ) { if ( x >= '0' && x <= '9' ) return 1 ; return 0 ; } void findIdandDomain ( string S , int N ) { string ID , Domain ; vector < string > words ; string curr = " " ; for ( int i = 0 ; i < N ; i ++ ) { if ( S [ i ] == ' ▁ ' ) { words . push_back ( curr ) ; curr = " " ; } else { if ( S [ i ] == ' . ' ) { if ( i + 1 == N || ( i + 1 < N && S [ i + 1 ] == ' ▁ ' ) ) continue ; } curr += S [ i ] ; } } if ( curr . length ( ) ) words . push_back ( curr ) ; for ( string ss : words ) { if ( ss . size ( ) == 10 ) { bool flag = 0 ; for ( int j = 0 ; j <= 9 ; j ++ ) { if ( j >= 5 && j < 9 ) { if ( isnum ( ss [ j ] ) == 0 ) flag = 1 ; } else { if ( ischar ( ss [ j ] ) == 0 ) flag = 1 ; } } if ( ! flag ) { ID = ss ; } } if ( ss . substr ( 0 , 3 ) == " www " && ss . substr ( ss . length ( ) - 3 , 3 ) == " com " ) { Domain = ss . substr ( 4 , ss . size ( ) - 4 ) ; } } cout << " ID ▁ = ▁ " << ID << endl ; cout << " Domain ▁ = ▁ " << Domain ; } int main ( ) { string S = " We ▁ thank ▁ ABCDE1234F ▁ for ▁ visiting ▁ " " us ▁ and ▁ buying ▁ " " products ▁ item ▁ AMZrr @ ! k . ▁ For ▁ more ▁ " " offers , ▁ visit ▁ " " us ▁ at ▁ www . amazon . com " ; int N = S . length ( ) ; findIdandDomain ( S , N ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: curr, i, j, stdc
Iterator variables: i, j, ss
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isValid ( int weight [ ] , int n , int D , int mx ) { int st = 1 ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += weight [ i ] ; if ( sum > mx ) { st ++ ; sum = weight [ i ] ; } if ( st > D ) return false ; } return true ; } void shipWithinDays ( int weight [ ] , int D , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += weight [ i ] ; int s = weight [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { s = max ( s , weight [ i ] ) ; } int e = sum ; int res = -1 ; while ( s <= e ) { int mid = s + ( e - s ) / 2 ; if ( isValid ( weight , n , D , mid ) ) { res = mid ; e = mid - 1 ; } else s = mid + 1 ; } cout << res ; } int main ( ) { int weight [ ] = { 9 , 8 , 10 } ; int D = 3 ; int N = sizeof ( weight ) / sizeof ( weight [ 0 ] ) ; shipWithinDays ( weight , D , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, st, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void createGraph ( unordered_map < int , vector < int > > & adj , int paths [ ] [ 2 ] , int A [ ] , int N , int E ) { for ( int i = 0 ; i < E ; i ++ ) { if ( ! A [ paths [ i ] [ 0 ] ] && ! A [ paths [ i ] [ 1 ] ] ) { adj [ paths [ i ] [ 0 ] ] . push_back ( paths [ i ] [ 1 ] ) ; } } } int minPath ( int paths [ ] [ 2 ] , int A [ ] , int N , int E ) { if ( A [ 0 ] == 1 A [ N - 1 ] == 1 ) return -1 ; unordered_map < int , vector < int > > adj ; createGraph ( adj , paths , A , N , E ) ; vector < int > visited ( N , 0 ) ; int dist [ N ] ; dist [ 0 ] = 0 ; queue < int > q ; q . push ( 0 ) ; visited [ 0 ] = 1 ; while ( ! q . empty ( ) ) { int temp = q . front ( ) ; q . pop ( ) ; for ( auto x : adj [ temp ] ) { if ( ! visited [ x ] ) { q . push ( x ) ; visited [ x ] = 1 ; dist [ x ] = dist [ temp ] + 1 ; } } } if ( ! visited [ N - 1 ] ) return -1 ; else return dist [ N - 1 ] ; } int main ( ) { int N = 5 , E = 5 ; int A [ ] = { 0 , 1 , 0 , 0 , 0 } ; int paths [ ] [ 2 ] = { { 0 , 1 } , { 0 , 2 } , { 1 , 4 } , { 2 , 3 } , { 3 , 4 } } ; cout << minPath ( paths , A , N , E ) ; return 0 ; }

Index/key variables: N, i, temp, x
Accumulator variables: i, stdc
Iterator variables: i, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findSum ( int * arr , int N , int pt ) { int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sum += abs ( arr [ i ] - pt ) ; } return sum ; } void findPoint ( int * arr , int N , int K ) { int left ; if ( N % 2 ) { left = arr [ N / 2 ] ; } else { left = arr [ N / 2 - 1 ] + 1 ; } int right = arr [ N - 1 ] ; while ( left <= right ) { int mid = ( left + right ) / 2 ; int temp = findSum ( arr , N , mid ) ; if ( temp == K ) { cout << mid << endl ; return ; } else if ( K < temp ) { right = mid - 1 ; } else { left = mid + 1 ; } } left = arr [ 0 ] ; right = arr [ N / 2 ] - 1 ; while ( left <= right ) { int mid = ( left + right ) / 2 ; int temp = findSum ( arr , N , mid ) ; if ( temp == K ) { cout << mid << endl ; return ; } else if ( K > temp ) { right = mid - 1 ; } else { left = mid + 1 ; } } cout << " - 1" << endl ; } int main ( ) { int arr [ ] = { 1 , 3 , 6 , 7 , 11 } ; int K = 18 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findPoint ( arr , N , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findArray ( int arr [ ] , int n ) { vector < int > v ; for ( int i = 0 ; i < n ; i ++ ) { int ans = -1 , old_c = 0 ; for ( int j = i + 1 ; j < n ; j ++ ) { if ( arr [ j ] > arr [ i ] ) { int curr_c = count ( & arr [ j ] , & arr [ n ] , arr [ j ] ) ; if ( curr_c == old_c ) { if ( arr [ j ] < ans ) ans = arr [ j ] ; } if ( curr_c > old_c ) { ans = arr [ j ] ; old_c = curr_c ; } } } v . push_back ( ans ) ; } for ( int i = 0 ; i < v . size ( ) ; i ++ ) cout << v [ i ] << " ▁ " ; } int main ( ) { int arr [ ] = { 4 , 5 , 2 , 25 , 10 , 5 , 10 , 3 , 10 , 5 } ; int size = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findArray ( arr , size ) ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; void prodEquilibrium ( int arr [ ] , int N ) { int product = 1 ; for ( int i = 0 ; i < N ; i ++ ) { product *= arr [ i ] ; } int left = 1 ; int right = product ; for ( int i = 0 ; i < N ; i ++ ) { left = left * arr [ i ] ; right = right / arr [ i ] ; if ( left == right ) { cout << i + 1 << endl ; return ; } } cout << -1 << endl ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 3 , 2 , 1 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; prodEquilibrium ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, product
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countTriplets ( int D , vector < int > & arr ) { unordered_map < int , int > freq ; int ans = 0 ; for ( int i = 0 ; i < arr . size ( ) ; i ++ ) { if ( freq . find ( arr [ i ] - D ) != freq . end ( ) && freq . find ( arr [ i ] - 2 * D ) != freq . end ( ) ) { ans += freq [ arr [ i ] - D ] * freq [ arr [ i ] - 2 * D ] ; } freq [ arr [ i ] ] ++ ; } return ans ; } int main ( ) { vector < int > arr { 1 , 2 , 4 , 5 , 7 , 8 , 10 } ; int D = 1 ; cout << countTriplets ( D , arr ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int find_index ( int arr [ ] , int N ) { int max_value = INT_MIN ; for ( int i = 0 ; i < N ; i ++ ) { max_value = max ( max_value , arr [ i ] ) ; } map < int , int > store ; for ( int i = 1 ; i <= max_value ; i ++ ) { store [ i ] ++ ; } if ( store . find ( 1 ) != store . end ( ) ) { store . erase ( 1 ) ; } for ( int i = 2 ; i <= sqrt ( max_value ) ; i ++ ) { int multiple = 2 ; while ( ( i * multiple ) <= max_value ) { if ( store . find ( i * multiple ) != store . end ( ) ) { store . erase ( i * multiple ) ; } multiple ++ ; } } int prime_sum_from_left = 0 ; int first_array [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { first_array [ i ] = prime_sum_from_left ; if ( store . find ( arr [ i ] ) != store . end ( ) ) { prime_sum_from_left += arr [ i ] ; } } int prime_sum_from_right = 0 ; int second_array [ N ] ; for ( int i = N - 1 ; i >= 0 ; i -- ) { second_array [ i ] = prime_sum_from_right ; if ( store . find ( arr [ i ] ) != store . end ( ) ) { prime_sum_from_right += arr [ i ] ; } } for ( int i = 0 ; i < N ; i ++ ) { if ( first_array [ i ] == second_array [ i ] ) { return i ; } } return -1 ; } int main ( ) { int arr [ ] = { 11 , 4 , 7 , 6 , 13 , 1 , 5 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << find_index ( arr , N ) ; return 0 ; }

Index/key variables: N, i
Accumulator variables: i, multiple, prime_sum_from_left, prime_sum_from_right, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void convert ( int arr [ ] , int n ) { int brr [ n ] ; for ( int i = 0 ; i < n ; i ++ ) brr [ i ] = arr [ i ] ; sort ( brr , brr + n ) ; for ( int i = 0 ; i < n ; i ++ ) { int l = 0 , r = n - 1 , mid ; while ( l <= r ) { mid = ( l + r ) / 2 ; if ( brr [ mid ] == arr [ i ] ) { cout << mid << ' ▁ ' ; break ; } else if ( brr [ mid ] < arr [ i ] ) { l = mid + 1 ; } else { r = mid - 1 ; } } } } int main ( ) { int arr [ ] = { 10 , 20 , 15 , 12 , 11 , 50 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; convert ( arr , N ) ; return 0 ; }

Index/key variables: i, mid, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findIndex ( int arr [ ] , int N ) { int maxValue = INT_MIN ; for ( int i = 0 ; i < N ; i ++ ) { maxValue = max ( maxValue , arr [ i ] ) ; } map < int , int > St ; for ( int i = 1 ; i <= maxValue ; i ++ ) { St [ i ] ++ ; } if ( St . find ( 1 ) != St . end ( ) ) { St . erase ( 1 ) ; } for ( int i = 2 ; i <= sqrt ( maxValue ) ; i ++ ) { int j = 2 ; while ( ( i * j ) <= maxValue ) { if ( St . find ( i * j ) != St . end ( ) ) { St . erase ( i * j ) ; } j ++ ; } } int LeftCount = 0 ; int Prefix [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { Prefix [ i ] = LeftCount ; if ( St . find ( arr [ i ] ) != St . end ( ) ) { LeftCount ++ ; } } int RightCount = 0 ; int Suffix [ N ] ; for ( int i = N - 1 ; i >= 0 ; i -- ) { Suffix [ i ] = RightCount ; if ( St . find ( arr [ i ] ) != St . end ( ) ) { RightCount ++ ; } } for ( int i = 0 ; i < N ; i ++ ) { if ( Prefix [ i ] == Suffix [ i ] ) { return i ; } } return -1 ; } int main ( ) { int arr [ ] = { 2 , 3 , 4 , 7 , 5 , 10 , 1 , 8 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findIndex ( arr , N ) ; return 0 ; }

Index/key variables: N, i
Accumulator variables: LeftCount, RightCount, i, j, stdc
Iterator variables: i