dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxSum ( int arr [ ] , int n ) { if ( n < 2 ) return -1 ; int ans = arr [ 0 ] + arr [ 1 ] ; for ( int i = 1 ; i + 1 < n ; i ++ ) ans = min ( ans , ( arr [ i ] + arr [ i + 1 ] ) ) ; return ans ; } int main ( ) { int arr [ ] = { 1 , 12 , 2 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maxSum ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int f ( int n ) { return n * ( 2 * n * n - 1 ) ; } bool binarySearch ( int low , int high , int x ) { while ( low <= high ) { long long mid = ( low + high ) / 2 ; if ( f ( mid ) < x ) low = mid + 1 ; else if ( f ( mid ) > x ) high = mid - 1 ; else return true ; } return false ; } bool isStellaOctangula ( int x ) { if ( x == 0 ) return true ; int i = 1 ; while ( f ( i ) < x ) i = i * 2 ; if ( f ( i ) == x ) return true ; return binarySearch ( i / 2 , i , x ) ; } int main ( ) { int n = 51 ; if ( isStellaOctangula ( n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; string sortString ( string str , int n ) { string new_str = " " ; for ( int i = ' a ' ; i <= ' z ' ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) if ( str [ j ] == i ) new_str += str [ j ] ; return new_str ; } int main ( ) { string str = " geeksforgeeks " ; int n = str . size ( ) ; cout << sortString ( str , n ) ; return 0 ; }

Index/key variables: j
Accumulator variables: i, j, new_str, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; string sortString ( string str , int n ) { int i ; char arr [ 26 ] = { 0 } ; string new_str = " " ; for ( i = 0 ; i < n ; i ++ ) ++ arr [ str [ i ] - ' a ' ] ; for ( i = 0 ; i < 26 ; i ++ ) while ( arr [ i ] -- ) new_str += i + ' a ' ; return new_str ; } int main ( ) { string str = " geeksforgeeks " ; int n = str . size ( ) ; cout << sortString ( str , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, new_str
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { char data ; struct Node * next ; } ; char maxChar ( struct Node * head ) { struct Node * p = head ; int hash [ 256 ] = { 0 } ; while ( p != NULL ) { hash [ p -> data ] ++ ; p = p -> next ; } p = head ; int max = -1 ; char res ; while ( p != NULL ) { if ( max < hash [ p -> data ] ) { res = p -> data ; max = hash [ p -> data ] ; } p = p -> next ; } return res ; } void push ( struct Node * * head_ref , char new_data ) { struct Node * new_node = new Node ; new_node -> data = new_data ; new_node -> next = ( * head_ref ) ; ( * head_ref ) = new_node ; } int main ( ) { struct Node * head = NULL ; char str [ ] = " skeegforskeeg " ; for ( int i = 0 ; str [ i ] != ' \0' ; i ++ ) push ( & head , str [ i ] ) ; cout << maxChar ( head ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
#define N  3
using namespace std ; int getGreatestSum ( int a [ ] [ N ] ) { int prev_max = 0 ; for ( int j = 0 ; j < N ; j ++ ) if ( prev_max < a [ N - 1 ] [ j ] ) prev_max = a [ N - 1 ] [ j ] ; int sum = prev_max ; for ( int i = N - 2 ; i >= 0 ; i -- ) { int curr_max = INT_MIN ; for ( int j = 0 ; j < N ; j ++ ) if ( prev_max > a [ i ] [ j ] && a [ i ] [ j ] > curr_max ) curr_max = a [ i ] [ j ] ; if ( curr_max == INT_MIN ) return -1 ; prev_max = curr_max ; sum += prev_max ; } return sum ; } int main ( ) { int a [ 3 ] [ 3 ] = { { 1 , 2 , 3 } , { 4 , 5 , 6 } , { 7 , 8 , 9 } } ; cout << getGreatestSum ( a ) << endl ; int b [ 3 ] [ 3 ] = { { 4 , 5 , 6 } , { 4 , 5 , 6 } , { 4 , 5 , 6 } } ; cout << getGreatestSum ( b ) << endl ; return 0 ; }

Index/key variables: N, i, j
Accumulator variables: i, j, stdc, sum
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void occurrenceDays ( int n , string firstday ) { string days [ ] = { " Monday " , " Tuesday " , " Wednesday " , " Thursday " , " Friday " , " Saturday " , " Sunday " } ; int count [ 7 ] ; for ( int i = 0 ; i < 7 ; i ++ ) count [ i ] = 4 ; int pos ; for ( int i = 0 ; i < 7 ; i ++ ) { if ( firstday == days [ i ] ) { pos = i ; break ; } } int inc = n - 28 ; for ( int i = pos ; i < pos + inc ; i ++ ) { if ( i > 6 ) count [ i % 7 ] = 5 ; else count [ i ] = 5 ; } for ( int i = 0 ; i < 7 ; i ++ ) { cout << days [ i ] << " ▁ " << count [ i ] << endl ; } } int main ( ) { int n = 31 ; string firstday = " Tuesday " ; occurrenceDays ( n , firstday ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findElement ( int n , int k ) { int left = 1 ; int right = pow ( 2 , n ) - 1 ; while ( 1 ) { int mid = ( left + right ) / 2 ; if ( k == mid ) { cout << ans << endl ; break ; } ans -- ; if ( k < mid ) right = mid - 1 ; else left = mid + 1 ; } } int main ( ) { int n = 4 , k = 8 ; findElement ( n , k ) ; return 0 ; }

Accumulator variables: ans, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * next ; } ; void push ( struct Node * * head_ref , int new_data ) { struct Node * new_node = ( struct Node * ) malloc ( sizeof ( struct Node ) ) ; new_node -> data = new_data ; new_node -> next = ( * head_ref ) ; ( * head_ref ) = new_node ; } int firstCommon ( struct Node * head1 , struct Node * head2 ) { for ( ; head1 != NULL ; head1 = head1 -> next ) for ( Node * p = head2 ; p != NULL ; p = p -> next ) if ( p -> data == head1 -> data ) return head1 -> data ; return 0 ; } int main ( ) { struct Node * head1 = NULL ; push ( & head1 , 20 ) ; push ( & head1 , 5 ) ; push ( & head1 , 15 ) ; push ( & head1 , 10 ) ; struct Node * head2 = NULL ; push ( & head2 , 10 ) ; push ( & head2 , 2 ) ; push ( & head2 , 15 ) ; push ( & head2 , 8 ) ; cout << firstCommon ( head1 , head2 ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countMaxSumPairs ( int a [ ] , int n ) { int first = INT_MIN , second = INT_MIN ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] > first ) { second = first ; first = a [ i ] ; } else if ( a [ i ] > second && a [ i ] != first ) second = a [ i ] ; } int cnt1 = 0 , cnt2 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == first ) if ( a [ i ] == second ) } if ( cnt1 == 1 ) return cnt2 ; if ( cnt1 > 1 ) return cnt1 * ( cnt1 - 1 ) / 2 ; } float findMaxSumProbability ( int a [ ] , int n ) { int total = n * ( n - 1 ) / 2 ; int max_sum_pairs = countMaxSumPairs ( a , n ) ; return ( float ) max_sum_pairs / ( float ) total ; } int main ( ) { int a [ ] = { 1 , 2 , 2 , 3 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << findMaxSumProbability ( a , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
int sum [ n + 1 ] = { 0 } ; for ( int i = 1 ; i <= n ; i ++ ) sum [ i ] = sum [ i - 1 ] + arr [ i - 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) dp [ 1 ] [ i ] = sum [ i ] ; and using it to calculate the result as : best = min ( best , max ( dp [ i - 1 ] [ p ] , sum [ j ] - sum [ p ] ) ) ;

Index/key variables: i, j, p
Accumulator variables: i
Iterator variables: i
C++ program:
for ( int i = k - 1 ; i <= n ; i ++ ) best = min ( best , max ( partition ( arr , i , k - 1 ) , sum ( arr , i , n - 1 ) ) ) ;

Accumulator variables: i
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int findS ( int s ) { int sum = 0 ; for ( int n = 1 ; sum < s ; n ++ ) { sum += n ; if ( sum == s ) return n ; } return -1 ; } int main ( ) { int s = 15 ; int n = findS ( s ) ; n == -1 ? cout << " - 1" : cout << n ; return 0 ; }

Accumulator variables: n, sum
Iterator variables: n
C++ program:
#include <bits/stdc++.h>
# define ll  long long
using namespace std ; ll int isvalid ( ll int s ) { float k = ( -1 + sqrt ( 1 + 8 * s ) ) / 2 ; if ( ceil ( k ) == floor ( k ) ) return k ; else return -1 ; } int main ( ) { int s = 15 ; cout << isvalid ( s ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int calcSafe ( int pos ) { int j = pos % 10 ; int i = pos / 10 ; int dis_11 = min ( abs ( 1 - i ) , abs ( 1 - j ) ) ; int dis_18 = min ( abs ( 1 - i ) , abs ( 8 - j ) ) ; int dis_81 = min ( abs ( 8 - i ) , abs ( 1 - j ) ) ; int dis_88 = min ( abs ( 8 - i ) , abs ( 8 - j ) ) ; int sum = dis_11 + dis_18 + dis_81 + dis_88 + 1 ; return ( 64 - sum ) ; } int main ( ) { int pos = 34 ; cout << " Safe ▁ Positions ▁ = ▁ " << calcSafe ( pos ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void merge ( int arr [ ] , int l , int m , int r , int * count_crossline ) { int i , j , k ; int n1 = m - l + 1 ; int n2 = r - m ; int L [ n1 ] , R [ n2 ] ; for ( i = 0 ; i < n1 ; i ++ ) L [ i ] = arr [ l + i ] ; for ( j = 0 ; j < n2 ; j ++ ) R [ j ] = arr [ m + 1 + j ] ; while ( i < n1 && j < n2 ) { if ( L [ i ] <= R [ j ] ) { arr [ k ] = L [ i ] ; i ++ ; } else { arr [ k ] = R [ j ] ; * count_crossline += ( n1 - i ) ; j ++ ; } k ++ ; } while ( i < n1 ) { arr [ k ] = L [ i ] ; i ++ ; k ++ ; } while ( j < n2 ) { arr [ k ] = R [ j ] ; j ++ ; k ++ ; } } void mergeSort ( int arr [ ] , int l , int r , int * count_crossline ) { if ( l < r ) { int m = l + ( r - l ) / 2 ; mergeSort ( arr , l , m , count_crossline ) ; mergeSort ( arr , m + 1 , r , count_crossline ) ; merge ( arr , l , m , r , count_crossline ) ; } } int countCrossLine ( int arr [ ] , int n ) { int count_crossline = 0 ; mergeSort ( arr , 0 , n - 1 , & count_crossline ) ; return count_crossline ; } int main ( ) { int arr [ ] = { 12 , 11 , 13 , 5 , 6 , 7 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countCrossLine ( arr , n ) << endl ; return 0 ; }

Index/key variables: i, j, k, n1, n2
Accumulator variables: count_crossline, i, j, k, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getCount ( int arr [ ] , int n , int num1 , int num2 ) { int i = 0 ; for ( i = 0 ; i < n ; i ++ ) if ( arr [ i ] == num1 ) break ; if ( i >= n - 1 ) return 0 ; int j ; for ( j = n - 1 ; j >= i + 1 ; j -- ) if ( arr [ j ] == num2 ) break ; if ( j == i ) return 0 ; return ( j - i - 1 ) ; } int main ( ) { int arr [ ] = { 3 , 5 , 7 , 6 , 4 , 9 , 12 , 4 , 8 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int num1 = 5 , num2 = 4 ; cout << getCount ( arr , n , num1 , num2 ) ; 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 ; #define ROW  3
#define COL  5
int minTotalDistance ( int grid [ ] [ COL ] ) { if ( ROW == 0 COL == 0 ) return 0 ; vector < int > vertical ; vector < int > horizontal ; for ( int i = 0 ; i < ROW ; i ++ ) { for ( int j = 0 ; j < COL ; j ++ ) { if ( grid [ i ] [ j ] == 1 ) { vertical . push_back ( i ) ; horizontal . push_back ( j ) ; } } } sort ( vertical . begin ( ) , vertical . end ( ) ) ; sort ( horizontal . begin ( ) , horizontal . end ( ) ) ; int size = vertical . size ( ) / 2 ; int x = vertical [ size ] ; int y = horizontal [ size ] ; int distance = 0 ; for ( int i = 0 ; i < ROW ; i ++ ) for ( int j = 0 ; j < COL ; j ++ ) if ( grid [ i ] [ j ] == 1 ) distance += abs ( x - i ) + abs ( y - j ) ; return distance ; } int main ( ) { int grid [ ROW ] [ COL ] = { { 1 , 0 , 1 , 0 , 1 } , { 0 , 1 , 0 , 0 , 0 } , { 0 , 1 , 1 , 0 , 0 } } ; cout << minTotalDistance ( grid ) ; return 0 ; }

Index/key variables: COL, ROW, i, j, size
Accumulator variables: distance, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int sumOfDigit ( int K ) { int sod = 0 ; while ( K ) { sod += K % 10 ; K /= 10 ; } return sod ; } int totalNumbersWithSpecificDifference ( int N , int diff ) { int low = 1 , high = N ; while ( low <= high ) { int mid = ( low + high ) / 2 ; if ( mid - sumOfDigit ( mid ) < diff ) low = mid + 1 ; else high = mid - 1 ; } return ( N - high ) ; } int main ( ) { int N = 13 ; int diff = 2 ; cout << totalNumbersWithSpecificDifference ( N , diff ) ; return 0 ; }

Accumulator variables: K, sod, stdc
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 ) { while ( l <= r ) { int m = getRandom ( l , r ) ; if ( arr [ m ] == x ) return m ; if ( arr [ m ] < x ) l = m + 1 ; else r = m - 1 ; } 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: m
C++ program:
#include <iostream>
using namespace std ; int countBuildings ( int arr [ ] , int n ) { int count = 1 ; int curr_max = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] > curr_max arr [ i ] == curr_max ) { count ++ ; curr_max = arr [ i ] ; } } return count ; } int main ( ) { int arr [ ] = { 7 , 4 , 8 , 2 , 9 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countBuildings ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int findExtra ( int arr1 [ ] , int arr2 [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) if ( arr1 [ i ] != arr2 [ i ] ) return i ; return n ; } int main ( ) { int arr1 [ ] = { 2 , 4 , 6 , 8 , 10 , 12 , 13 } ; int arr2 [ ] = { 2 , 4 , 6 , 8 , 10 , 12 } ; int n = sizeof ( arr2 ) / sizeof ( arr2 [ 0 ] ) ; cout << findExtra ( arr1 , arr2 , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int findExtra ( int arr1 [ ] , int arr2 [ ] , int n ) { int index = n ; int left = 0 , right = n - 1 ; while ( left <= right ) { int mid = ( left + right ) / 2 ; if ( arr2 [ mid ] == arr1 [ mid ] ) left = mid + 1 ; else { index = mid ; right = mid - 1 ; } } return index ; } int main ( ) { int arr1 [ ] = { 2 , 4 , 6 , 8 , 10 , 12 , 13 } ; int arr2 [ ] = { 2 , 4 , 6 , 8 , 10 , 12 } ; int n = sizeof ( arr2 ) / sizeof ( arr2 [ 0 ] ) ; cout << findExtra ( arr1 , arr2 , n ) ; return 0 ; }

Index/key variables: mid
C++ program:
#include <bits/stdc++.h>
using namespace std ; int computeCost ( int arr [ ] , int N , int X ) { int cost = 0 ; for ( int i = 0 ; i < N ; i ++ ) cost += abs ( arr [ i ] - X ) ; return cost ; } int minCostToMakeElementEqual ( int arr [ ] , int N ) { int low , high ; low = high = arr [ 0 ] ; for ( int i = 0 ; i < N ; i ++ ) { if ( low > arr [ i ] ) low = arr [ i ] ; if ( high < arr [ i ] ) high = arr [ i ] ; } while ( ( high - low ) > 2 ) { int mid1 = low + ( high - low ) / 3 ; int mid2 = high - ( high - low ) / 3 ; int cost1 = computeCost ( arr , N , mid1 ) ; int cost2 = computeCost ( arr , N , mid2 ) ; if ( cost1 < cost2 ) high = mid2 ; else low = mid1 ; } return computeCost ( arr , N , ( low + high ) / 2 ) ; } int main ( ) { int arr [ ] = { 1 , 100 , 101 } ; int N = sizeof ( arr ) / sizeof ( int ) ; cout << minCostToMakeElementEqual ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: cost, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minJumps ( int w [ ] , int l [ ] , int n ) { if ( n == 1 ) { cout << 0 ; return ; } int ans = 0 ; unordered_map < int , int > pos , jump ; unordered_map < int , bool > filled ; int a [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { pos [ w [ i ] ] = i ; filled [ i ] = true ; jump [ w [ i ] ] = l [ i ] ; a [ i ] = w [ i ] ; } sort ( a , a + n ) ; for ( int curr = 1 ; curr < n ; curr ++ ) { int currElementPos = pos [ a [ curr ] ] ; int prevElementPos = pos [ a [ curr - 1 ] ] ; if ( currElementPos > prevElementPos ) continue ; while ( currElementPos <= prevElementPos filled [ currElementPos ] ) { currElementPos += jump [ a [ curr ] ] ; ans ++ ; } pos [ a [ curr ] ] = currElementPos ; filled [ currElementPos ] = true ; } cout << ans ; } int main ( ) { int W [ ] = { 2 , 1 , 4 , 3 } ; int L [ ] = { 4 , 1 , 2 , 4 } ; int N = sizeof ( W ) / sizeof ( W [ 0 ] ) ; minJumps ( W , L , N ) ; return 0 ; }

Index/key variables: curr, currElementPos, i, n
Accumulator variables: ans, curr, currElementPos, i, stdc
Iterator variables: curr, i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void check ( int arr [ ] , int n ) { for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i - 1 ] >= ( i - 1 ) ) { int p = arr [ i - 1 ] - ( i - 1 ) ; arr [ i ] += p ; arr [ i - 1 ] -= p ; } } for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] <= arr [ i - 1 ] ) { cout << " No " ; return ; } } cout << " Yes " ; } int main ( ) { int arr [ ] = { 1 , 5 , 2 , 7 , 6 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; check ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int keyFunc ( int n ) { int rev = 0 ; while ( n > 0 ) { rev = rev << 1 ; if ( n & 1 == 1 ) rev = rev ^ 1 ; n = n >> 1 ; } return rev ; } vector < vector < int > > getNew ( vector < int > arr ) { vector < vector < int > > ans ; for ( int i : arr ) ans . push_back ( { keyFunc ( i ) , i } ) ; return ans ; } vector < int > getArr ( vector < vector < int > > arr ) { vector < int > ans ; for ( auto i : arr ) ans . push_back ( i [ 1 ] ) ; return ans ; } void sortArray ( vector < int > arr ) { vector < vector < int > > newArr = getNew ( arr ) ; sort ( newArr . begin ( ) , newArr . end ( ) ) ; arr = getArr ( newArr ) ; int n = arr . size ( ) ; cout << " [ " ; for ( int i = 0 ; i < n - 1 ; i ++ ) cout << arr [ i ] << " , ▁ " ; cout << arr [ n - 1 ] << " ] " ; } int main ( ) { vector < int > arr = { 43 , 52 , 61 , 41 } ; sortArray ( arr ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minimumSize ( int arr [ ] , int N , int K ) { sort ( arr , arr + N ) ; reverse ( arr , arr + N ) ; if ( count ( arr , arr + N , 0 ) == N ) cout << 0 ; else if ( K >= N ) cout << 1 << endl ; else cout << arr [ K ] << endl ; } int main ( ) { int arr [ ] = { 2 , 4 , 8 , 2 } ; int K = 2 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; minimumSize ( arr , N , K ) ; return 0 ; }

Index/key variables: K
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void isPossibleToSort ( int arr [ ] , int N ) { int idx = -1 ; for ( int i = 1 ; i < N ; i ++ ) { if ( arr [ i ] == 1 && arr [ i - 1 ] == 1 ) { idx = i ; break ; } } if ( idx == -1 ) { cout << " YES " ; return ; } for ( int i = idx + 1 ; i < N ; i ++ ) { if ( arr [ i ] == 0 && arr [ i - 1 ] == 0 ) { cout << " NO " ; return ; } } cout << " YES " ; } int main ( ) { int arr [ ] = { 1 , 0 , 1 , 0 , 1 , 1 , 0 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; isPossibleToSort ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxConsecutiveRopes ( int ropes [ ] , int N ) { int curSize = 0 ; sort ( ropes , ropes + N ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( ropes [ i ] <= curSize + 1 ) { curSize = curSize + ropes [ i ] ; } else break ; } return curSize ; } int main ( ) { int N = 5 ; int ropes [ ] = { 1 , 2 , 7 , 1 , 1 } ; cout << maxConsecutiveRopes ( ropes , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxRanges ( vector < vector < int > > arr , int N ) { sort ( arr . begin ( ) , arr . end ( ) ) ; int count = 1 ; vector < int > prev = arr [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { vector < int > last = arr [ i - 1 ] ; vector < int > current = arr [ i ] ; if ( last [ 0 ] == current [ 0 ] && last [ 1 ] == current [ 1 ] && current [ 1 ] == current [ 0 ] ) continue ; int start = max ( prev [ 0 ] , current [ 0 ] - 1 ) ; int end = max ( prev [ 1 ] , current [ 1 ] ) ; if ( end - start > 0 ) { prev [ 0 ] = 1 + start ; prev [ 1 ] = end ; count ++ ; } } return count ; } int main ( ) { vector < vector < int > > range = { { 1 , 4 } , { 4 , 4 } , { 2 , 2 } , { 3 , 4 } , { 1 , 1 } } ; int N = range . size ( ) ; cout << maxRanges ( range , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool adjust ( string & S , int & i , int & start , int & end ) { int N = S . length ( ) ; start = i - 1 ; while ( i < N && S [ i ] < S [ i - 1 ] ) { i ++ ; } end = i - 1 ; if ( start <= 0 && i >= N ) return true ; if ( start >= 1 && i <= N ) { return ( S [ end ] >= S [ start - 1 ] && S [ start ] <= S [ i ] ) ; } if ( start >= 1 ) { return S [ end ] >= S [ start - 1 ] ; } if ( i < N ) { return S [ start ] <= S [ i ] ; } return false ; } void isPossible ( string & S , int N ) { int start = -1 , end = -1 ; bool flag = true ; for ( int i = 1 ; i < N ; i ++ ) { if ( S [ i ] < S [ i - 1 ] ) { if ( flag ) { if ( adjust ( S , i , start , end ) == false ) { cout << -1 << endl ; return ; } flag = false ; } else { cout << -1 << endl ; return ; } } } if ( start == -1 ) { start = end = 1 ; } cout << start << " ▁ " << end << " STRNEWLINE " ; } int main ( ) { string S = " abcyxuz " ; int N = S . length ( ) ; isPossible ( S , N ) ; return 0 ; }

Index/key variables: end, i, start
Accumulator variables: i, stdc
Iterator variables: i
Boolean variables: flag
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maximizedCapital ( int K , int W , vector < int > & profits , vector < int > & capital ) { priority_queue < int > pq ; vector < pair < int , int > > v ; for ( int i = 0 ; i < capital . size ( ) ; i ++ ) { v . push_back ( { capital [ i ] , i } ) ; } sort ( v . begin ( ) , v . end ( ) ) ; int j = 0 ; while ( K ) { while ( j < ( int ) capital . size ( ) && v [ j ] . first <= W ) { pq . push ( profits [ v [ j ] . second ] ) ; j ++ ; } if ( ! pq . empty ( ) ) { W = W + pq . top ( ) ; pq . pop ( ) ; } K -- ; } return W ; } int main ( ) { int K = 2 ; int W = 0 ; vector < int > P = { 1 , 2 , 3 } ; vector < int > C = { 0 , 1 , 1 } ; cout << maximizedCapital ( K , W , P , C ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: K, i, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maximumSum ( int arr [ ] , int S [ ] , int N , int K ) { int ans = 0 ; sort ( arr , arr + N , greater < int > ( ) ) ; for ( int i = 0 ; i < K ; i ++ ) ans += arr [ i ] ; sort ( S , S + K ) ; for ( int i = 0 ; i < K ; i ++ ) { if ( S [ i ] == 1 ) ans += arr [ i ] ; S [ i ] -- ; } int counter = K - 1 ; for ( int i = 0 ; i < K ; i ++ ) { counter = counter + S [ i ] ; if ( S [ i ] != 0 ) ans += arr [ counter ] ; } return ans ; } int main ( ) { int arr [ ] = { 1 , 13 , 7 , 17 } ; int S [ ] = { 1 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = sizeof ( S ) / sizeof ( S [ 0 ] ) ; cout << maximumSum ( arr , S , N , K ) ; return 0 ; }

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