dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maximumKthLargestsumPart ( int arr [ ] , int N , int M , int K ) { int maxSum = 0 ; if ( N % M ) return -1 ; int sz = ( N / M ) ; if ( K > sz ) return -1 ; sort ( arr , arr + N , greater < int > ( ) ) ; for ( int i = 1 ; i <= M ; i ++ ) { maxSum += arr [ i * K - 1 ] ; } return maxSum ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 } ; int M = 2 ; int K = 1 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maximumKthLargestsumPart ( arr , N , M , K ) ; return 0 ; }

Accumulator variables: i, maxSum, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
#include <iostream>
using namespace std ; void minimumRange ( int arr [ ] , int N , int K ) { if ( K >= N ) { cout << 0 ; return ; } sort ( arr , arr + N ) ; int left = 0 , right = N - 1 , i ; for ( i = 0 ; i < K ; i ++ ) { if ( arr [ right - 1 ] - arr [ left ] < arr [ right ] - arr [ left + 1 ] ) right -- ; else left ++ ; } cout << arr [ right ] - arr [ left ] ; } int main ( ) { int arr [ ] = { 5 , 10 , 12 , 14 , 21 , 54 , 61 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 4 ; minimumRange ( arr , N , K ) ; return 0 ; }

Index/key variables: left, right
Accumulator variables: i, left, right, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void splitArray ( int arr [ ] , int n , int K ) { sort ( arr , arr + n ) ; int i = n - 1 ; int result = 0 ; while ( K -- ) { result += arr [ i - 1 ] ; i -= 2 ; } cout << result ; } int main ( ) { int arr [ ] = { 1 , 3 , 1 , 5 , 1 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 2 ; splitArray ( arr , N , K ) ; return 0 ; }

Accumulator variables: K, i, result, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void merge ( int * indices , int * a , int l , int mid , int r ) { int temp_ind [ r - l + 1 ] , j = mid + 1 ; int i = 0 , temp_l = l , k ; while ( l <= mid && j <= r ) { if ( a [ indices [ l ] ] < a [ indices [ j ] ] ) temp_ind [ i ++ ] = indices [ l ++ ] ; else temp_ind [ i ++ ] = indices [ j ++ ] ; } while ( l <= mid ) temp_ind [ i ++ ] = indices [ l ++ ] ; while ( j <= r ) temp_ind [ i ++ ] = indices [ j ++ ] ; for ( k = 0 ; k < i ; k ++ ) indices [ temp_l ++ ] = temp_ind [ k ] ; } void divide ( int * indices , int * a , int l , int r ) { if ( l >= r ) return ; int mid = l / 2 + r / 2 ; divide ( indices , a , l , mid ) ; divide ( indices , a , mid + 1 , r ) ; merge ( indices , a , l , mid , r ) ; } void noOfSubsequences ( int arr [ ] , int N ) { int indices [ N ] , i ; for ( i = 0 ; i < N ; i ++ ) indices [ i ] = i ; divide ( indices , arr , 0 , N - 1 ) ; int B [ N ] ; int subseq = 1 ; for ( i = 0 ; i < N ; i ++ ) { B [ indices [ i ] ] = subseq ; subseq *= 2 ; } for ( i = 0 ; i < N ; i ++ ) cout << B [ i ] << " ▁ " ; } int main ( ) { int arr [ ] = { 2 , 3 , 1 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; noOfSubsequences ( arr , N ) ; return 0 ; }

Index/key variables: N, i, j, k, l
Accumulator variables: i, j, k, l, stdc, subseq, temp_l
Iterator variables: i, k
C++ program:
#include <iostream>
using namespace std ; void merge ( int * order , int * freq , int i , int mid , int j ) { int tempOrder [ j - i + 1 ] ; int temp = mid + 1 , index = -1 ; while ( i <= mid && temp <= j ) { if ( freq [ order [ i ] ] <= freq [ order [ temp ] ] ) { tempOrder [ ++ index ] = order [ i ++ ] ; } else { tempOrder [ ++ index ] = order [ temp ++ ] ; } } while ( i <= mid ) { tempOrder [ ++ index ] = order [ i ++ ] ; } while ( temp <= j ) { tempOrder [ ++ index ] = order [ temp ++ ] ; } for ( index ; index >= 0 ; index -- ) { order [ j -- ] = tempOrder [ index ] ; } } void divide ( int * order , int * freq , int i , int j ) { if ( i >= j ) return ; int mid = i / 2 + j / 2 ; divide ( order , freq , i , mid ) ; divide ( order , freq , mid + 1 , j ) ; merge ( order , freq , i , mid , j ) ; } void orderProcesses ( int A [ ] , int N , int q ) { int i = 0 ; int freq [ N ] ; for ( i = 0 ; i < N ; i ++ ) { freq [ i ] = ( A [ i ] / q ) + ( A [ i ] % q > 0 ) ; } int order [ 4 ] ; for ( i = 0 ; i < N ; i ++ ) { order [ i ] = i ; } divide ( order , freq , 0 , N - 1 ) ; for ( i = 0 ; i < N ; i ++ ) { cout << order [ i ] << " ▁ " ; } } int main ( ) { int arr [ ] = { 3 , 7 , 4 } ; int Q = 3 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; orderProcesses ( arr , N , Q ) ; return 0 ; }

Index/key variables: N, i, index, temp
Accumulator variables: i, index, j, temp
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxCostToRemove ( int arr [ ] , int N , int K ) { int maxCost = 0 ; sort ( arr , arr + N ) ; for ( int i = 0 ; i < N ; i += K ) { maxCost += arr [ i + 1 ] ; } return maxCost ; } int main ( ) { int arr [ ] = { 1 , 3 , 4 , 1 , 5 , 1 , 5 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 4 ; cout << maxCostToRemove ( arr , N , K ) ; }

Accumulator variables: i, maxCost, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; string convert_to_words ( int n ) { char num [ 1000 ] ; string str = to_string ( n ) ; strcpy ( num , str . c_str ( ) ) ; char * arr_ptr = & num [ 0 ] ; int len = strlen ( arr_ptr ) ; string ans = " " ; if ( len == 0 ) { ans += " Empty ▁ String " ; return ans ; } string single_digits [ ] = { " zero " , " one " , " two " , " three " , " four " , " five " , " six " , " seven " , " eight " , " nine " } ; string two_digits [ ] = { " " , " ten " , " eleven " , " twelve " , " thirteen " , " fourteen " , " fifteen " , " sixteen " , " seventeen " , " eighteen " , " nineteen " } ; string tens_multiple [ ] = { " " , " " , " twenty " , " thirty " , " forty " , " fifty " , " sixty " , " seventy " , " eighty " , " ninety " } ; string tens_power [ ] = { " hundred " , " thousand " } ; if ( len == 1 ) { ans += single_digits [ num [ 0 ] - '0' ] ; return ans ; } int x = 0 ; while ( x < len ) { if ( len >= 3 ) { if ( num [ x ] - '0' != 0 ) { ans += single_digits [ num [ x ] - '0' ] ; ans += " ▁ " ; ans += tens_power [ len - 3 ] ; ans += " ▁ " ; } -- len ; } else { if ( num [ x ] - '0' == 1 ) { int sum = num [ x ] - '0' + num [ x ] - '0' ; ans += two_digits [ sum ] ; return ans ; } else if ( num [ x ] - '0' == 2 && num [ x + 1 ] - '0' == 0 ) { ans += " twenty " ; return ans ; } else { int i = ( num [ x ] - '0' ) ; if ( i > 0 ) { ans += tens_multiple [ i ] ; ans += " ▁ " ; } else ans += " " ; ++ x ; if ( num [ x ] - '0' != 0 ) ans += single_digits [ num [ x ] - '0' ] ; } } ++ x ; } return " " ; } static void lexNumbers ( int n ) { vector < string > s ; for ( int i = 1 ; i <= n ; i ++ ) { s . push_back ( convert_to_words ( i ) ) ; } sort ( s . begin ( ) , s . end ( ) ) ; vector < string > ans ; for ( int i = 0 ; i < n ; i ++ ) ans . push_back ( s [ i ] ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) cout << ans [ i ] << " , ▁ " ; cout << ans [ n - 1 ] ; } int main ( ) { int n = 5 ; lexNumbers ( n ) ; return 0 ; }

Index/key variables: i, sum, x
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minimumCost ( int * binary , int n , int a , int b ) { vector < int > groupOfZeros ; int len = 0 , i = 0 ; bool increment_need = true ; while ( i < n ) { increment_need = true ; while ( i < n && binary [ i ] == 0 ) { len ++ ; i ++ ; increment_need = false ; } if ( increment_need == true ) { i ++ ; } if ( len != 0 ) { groupOfZeros . push_back ( len ) ; } len = 0 ; } sort ( groupOfZeros . begin ( ) , groupOfZeros . end ( ) ) ; i = 0 ; bool found_ones = false ; int NumOfOnes = 0 ; while ( i < n ) { found_ones = false ; while ( i < n && binary [ i ] == 1 ) { i ++ ; found_ones = true ; } if ( found_ones == false ) i ++ ; else NumOfOnes ++ ; } int ans = INT_MAX ; for ( int i = 0 ; i < n ; i ++ ) { int curr = 0 , totalOnes = NumOfOnes ; if ( i == 0 ) { curr = totalOnes * a ; } else { int mark = i , num_of_changes = 0 ; for ( int x : groupOfZeros ) { if ( mark >= x ) { totalOnes -- ; mark -= x ; num_of_changes += x ; } else { break ; } } curr = ( num_of_changes * b ) + ( totalOnes * a ) ; } ans = min ( ans , curr ) ; } cout << ans ; } int main ( ) { int arr [ ] = { 1 , 1 , 1 , 0 , 1 , 1 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int X = 10 , Y = 4 ; minimumCost ( arr , N , X , Y ) ; return 0 ; }

Index/key variables: i
Accumulator variables: NumOfOnes, i, len, mark, num_of_changes, stdc, totalOnes
Iterator variables: i, x
Boolean variables: found_ones, increment_need
C++ program:
#include <bits/stdc++.h>
using namespace std ; int isSortedparitions ( int arr [ ] , int i , int j ) { for ( int k = i + 1 ; k <= j ; k ++ ) { if ( arr [ k ] < arr [ k - 1 ] ) { return 0 ; } } return 1 ; } int partitionsArr ( int arr [ ] , int i , int j ) { if ( i >= j ) return 1 ; bool flag = isSortedparitions ( arr , i , j ) ; if ( flag ) { return ( j - i + 1 ) ; } int mid = ( i + j ) / 2 ; int X = partitionsArr ( arr , i , mid ) ; int Y = partitionsArr ( arr , mid + 1 , j ) ; return max ( X , Y ) ; } int main ( ) { int arr [ ] = { 11 , 12 , 1 , 2 , 13 , 14 , 3 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << partitionsArr ( arr , 0 , N - 1 ) ; return 0 ; }

Index/key variables: k
Accumulator variables: k, stdc
Iterator variables: k
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkIfPossibleMerge ( int A [ ] , int B [ ] , int N ) { int i = 0 ; int j = 0 ; int prev = -1 ; int flag = 1 ; while ( i < N && j < N ) { if ( A [ i ] < B [ j ] && prev != 0 ) { prev = 0 ; i ++ ; } else if ( B [ j ] < A [ i ] && prev != 1 ) { prev = 1 ; j ++ ; } else if ( A [ i ] == B [ j ] ) { if ( prev != 1 ) { prev = 1 ; j ++ ; } else { prev = 0 ; i ++ ; } } else { flag = 0 ; break ; } } return flag ; } int main ( ) { int A [ 3 ] = { 3 , 5 , 8 } ; int B [ 3 ] = { 2 , 4 , 6 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; if ( checkIfPossibleMerge ( A , B , N ) ) { cout << " Yes " ; } else { cout << " No " ; } return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minimum_possible_sum ( int arr [ ] , int n , int k ) { if ( n == 0 ) { return 0 ; } if ( n == 1 ) { return arr [ 0 ] ; } for ( int i = 0 ; i < k ; i ++ ) { int smallest_element = arr [ 0 ] ; int smallest_pos = 0 ; int largest_element = arr [ 0 ] ; int largest_pos = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] >= largest_element ) { largest_element = arr [ i ] ; largest_pos = i ; } if ( arr [ i ] < smallest_element ) { smallest_element = arr [ i ] ; smallest_pos = i ; } } int a = smallest_element * 2 ; int b = largest_element / 2 ; if ( a + b < smallest_element + largest_element ) { arr [ smallest_pos ] = a ; arr [ largest_pos ] = b ; } } int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ans += arr [ i ] ; } return ans ; } int main ( ) { int arr [ ] = { 50 , 1 , 100 , 100 , 1 } ; int K = 2 ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << minimum_possible_sum ( arr , n , K ) ; return 0 ; }

Index/key variables: i, largest_pos, smallest_pos
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxSum ( int n , int a [ ] , int l [ ] [ 2 ] , int q ) { vector < int > v ; int d [ n ] = { 0 } ; for ( int i = 0 ; i < q ; i ++ ) { for ( int x = l [ i ] [ 0 ] ; x <= l [ i ] [ 1 ] ; x ++ ) { if ( d [ x ] == 0 ) { d [ x ] = 1 ; } } } set < int > st ; for ( int i = 0 ; i < n ; i ++ ) { if ( d [ i ] == 0 ) { v . push_back ( a [ i ] ) ; st . insert ( i ) ; } } sort ( v . begin ( ) , v . end ( ) , greater < int > ( ) ) ; int c = 0 ; for ( auto it : st ) { a [ it ] = v ; c ++ ; } int pref_sum = 0 ; int temp_sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { temp_sum += a [ i ] ; pref_sum += temp_sum ; } return pref_sum ; } int main ( ) { int arr [ ] = { -8 , 4 , -2 , -6 , 4 , 7 , 1 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int q [ ] [ 2 ] = { { 0 , 0 } , { 4 , 5 } } ; int queries = sizeof ( q ) / sizeof ( q [ 0 ] ) ; cout << maxSum ( N , arr , q , queries ) ; return 0 ; }

Index/key variables: i, it, n, x
Accumulator variables: c, i, pref_sum, stdc, temp_sum, x
Iterator variables: i, it, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; void countPairs ( int A [ ] , int N ) { int count = 0 ; sort ( A , A + N ) ; int bits [ 32 ] = { 0 } ; for ( int i = 0 ; i < N ; i ++ ) { if ( A [ i ] == 0 ) { continue ; } for ( int j = 0 ; j < 32 ; j ++ ) { if ( ! ( ( 1LL << j ) & A [ i ] ) ) { count += bits [ j ] ; } } ++ bits [ ( int ) ( log2l ( A [ i ] ) ) ] ; } cout << count ; } int main ( ) { int arr [ ] = { 2 , 4 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; countPairs ( arr , N ) ; 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 ; void mostvisitedsector ( int N , vector < int > & A ) { int maxVisited = 0 ; map < int , int > mp ; for ( int i = 0 ; i < A . size ( ) - 1 ; i ++ ) { int start = A [ i ] % N ; int end = A [ i + 1 ] % N ; while ( start != end ) { if ( start == 0 ) { mp [ N ] ++ ; if ( mp [ N ] > maxVisited ) { maxVisited = mp [ N ] ; } } else { mp [ start ] ++ ; if ( mp [ start ] > maxVisited ) { maxVisited = mp [ start ] ; } } start = ( start + 1 ) % N ; } } mp [ A . back ( ) ] ++ ; if ( mp [ A . back ( ) ] > maxVisited ) { maxVisited = mp [ A . back ( ) ] ; } for ( auto x : mp ) { if ( x . second == maxVisited ) { cout << x . first << " ▁ " ; } } } int main ( ) { int N = 4 ; vector < int > arr = { 1 , 2 , 1 , 2 } ; mostvisitedsector ( N , arr ) ; return 0 ; }

Index/key variables: N, i, start
Accumulator variables: i, stdc
Iterator variables: i, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxRectangle ( vector < vector < int > > sequence , int size ) { long long int X_Cord [ size ] , Y_Cord [ size ] ; for ( int i = 0 ; i < size ; i ++ ) { X_Cord [ i ] = sequence [ i ] [ 0 ] ; Y_Cord [ i ] = sequence [ i ] [ 1 ] ; } sort ( X_Cord , X_Cord + size ) ; sort ( Y_Cord , Y_Cord + size ) ; long long int X_Max = 0 , Y_Max = 0 ; for ( int i = 0 ; i < size - 1 ; i ++ ) { X_Max = max ( X_Max , X_Cord [ i + 1 ] - X_Cord [ i ] ) ; Y_Max = max ( Y_Max , Y_Cord [ i + 1 ] - Y_Cord [ i ] ) ; } return X_Max * Y_Max ; } int main ( ) { vector < vector < int > > point = { { -2 , 0 } , { 2 , 0 } , { 4 , 0 } , { 4 , 2 } } ; int n = point . size ( ) ; cout << maxRectangle ( point , n ) ; }

Index/key variables: i, size
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void checkArrangement ( int A1 [ ] , int A2 [ ] , int n , int k ) { sort ( A1 , A1 + n ) ; sort ( A2 , A2 + n , greater < int > ( ) ) ; int flag = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( A1 [ i ] + A2 [ i ] > k ) || ( A1 [ i ] + A2 [ i ] < k / 2 ) ) { flag = 1 ; break ; } } if ( flag == 1 ) cout << " No " ; else cout << " Yes " ; } int main ( ) { int arr1 [ ] = { 1 , 3 , 4 , 5 } ; int arr2 [ ] = { 2 , 0 , 1 , 1 } ; int K = 6 ; int N = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; checkArrangement ( arr1 , arr2 , 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 MaxRearrngeSum ( int A [ ] , int B [ ] , int N ) { sort ( A , A + N ) ; sort ( B , B + N , greater < int > ( ) ) ; int maxSum = 0 ; for ( int i = 0 ; i < N ; i ++ ) { maxSum += abs ( A [ i ] - B [ i ] ) ; } return maxSum ; } int main ( ) { int A [ ] = { 1 , 2 , 2 , 4 , 5 } ; int B [ ] = { 5 , 5 , 5 , 6 , 6 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << MaxRearrngeSum ( A , B , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, maxSum, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int largestArea ( int arr1 [ ] , int n , int arr2 [ ] , int m ) { int end = 0 , start = 0 , i = 0 , j = 0 ; sort ( arr1 , arr1 + n ) ; sort ( arr2 , arr2 + m ) ; while ( i < n and j < m ) { if ( arr1 [ i ] == arr2 [ j ] ) { if ( start == 0 ) start = arr1 [ i ] ; else end = arr1 [ i ] ; i ++ ; j ++ ; } else if ( arr1 [ i ] > arr2 [ j ] ) j ++ ; else i ++ ; } if ( end == 0 or start == 0 ) return 0 ; else return ( end - start ) ; } int main ( ) { int arr1 [ ] = { 1 , 2 , 4 } ; int N = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; int arr2 [ ] = { 1 , 3 , 4 } ; int M = sizeof ( arr2 ) / sizeof ( arr2 [ 0 ] ) ; cout << largestArea ( arr1 , N , arr2 , M ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int count_pairs ( int arr [ ] , int brr [ ] , int N , int M , int K ) { int i = 0 ; int j = 0 ; int cntPairs = 0 ; sort ( arr , arr + N ) ; sort ( brr , brr + M ) ; while ( i < N && j < M ) { if ( brr [ j ] - arr [ i ] > K ) { cntPairs += ( M - j ) ; i ++ ; } else { j ++ ; } } return cntPairs ; } int main ( ) { int arr [ ] = { 5 , 9 , 1 , 8 } ; int brr [ ] = { 10 , 12 , 7 , 4 , 2 , 3 } ; int K = 3 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int M = sizeof ( brr ) / sizeof ( brr [ 0 ] ) ; cout << count_pairs ( arr , brr , N , M , K ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: cntPairs, i, j, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void minHeapify ( int brr [ ] , int i , int M ) { int left = 2 * i + 1 ; int right = 2 * i + 2 ; int smallest = i ; if ( left < M && brr [ left ] < brr [ smallest ] ) { smallest = left ; } if ( right < M && brr [ right ] < brr [ smallest ] ) { smallest = right ; } if ( smallest != i ) { swap ( brr [ i ] , brr [ smallest ] ) ; minHeapify ( brr , smallest , M ) ; } } void merge ( int arr [ ] , int brr [ ] , int N , int M ) { for ( int i = 0 ; i < N ; ++ i ) { if ( arr [ i ] > brr [ 0 ] ) { swap ( arr [ i ] , brr [ 0 ] ) ; minHeapify ( brr , 0 , M ) ; } } sort ( brr , brr + M ) ; } void printArray ( int arr [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) cout << arr [ i ] << " ▁ " ; } int main ( ) { int arr [ ] = { 2 , 23 , 35 , 235 , 2335 } ; int brr [ ] = { 3 , 5 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int M = sizeof ( brr ) / sizeof ( brr [ 0 ] ) ; merge ( arr , brr , N , M ) ; printArray ( arr , N ) ; printArray ( brr , M ) ; return 0 ; }

Index/key variables: i, left, right, smallest
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void partition ( int arr [ ] , int N , int brr [ ] , int M , int Pivot ) { int l = N - 1 ; int r = 0 ; while ( l >= 0 && r < M ) { if ( arr [ l ] < Pivot ) l -- ; else if ( brr [ r ] > Pivot ) r ++ ; else { swap ( arr [ l ] , brr [ r ] ) ; l -- ; r ++ ; } } } void Merge ( int arr [ ] , int N , int brr [ ] , int M ) { int l = 0 ; int r = 0 ; int index = -1 ; int Pivot = 0 ; while ( index < N && l < N && r < M ) { if ( arr [ l ] < brr [ r ] ) { Pivot = arr [ l ++ ] ; } else { Pivot = brr [ r ++ ] ; } index ++ ; } while ( index < N && l < N ) { Pivot = arr [ l ++ ] ; index ++ ; } while ( index < N && r < M ) { Pivot = brr [ r ++ ] ; index ++ ; } partition ( arr , N , brr , M , Pivot ) ; sort ( arr , arr + N ) ; sort ( brr , brr + M ) ; for ( int i = 0 ; i < N ; i ++ ) cout << arr [ i ] << " ▁ " ; for ( int i = 0 ; i < M ; i ++ ) cout << brr [ i ] << " ▁ " ; } int main ( ) { int arr [ ] = { 1 , 5 , 9 } ; int brr [ ] = { 2 , 4 , 7 , 10 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int M = sizeof ( brr ) / sizeof ( brr [ 0 ] ) ; Merge ( arr , N , brr , M ) ; return 0 ; }

Index/key variables: i, l, r
Accumulator variables: i, index, l, r, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int rankLessThanK ( int * arr , int k , int n ) { int rank = 1 ; int position = 1 ; sort ( arr , arr + n ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( i == n - 1 arr [ i ] != arr [ i + 1 ] ) { rank = position ; if ( rank > k ) return position - 1 ; } position ++ ; } return n ; } int main ( ) { int arr [ 5 ] = { 2 , 2 , 3 , 4 , 5 } ; int N = 5 ; int K = 4 ; cout << rankLessThanK ( arr , K , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, position, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void eraseSubdirectory ( vector < string > & dir ) { vector < string > res ; sort ( dir . begin ( ) , dir . end ( ) ) ; res . push_back ( dir [ 0 ] ) ; cout << " { " << dir [ 0 ] << " , ▁ " ; for ( int i = 1 ; i < dir . size ( ) ; i ++ ) { string curr = dir [ i ] ; string prev = res . back ( ) ; int l = prev . length ( ) ; if ( curr . length ( ) > l && curr [ l ] == ' / ' && prev == curr . substr ( 0 , l ) ) continue ; res . push_back ( curr ) ; cout << curr << " , ▁ " ; } cout << " } STRNEWLINE " ; } int main ( ) { vector < string > dir = { " / a " , " / a / j " , " / c / d / e " , " / c / d " , " / b " } ; eraseSubdirectory ( dir ) ; return 0 ; }

Index/key variables: i, l
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int numberOfPairs ( int arr1 [ ] , int n , int arr2 [ ] , int m ) { priority_queue < int > pq ; int i , j ; sort ( arr1 , arr1 + n ) ; for ( j = 0 ; j < m ; j ++ ) { pq . push ( arr2 [ j ] ) ; } int ans = 0 ; for ( i = n - 1 ; i >= 0 ; i -- ) { if ( pq . top ( ) >= 2 * arr1 [ i ] ) { ans ++ ; pq . pop ( ) ; } } return ans ; } int main ( ) { int arr1 [ ] = { 3 , 1 , 2 } ; int arr2 [ ] = { 3 , 4 , 2 , 1 } ; int N = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; int M = sizeof ( arr2 ) / sizeof ( arr2 [ 0 ] ) ; cout << numberOfPairs ( arr1 , N , arr2 , M ) ; 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 ; void minCost ( int arr [ ] , int n ) { if ( n == 1 ) { cout << 0 << endl ; return ; } sort ( arr , arr + n ) ; float raised = 1 / float ( n - 1 ) ; float temp = pow ( arr [ n - 1 ] , raised ) ; int r = round ( temp ) + 1 ; int i , j , min_cost = INT_MAX ; int common_ratio = 1 ; for ( j = 1 ; j <= r ; j ++ ) { int curr_cost = 0 , prod = 1 ; for ( i = 0 ; i < n ; i ++ ) { curr_cost += abs ( arr [ i ] - prod ) ; prod *= j ; if ( curr_cost >= min_cost ) break ; } if ( i == n ) { min_cost = min ( min_cost , curr_cost ) ; common_ratio = j ; } } cout << min_cost << ' ▁ ' ; cout << common_ratio << ' ▁ ' ; } int main ( ) { int N = 6 ; int arr [ ] = { 1 , 11 , 4 , 27 , 15 , 33 } ; minCost ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: curr_cost, i, j, prod, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define maxN  10
void calculateFib ( int fib [ ] , int n ) { fib [ 0 ] = fib [ 1 ] = 1 ; for ( int x = 2 ; x < n ; x ++ ) { fib [ x ] = fib [ x - 1 ] + fib [ x - 2 ] ; } } int find_mth_bit ( int n , int m , int fib [ ] ) { if ( n <= 1 ) { return n ; } int len_left = fib [ n - 2 ] ; int len_right = fib [ n - 1 ] ; if ( m <= len_left ) { return find_mth_bit ( n - 2 , len_left + 1 - m , fib ) ; } else { return find_mth_bit ( n - 1 , len_right + 1 - ( m - len_left ) , fib ) ; } } void find_mth_bitUtil ( int n , int m ) { int fib [ maxN ] ; calculateFib ( fib , maxN ) ; int ans = find_mth_bit ( n , m , fib ) ; cout << ans << ' ▁ ' ; } int main ( ) { int n = 5 , m = 3 ; find_mth_bitUtil ( n , m ) ; return 0 ; }

Index/key variables: maxN, x
Accumulator variables: stdc, x
Iterator variables: x
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minAdjSwaps ( vector < vector < int > > & mat ) { int N = mat . size ( ) ; vector < int > cntZero ( N , 0 ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = N - 1 ; j >= 0 && mat [ i ] [ j ] == 0 ; j -- ) { cntZero [ i ] ++ ; } } int cntSwaps = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( cntZero [ i ] < ( N - i - 1 ) ) { int First = i ; while ( First < N && cntZero [ First ] < ( N - i - 1 ) ) { First ++ ; } if ( First == N ) { return -1 ; } while ( First > i ) { swap ( cntZero [ First ] , cntZero [ First - 1 ] ) ; First -- ; cntSwaps ++ ; } } } return cntSwaps ; } int main ( ) { vector < vector < int > > mat = { { 0 , 0 , 2 } , { 3 , 1 , 0 } , { 4 , 0 , 0 } } ; cout << minAdjSwaps ( mat ) ; }

Index/key variables: First, i, j
Accumulator variables: First, cntSwaps, i, j, stdc
Iterator variables: i, j