dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <iostream>
#include <bits/stdc++.h>
using namespace std ; void max_length ( int N , int x , vector < int > & v ) { int i , a ; vector < int > preff , suff ; int ct = 0 ; for ( i = 0 ; i < N ; i ++ ) { a = v [ i ] ; if ( a % x == 0 ) { ct += 1 ; } } if ( ct == N ) { cout << -1 << endl ; return ; } reverse ( v . begin ( ) , v . end ( ) ) ; suff . push_back ( v [ 0 ] ) ; for ( i = 1 ; i < N ; i ++ ) { suff . push_back ( v [ i ] + suff [ i - 1 ] ) ; } reverse ( v . begin ( ) , v . end ( ) ) ; reverse ( suff . begin ( ) , suff . end ( ) ) ; preff . push_back ( v [ 0 ] ) ; for ( i = 1 ; i < N ; i ++ ) { preff . push_back ( v [ i ] + preff [ i - 1 ] ) ; } int ans = 0 ; int lp = 0 ; int rp = N - 1 ; for ( i = 0 ; i < N ; i ++ ) { if ( suff [ i ] % x != 0 && ( ans < ( N - 1 ) ) ) { lp = i ; rp = N - 1 ; ans = max ( ans , N - i ) ; } if ( preff [ i ] % x != 0 && ( ans < ( i + 1 ) ) ) { lp = 0 ; rp = i ; ans = max ( ans , i + 1 ) ; } } for ( i = lp ; i <= rp ; i ++ ) { cout << v [ i ] << " ▁ " ; } } int main ( ) { int x = 3 ; vector < int > v = { D2 : V21 , 3 , 2 , 6 } ; int N = v . size ( ) ; max_length ( N , x , v ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ct, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void maxUpdated ( vector < int > arr ) { int h_score = arr [ 0 ] ; int l_score = arr [ 0 ] ; int i = 1 , j = 1 ; for ( auto n : arr ) { if ( h_score < n ) { h_score = n ; i ++ ; } if ( l_score > n ) { l_score = n ; j ++ ; } } cout << " Number ▁ of ▁ times ▁ maximum ▁ value ▁ " ; cout << " updated ▁ = ▁ " << i << endl ; cout << " Number ▁ of ▁ times ▁ minimum ▁ value ▁ " ; cout << " updated ▁ = ▁ " << j << endl ; } int main ( ) { vector < int > arr ( { 10 , 5 , 20 , 22 } ) ; maxUpdated ( arr ) ; }

Accumulator variables: i, j, stdc
Iterator variables: n
C++ program:
#include <bits/stdc++.h>
using namespace std ; void farthest_min ( int a [ ] , int n ) { int suffix_min [ n ] ; suffix_min [ n - 1 ] = a [ n - 1 ] ; for ( int i = n - 2 ; i >= 0 ; i -- ) { suffix_min [ i ] = min ( suffix_min [ i + 1 ] , a [ i ] ) ; } for ( int i = 0 ; i < n ; i ++ ) { int low = i + 1 , high = n - 1 , ans = -1 ; while ( low <= high ) { int mid = ( low + high ) / 2 ; if ( suffix_min [ mid ] < a [ i ] ) { ans = mid ; low = mid + 1 ; } else high = mid - 1 ; } cout << ans << " ▁ " ; } } int main ( ) { int a [ ] = { 3 , 1 , 5 , 2 , 4 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; farthest_min ( a , 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 ; void printElements ( int a [ ] , int n ) { sort ( a , a + n , greater < int > ( ) ) ; int cnt = 1 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( a [ i ] != a [ i + 1 ] ) { cout << a [ i ] << " ▁ occurs ▁ " << cnt << " ▁ times STRNEWLINE " ; cnt = 1 ; } else cnt += 1 ; } cout << a [ n - 1 ] << " ▁ occurs ▁ " << cnt << " ▁ times STRNEWLINE " ; } int main ( ) { int a [ ] = { 1 , 1 , 1 , 2 , 3 , 4 , 9 , 9 , 10 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; printElements ( a , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cnt, i, stdc
Iterator variables: i
C++ program:
#include <iostream>
#include <math.h>
#define SMALL_N  1000000
#define LARGE_N  1000000000000000
using namespace std ; long long func ( long long a , long long b , long long c , long long n ) { long long res = a * n ; long long logVlaue = floor ( log2 ( n ) ) ; res += b * n * logVlaue ; res += c * ( n * n * n ) ; return res ; } long long getPositionInSeries ( long long a , long long b , long long c , long long k ) { long long start = 1 , end = SMALL_N ; if ( c == 0 ) { end = LARGE_N ; } long long ans = 0 ; while ( start <= end ) { long long mid = ( start + end ) / 2 ; long long val = func ( a , b , c , mid ) ; if ( val == k ) { ans = mid ; break ; } else if ( val > k ) { end = mid - 1 ; } else { start = mid + 1 ; } } return ans ; } int main ( ) { long long a = 2 , b = 1 , c = 1 ; long long k = 12168587437017 ; cout << getPositionInSeries ( a , b , c , k ) ; return 0 ; }

Accumulator variables: res
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkSorted ( int n , int arr [ ] ) { int b [ n ] ; for ( int i = 0 ; i < n ; i ++ ) b [ i ] = arr [ i ] ; sort ( b , b + n ) ; int ct = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( arr [ i ] != b [ i ] ) ct ++ ; if ( ct == 0 ct == 2 ) return true ; else return false ; } int main ( ) { int arr [ ] = { 1 , 5 , 3 , 4 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; if ( checkSorted ( n , arr ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: i, n
Accumulator variables: ct, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkIndices ( int Arr [ ] , int N ) { for ( int i = 0 ; i < N - 1 ; i ++ ) { for ( int j = i + 1 ; j < N ; j ++ ) { if ( Arr [ i ] != Arr [ j ] ) { if ( Arr [ Arr [ i ] - 1 ] == Arr [ Arr [ j ] - 1 ] ) return true ; } } } return false ; } int main ( ) { int Arr [ ] = { 3 , 2 , 1 , 1 , 4 } ; int N = sizeof ( Arr ) / sizeof ( Arr [ 0 ] ) ; checkIndices ( Arr , N ) ? cout << " Yes " : cout << " No " ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
#include <unordered_map>
#include <vector>
using namespace std ; typedef pair < int , int > Pair ; void findPairs ( int arr [ ] , int n ) { unordered_map < int , vector < Pair > > map ; for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { int sum = arr [ i ] + arr [ j ] ; if ( map . find ( sum ) != map . end ( ) ) { for ( auto pair : map . find ( sum ) -> second ) { int m = pair . first , n = pair . second ; if ( ( m != i && m != j ) && ( n != i && n != j ) ) { cout << " Pair ▁ First ( " << arr [ i ] << " , ▁ " << arr [ j ] << " Pair Second ( " ▁ < < ▁ arr [ m ] ▁ < < ▁ " , " ▁ < < ▁ arr [ n ] ▁ < < ▁ " ) " return ; } } } map [ sum ] . push_back ( { i , j } ) ; } } cout << " No ▁ such ▁ non - overlapping ▁ pairs ▁ present " ; } int main ( ) { int arr [ ] = { 8 , 4 , 7 , 8 , 4 } ; int size = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findPairs ( arr , size ) ; return 0 ; }

Index/key variables: i, j, m, n, sum
Accumulator variables: i, j
Iterator variables: i, j, pair
C++ program:
#include <bits/stdc++.h>
using namespace std ; int printPairs ( int arr [ ] , int n , int sum ) { for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) if ( arr [ i ] + arr [ j ] == sum ) cout << " ( " << arr [ i ] << " , ▁ " << arr [ j ] << " ) " << endl ; } int main ( ) { int arr [ ] = { 1 , 5 , 7 , -1 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int sum = 6 ; printPairs ( arr , n , sum ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countTripletsLessThanL ( int n , int L , int * arr ) { sort ( arr , arr + n ) ; int ways = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int indexGreater = upper_bound ( arr , arr + n , arr [ i ] + L ) - arr ; int numberOfElements = indexGreater - ( i + 1 ) ; if ( numberOfElements >= 2 ) { ways += ( numberOfElements * ( numberOfElements - 1 ) / 2 ) ; } } return ways ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int L = 4 ; int ans = countTripletsLessThanL ( n , L , arr ) ; cout << " Total ▁ Number ▁ of ▁ ways ▁ = ▁ " << ans << " STRNEWLINE " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, ways
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int minSum ( int arr [ ] , int n ) { int sum = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] == arr [ i - 1 ] ) { int j = i ; while ( j < n && arr [ j ] <= arr [ j - 1 ] ) { arr [ j ] = arr [ j ] + 1 ; j ++ ; } } sum = sum + arr [ i ] ; } return sum ; } int main ( ) { int arr [ ] = { 2 , 2 , 3 , 5 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << minSum ( arr , n ) << endl ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int minSum ( int arr [ ] , int n ) { int sum = arr [ 0 ] , prev = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] <= prev ) { prev = prev + 1 ; sum = sum + prev ; } else { sum = sum + arr [ i ] ; prev = arr [ i ] ; } } return sum ; } int main ( ) { int arr [ ] = { 2 , 2 , 3 , 5 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << minSum ( arr , n ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <iostream>
#include <ctime>
using namespace std ; int getRandom ( int x , int y ) { srand ( time ( NULL ) ) ; return ( x + rand ( ) % ( y - x + 1 ) ) ; } int randomizedBinarySearch ( int arr [ ] , int l , int r , int x ) { if ( r >= l ) { int mid = getRandom ( l , r ) ; if ( arr [ mid ] == x ) return mid ; if ( arr [ mid ] > x ) return randomizedBinarySearch ( arr , l , mid - 1 , x ) ; return randomizedBinarySearch ( arr , mid + 1 , r , x ) ; } return -1 ; } int main ( void ) { int arr [ ] = { 2 , 3 , 4 , 10 , 40 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int x = 10 ; int result = randomizedBinarySearch ( arr , 0 , n - 1 , x ) ; ( result == -1 ) ? printf ( " Element ▁ is ▁ not ▁ present ▁ in ▁ array " ) : printf ( " Element ▁ is ▁ present ▁ at ▁ index ▁ % d " , result ) ; return 0 ; }

Index/key variables: mid
C++ program:
#include <bits/stdc++.h>
using namespace std ; string remVowel ( string str ) { vector < char > vowels = { ' a ' , ' e ' , ' i ' , ' o ' , ' u ' , ' A ' , ' E ' , ' I ' , ' O ' , ' U ' } ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( find ( vowels . begin ( ) , vowels . end ( ) , str [ i ] ) != vowels . end ( ) ) { str = str . replace ( i , 1 , " " ) ; i -= 1 ; } } return str ; } int main ( ) { string str = " GeeeksforGeeks ▁ - ▁ A ▁ Computer " " ▁ Science ▁ Portal ▁ for ▁ Geeks " ; cout << remVowel ( str ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minCostToMakeElementEqual ( int a [ ] , int n ) { int y ; if ( n % 2 == 1 ) y = a [ n / 2 ] ; else y = ( a [ n / 2 ] + a [ ( n - 2 ) / 2 ] ) / 2 ; int s = 0 ; for ( int i = 0 ; i < n ; i ++ ) s += abs ( a [ i ] - y ) ; return s ; } int main ( ) { int a [ ] = { 1 , 100 , 101 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << ( minCostToMakeElementEqual ( a , n ) ) ; }

Index/key variables: i
Accumulator variables: i, s, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isSorted ( int arr [ ] , int n ) { for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( arr [ i ] > arr [ i + 1 ] ) return false ; } return true ; } bool sortPoss ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) { int idx = -1 ; int minVar = arr [ i ] ; int j = i ; while ( j < n ) { if ( arr [ j ] < minVar ) { minVar = arr [ j ] ; idx = j ; } j = j + 2 ; } if ( idx != -1 ) { swap ( arr [ i ] , arr [ idx ] ) ; } } if ( isSorted ( arr , n ) ) return true ; else return false ; } int main ( ) { int arr [ ] = { 3 , 5 , 1 , 2 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; if ( sortPoss ( arr , n ) ) cout << " True " ; else cout << " False " ; return 0 ; }

Index/key variables: i, idx, j
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int upperBound ( int arr [ ] , int N , int K ) { int l = 0 ; int r = N ; while ( l < r ) { int mid = ( l + r ) / 2 ; if ( arr [ mid ] <= K ) { l = mid + 1 ; } else { r = mid ; } } return l ; } void NDivKWithFreq ( int arr [ ] , int N , int K ) { sort ( arr , arr + N ) ; int i = 0 ; while ( i < N ) { int X = upperBound ( arr , N , arr [ i ] ) ; if ( ( X - i ) > N / 4 ) { cout << arr [ i ] << " ▁ " ; } i = X ; } } int main ( ) { int arr [ ] = { 1 , 2 , 2 , 6 , 6 , 6 , 6 , 7 , 10 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 4 ; NDivKWithFreq ( arr , N , K ) ; return 0 ; }

Index/key variables: i, mid
Accumulator variables: stdc
C++ program:
#include <iostream>
using namespace std ; long maxSum ( int a [ ] , int n ) { int count [ n + 1 ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) count [ min ( a [ i ] , n ) ] ++ ; int size = 0 ; long ans = 0 ; for ( int k = 1 ; k <= n ; k ++ ) { while ( count [ k ] > 0 && size < k ) { size ++ ; ans += size ; count [ k ] -- ; } ans += k * count [ k ] ; } return ans ; } int main ( ) { int arr [ ] = { 3 , 5 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << ( maxSum ( arr , n ) ) ; return 0 ; }

Index/key variables: i, k
Accumulator variables: ans, i, k, size
Iterator variables: i, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; void answerQueries ( int arr [ ] , int n , vector < pair < int , int > > & queries ) { for ( int i = 0 ; i < queries . size ( ) ; i ++ ) { int ans = 0 ; int l = queries [ i ] . first - 1 ; int r = queries [ i ] . second - 1 ; map < int , int > freq ; for ( int j = l ; j <= r ; j ++ ) { freq [ arr [ j ] ] ++ ; } for ( auto & i : freq ) { ans += ( i . first * i . second ) ; } cout << ans << endl ; } } int main ( ) { int arr [ ] = { 1 , 2 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; vector < pair < int , int > > queries = { { 1 , 2 } , { 1 , 3 } } ; answerQueries ( arr , n , queries ) ; }

Index/key variables: i, j
Accumulator variables: ans, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Query { int l , r , x , index ; } ; struct Arrays { int val , index ; } ; bool cmp1 ( Query q1 , Query q2 ) { return q1 . x < q2 . x ; } bool cmp2 ( Arrays x , Arrays y ) { return x . val < y . val ; } void update ( int * Fenwick , int index , int val , int n ) { while ( index <= n ) { Fenwick [ index ] += val ; index += index & ( - index ) ; } } int query ( int * Fenwick , int index , int n ) { int sum = 0 ; while ( index > 0 ) { sum = sum + Fenwick [ index ] ; index -= index & ( - index ) ; } return sum ; } int maxLength ( int n , vector < int > & v ) { int where [ n + 2 ] ; memset ( where , 0 , sizeof where ) ; Arrays arr [ n ] ; for ( int i = 1 ; i <= n ; ++ i ) { v [ i - 1 ] = v [ i - 1 ] - 1 ; int x = v [ i - 1 ] ; where [ x ] = i - 1 ; arr [ i - 1 ] . val = x ; arr [ i - 1 ] . index = i - 1 ; } if ( n <= 2 ) { cout << n << endl ; return 0 ; } int left = n , right = 0 , mx = 0 ; Query queries [ 4 * n ] ; int j = 0 ; for ( int i = n - 1 ; i >= 0 ; -- i ) { left = min ( left , where [ i ] ) ; right = max ( right , where [ i ] ) ; int diff = right - left ; if ( diff == 0 diff == 1 ) { continue ; } int val1 = v [ left ] ; int val2 = v [ right ] ; int minn = min ( val1 , val2 ) ; queries [ j ] . l = left + 1 ; queries [ j ] . r = right - 1 ; queries [ j ] . x = minn ; queries [ j ] . index = j ; ++ j ; } int Fenwick [ n + 1 ] ; memset ( Fenwick , 0 , sizeof Fenwick ) ; int q = j - 1 ; sort ( arr , arr + n + 1 , cmp2 ) ; sort ( queries , queries + q + 1 , cmp1 ) ; int curr = 0 ; int ans [ q ] ; memset ( ans , 0 , sizeof ans ) ; for ( int i = 0 ; i <= q ; ++ i ) { while ( arr [ curr ] . val <= queries [ i ] . x and curr < n ) { update ( Fenwick , arr [ curr ] . index + 1 , 1 , n ) ; curr ++ ; } ans [ queries [ i ] . index ] = query ( Fenwick , queries [ i ] . r + 1 , n ) - query ( Fenwick , queries [ i ] . l , n ) ; } for ( int i = 0 ; i <= q ; ++ i ) { mx = max ( mx , ans [ i ] ) ; } mx = mx + 2 ; return mx ; } int main ( ) { int n = 6 ; vector < int > v = { 4 , 2 , 6 , 5 , 3 , 1 } ; cout << maxLength ( n , v ) << endl ; return 0 ; }

Index/key variables: curr, i, index, j, left, n, q, right, x
Accumulator variables: curr, index, stdc
Iterator variables: i
Class/struct names: Arrays, Query
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPandigital ( string str ) { if ( str . length ( ) != 9 ) return false ; char ch [ str . length ( ) ] ; strcpy ( ch , str . c_str ( ) ) ; sort ( ch , ch + str . length ( ) ) ; string s = ch ; if ( s . compare ( "123456789" ) == 0 ) return true ; else return true ; } bool PandigitalProduct_1_9 ( int n ) { for ( int i = 1 ; i * i <= n ; i ++ ) if ( n % i == 0 && isPandigital ( to_string ( n ) + to_string ( i ) + to_string ( n / i ) ) ) return true ; return false ; } int main ( ) { int n = 6952 ; if ( PandigitalProduct_1_9 ( n ) == true ) cout << " yes " ; else cout << " no " ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printModeMedian ( int a [ ] , int n ) { int b [ n ] ; int max = * max_element ( a , a + n ) ; int t = max + 1 ; int count [ t ] ; for ( int i = 0 ; i < t ; i ++ ) count [ i ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) count [ a [ i ] ] ++ ; int mode = 0 ; int k = count [ 0 ] ; for ( int i = 1 ; i < t ; i ++ ) { if ( count [ i ] > k ) { k = count [ i ] ; mode = i ; } } for ( int i = 1 ; i < t ; i ++ ) count [ i ] = count [ i ] + count [ i - 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { b [ count [ a [ i ] ] - 1 ] = a [ i ] ; count [ a [ i ] ] -- ; } float median ; if ( n % 2 != 0 ) median = b [ n / 2 ] ; else median = ( b [ ( n - 1 ) / 2 ] + b [ ( n / 2 ) ] ) / 2.0 ; cout << " median ▁ = ▁ " << median << endl ; cout << " mode ▁ = ▁ " << mode ; } int main ( ) { int a [ ] = { 1 , 4 , 1 , 2 , 7 , 1 , 2 , 5 , 3 , 6 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; printModeMedian ( a , n ) ; return 0 ; }

Index/key variables: i, n, t
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <cstring>
#include <iostream>
#include <string>
using namespace std ; # define MAX  26
bool function ( string str ) { int l = str . length ( ) ; int counter1 [ MAX ] ; int counter2 [ MAX ] ; memset ( counter1 , 0 , sizeof ( counter1 ) ) ; memset ( counter2 , 0 , sizeof ( counter2 ) ) ; for ( int i = 0 ; i < l / 2 ; i ++ ) counter1 [ str [ i ] - ' a ' ] ++ ; for ( int i = l / 2 ; i < l ; i ++ ) counter2 [ str [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < MAX ; i ++ ) if ( counter2 [ i ] != counter1 [ i ] ) return true ; return false ; } int main ( ) { string str = " abcasdsabcae " ; if ( function ( str ) ) cout << " Yes , ▁ both ▁ halves ▁ differ " << " ▁ by ▁ at ▁ least ▁ one ▁ character " ; else cout << " No , ▁ both ▁ halves ▁ do ▁ " << " not ▁ differ ▁ at ▁ all " ; return 0 ; }

Index/key variables: MAX, i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <cstring>
#include <iostream>
#include <string>
using namespace std ; # define MAX  26
bool function ( string str ) { int l = str . length ( ) ; int counter [ MAX ] ; memset ( counter , 0 , sizeof ( counter ) ) ; for ( int i = 0 ; i < l / 2 ; i ++ ) counter [ str [ i ] - ' a ' ] ++ ; for ( int i = l / 2 ; i < l ; i ++ ) counter [ str [ i ] - ' a ' ] -- ; for ( int i = 0 ; i < MAX ; i ++ ) if ( counter [ i ] != 0 ) return true ; return false ; } int main ( ) { string str = " abcasdsabcae " ; if ( function ( str ) ) cout << " Yes , ▁ both ▁ halves ▁ differ " << " ▁ by ▁ at ▁ least ▁ one ▁ character " ; else cout << " No , ▁ both ▁ halves ▁ do " << " ▁ not ▁ differ ▁ at ▁ all " ; return 0 ; }

Index/key variables: MAX, i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct element { int index , no_of_fact ; } ; int countFactors ( int n ) { int count = 0 ; int sq = sqrt ( n ) ; if ( sq * sq == n ) count ++ ; for ( int i = 1 ; i < sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) count += 2 ; } return count ; } bool compare ( struct element e1 , struct element e2 ) { if ( e1 . no_of_fact == e2 . no_of_fact ) return e1 . index < e2 . index ; return e1 . no_of_fact > e2 . no_of_fact ; } void printOnBasisOfFactors ( int arr [ ] , int n ) { struct element num [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { num [ i ] . index = i ; num [ i ] . no_of_fact = countFactors ( arr [ i ] ) ; } sort ( num , num + n , compare ) ; for ( int i = 0 ; i < n ; i ++ ) cout << arr [ num [ i ] . index ] << " ▁ " ; } int main ( ) { int arr [ ] = { 5 , 11 , 10 , 20 , 9 , 16 , 23 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; printOnBasisOfFactors ( arr , n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: count, i, stdc
Iterator variables: i
Class/struct names: element
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minDifferenceAmongMaxMin ( int arr [ ] , int N , int K ) { sort ( arr , arr + N ) ; int res = INT_MAX ; for ( int i = 0 ; i <= ( N - K ) ; i ++ ) { int curSeqDiff = arr [ i + K - 1 ] - arr [ i ] ; res = min ( res , curSeqDiff ) ; } return res ; } int main ( ) { int arr [ ] = { 10 , 20 , 30 , 100 , 101 , 102 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 3 ; cout << minDifferenceAmongMaxMin ( arr , N , K ) ; return 0 ; }

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

Index/key variables: i, idx
Accumulator variables: i, result, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool possible ( int x , int S , int N ) { int minSum = ( x * ( x + 1 ) ) / 2 ; int maxSum = ( x * ( ( 2 * N ) - x + 1 ) ) / 2 ; if ( S < minSum S > maxSum ) { return false ; } return true ; } void findPermutation ( int N , int L , int R , int S ) { int x = R - L + 1 ; if ( ! possible ( x , S , N ) ) { cout << -1 ; return ; } else { vector < int > v ; for ( int i = N ; i >= 1 ; -- i ) { if ( ( S - i ) >= 0 && possible ( x - 1 , S - i , i - 1 ) ) { S = S - i ; x -- ; v . push_back ( i ) ; } if ( S == 0 ) { break ; } } if ( S != 0 ) { cout << -1 ; return ; } vector < int > v1 ; for ( int i = 1 ; i <= N ; ++ i ) { vector < int > :: iterator it = find ( v . begin ( ) , v . end ( ) , i ) ; if ( it == v . end ( ) ) { v1 . push_back ( i ) ; } } int j = 0 , f = 0 ; for ( int i = 1 ; i < L ; ++ i ) { cout << v1 [ j ] << " ▁ " ; j ++ ; } for ( int i = L ; i <= R ; ++ i ) { cout << v [ f ] << " ▁ " ; f ++ ; } for ( int i = R + 1 ; i <= N ; ++ i ) { cout << v1 [ j ] << " ▁ " ; j ++ ; } } return ; } int main ( ) { int N = 6 , L = 3 , R = 5 , S = 8 ; findPermutation ( N , L , R , S ) ; return 0 ; }

Index/key variables: f, j
Accumulator variables: f, j, stdc, x
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void skipIndices ( int N , int T , int arr [ ] ) { int sum = 0 ; map < int , int > count ; for ( int i = 0 ; i < N ; i ++ ) { int d = sum + arr [ i ] - T ; int k = 0 ; if ( d > 0 ) { for ( auto u = count . rbegin ( ) ; u != count . rend ( ) ; u ++ ) { int j = u -> first ; int x = j * count [ j ] ; if ( d <= x ) { k += ( d + j - 1 ) / j ; break ; } k += count [ j ] ; d -= x ; } } sum += arr [ i ] ; count [ arr [ i ] ] ++ ; cout << k << " ▁ " ; } } int main ( ) { int N = 7 ; int T = 15 ; int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 } ; skipIndices ( N , T , arr ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: d, i, k, stdc, sum, u
Iterator variables: i, u
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxNumPalindrome ( string S ) { int i = 0 ; int freq [ 26 ] = { 0 } ; int freqPair = 0 ; int len = S . length ( ) / 3 ; while ( i < S . length ( ) ) { freq [ S [ i ] - ' a ' ] ++ ; i ++ ; } for ( i = 0 ; i < 26 ; i ++ ) { freqPair += ( freq [ i ] / 2 ) ; } return min ( freqPair , len ) ; } int main ( ) { string S = " geeksforg " ; cout << maxNumPalindrome ( S ) << endl ; return 0 ; }

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