dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isPossible ( int arr [ ] , int n , int m , int curr_min ) { int studentsRequired = 1 ; int curr_sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > curr_min ) return false ; if ( curr_sum + arr [ i ] > curr_min ) { studentsRequired ++ ; curr_sum = arr [ i ] ; if ( studentsRequired > m ) return false ; } else curr_sum += arr [ i ] ; } return true ; } int findPages ( int arr [ ] , int n , int m ) { long long sum = 0 ; if ( n < m ) return -1 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; int start = 0 , end = sum ; int result = INT_MAX ; while ( start <= end ) { int mid = ( start + end ) / 2 ; if ( isPossible ( arr , n , m , mid ) ) { result = mid ; end = mid - 1 ; } else start = mid + 1 ; } return result ; } int main ( ) { int arr [ ] = { 12 , 34 , 67 , 90 } ; int n = sizeof arr / sizeof arr [ 0 ] ; cout << " Minimum ▁ number ▁ of ▁ pages ▁ = ▁ " << findPages ( arr , n , m ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: curr_sum, i, stdc, studentsRequired, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool comp ( vector < int > v1 , vector < int > v2 ) { return v1 [ 0 ] * v1 [ 1 ] > v2 [ 0 ] * v2 [ 1 ] ; } int countPlates ( vector < vector < int > > & plates , int lastLength , int lastWidth , int i , int n ) { if ( i == n ) return 0 ; int taken = 0 , notTaken = 0 ; if ( lastLength > plates [ i ] [ 0 ] && lastWidth > plates [ i ] [ 1 ] ) { taken = 1 + countPlates ( plates , plates [ i ] [ 0 ] , plates [ i ] [ 1 ] , i + 1 , n ) ; notTaken = countPlates ( plates , lastLength , lastWidth , i + 1 , n ) ; } else notTaken = countPlates ( plates , lastLength , lastWidth , i + 1 , n ) ; return max ( taken , notTaken ) ; } int main ( ) { vector < vector < int > > plates = { { 6 , 4 } , { 5 , 7 } , { 1 , 2 } , { 3 , 3 } , { 7 , 9 } } ; int n = plates . size ( ) ; sort ( plates . begin ( ) , plates . end ( ) , comp ) ; int lastLength = INT_MAX ; int lastWidth = INT_MAX ; cout << countPlates ( plates , lastLength , lastWidth , 0 , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool comp ( pair < int , int > & a , pair < int , int > & b ) { if ( a . second != b . second ) return a . second > b . second ; return a . first < b . first ; } int maximizeSum ( int arr [ ] , int n , int k ) { vector < int > cnt ( 30 , 0 ) ; int X = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < 30 ; j ++ ) { if ( arr [ i ] & ( 1 << j ) ) cnt [ j ] ++ ; } } vector < pair < int , int > > v ; for ( int i = 0 ; i < 30 ; i ++ ) { int gain = cnt [ i ] * ( 1 << i ) ; v . push_back ( { i , gain } ) ; } sort ( v . begin ( ) , v . end ( ) , comp ) ; for ( int i = 0 ; i < k ; i ++ ) { X |= ( 1 << v [ i ] . first ) ; } cout << X ; } int main ( ) { int arr [ ] = { 3 , 4 , 5 , 1 } ; int K = 1 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; maximizeSum ( arr , N , K ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: X, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int charVal ( char c ) { if ( c == ' I ' ) return 1 ; if ( c == ' V ' ) return 5 ; if ( c == ' X ' ) return 10 ; if ( c == ' L ' ) return 50 ; if ( c == ' C ' ) return 100 ; if ( c == ' D ' ) return 500 ; if ( c == ' M ' ) return 1000 ; return -1 ; } int romanToDec ( string S ) { int res = 0 ; int n = S . size ( ) ; res = charVal ( S [ n - 1 ] ) ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( charVal ( S [ i ] ) < charVal ( S [ i + 1 ] ) ) res -= charVal ( S [ i ] ) ; else res += charVal ( S [ i ] ) ; } return res ; } string DecToRoman ( int number ) { string res = " " ; int num [ ] = { 1 , 4 , 5 , 9 , 10 , 40 , 50 , 90 , 100 , 400 , 500 , 900 , 1000 } ; string sym [ ] = { " I " , " IV " , " V " , " IX " , " X " , " XL " , " L " , " XC " , " C " , " CD " , " D " , " CM " , " M " } ; int i = 12 ; while ( number > 0 ) { int div = number / num [ i ] ; number = number % num [ i ] ; while ( div -- ) { res += sym [ i ] ; } i -- ; } return res ; } bool compare ( char x , char y ) { int val_x = charVal ( x ) ; int val_y = charVal ( y ) ; return ( val_x > val_y ) ; } string findLargest ( string S ) { set < char > st = { ' I ' , ' V ' , ' X ' , ' L ' , ' C ' , ' D ' , ' M ' } ; for ( auto x : S ) { if ( st . find ( x ) == st . end ( ) ) return " Invalid " ; } sort ( S . begin ( ) , S . end ( ) , compare ) ; int N = romanToDec ( S ) ; string R = DecToRoman ( N ) ; if ( S != R ) return " Invalid " ; return S ; } int main ( ) { string S = " MCMIV " ; cout << findLargest ( S ) ; }

Index/key variables: i
Accumulator variables: div, i, res, stdc
Iterator variables: i, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; int minDepth ( Node * root ) { if ( root == NULL ) return 0 ; if ( root -> left == NULL && root -> right == NULL ) return 1 ; int l = INT_MAX , r = INT_MAX ; if ( root -> left ) l = minDepth ( root -> left ) ; if ( root -> right ) r = minDepth ( root -> right ) ; return min ( l , r ) + 1 ; } Node * newNode ( int data ) { Node * temp = new Node ; temp -> data = data ; temp -> left = temp -> right = NULL ; return ( temp ) ; } int main ( ) { Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; cout << " The ▁ minimum ▁ depth ▁ of ▁ binary ▁ tree ▁ is ▁ : ▁ " << minDepth ( root ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void maxFreqElements ( int arr [ ] , int N , int K ) { map < int , int > mp ; for ( int i = 0 ; i < N ; i ++ ) { mp [ arr [ i ] ] ++ ; } while ( K > 0 ) { int max = 0 ; int element ; for ( auto i : mp ) { if ( i . second > max ) { max = i . second ; element = i . first ; } } cout << element << " ▁ " ; mp [ element ] -- ; K -- ; } } int main ( ) { int arr [ ] = { 1 , 3 , 2 , 1 , 4 , 1 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 2 ; maxFreqElements ( arr , N , K ) ; return 0 ; }

Index/key variables: element, i
Accumulator variables: K, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxDiffLargSmallOper ( int arr [ ] , int N , int K ) { int maxDiff = 0 ; sort ( arr , arr + N , greater < int > ( ) ) ; for ( int i = 0 ; i <= min ( K , N - 1 ) ; i ++ ) { maxDiff += arr [ i ] ; } return maxDiff ; } int main ( ) { int arr [ ] = { 7 , 7 , 7 , 7 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 1 ; cout << maxDiffLargSmallOper ( arr , N , K ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, maxDiff, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minCost ( string str , int N , int R [ ] , int C [ ] ) { priority_queue < int , vector < int > , greater < int > > pq ; int flip = 0 ; int cost = 0 ; for ( int i = 0 ; i < N ; i ++ ) { while ( pq . size ( ) > 0 and pq . top ( ) < i ) { pq . pop ( ) ; flip -- ; } if ( flip % 2 == 1 ) { str [ i ] = '1' - str [ i ] + '0' ; } if ( str [ i ] == '1' ) { flip ++ ; cost += C [ i ] ; pq . push ( R [ i ] ) ; } } return cost ; } int main ( ) { string str = "1010" ; int R [ ] = { 1 , 2 , 2 , 3 } ; int C [ ] = { 3 , 1 , 2 , 3 } ; int N = str . length ( ) ; cout << minCost ( str , N , R , C ) ; }

Index/key variables: i
Accumulator variables: cost, flip, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; struct qItem { Node * node ; int depth ; } ; int minDepth ( Node * root ) { if ( root == NULL ) return 0 ; queue < qItem > q ; qItem qi = { root , 1 } ; q . push ( qi ) ; while ( q . empty ( ) == false ) { qi = q . front ( ) ; q . pop ( ) ; Node * node = qi . node ; int depth = qi . depth ; if ( node -> left == NULL && node -> right == NULL ) return depth ; if ( node -> left != NULL ) { qi . node = node -> left ; qi . depth = depth + 1 ; q . push ( qi ) ; } if ( node -> right != NULL ) { qi . node = node -> right ; qi . depth = depth + 1 ; q . push ( qi ) ; } } return 0 ; } Node * newNode ( int data ) { Node * temp = new Node ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } int main ( ) { Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; cout << minDepth ( root ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node, qItem
C++ program:
#include <bits/stdc++.h>
using namespace std ; void MaxDist ( vector < pair < int , int > > & A , int N ) { vector < int > V ( N ) , V1 ( N ) ; for ( int i = 0 ; i < N ; i ++ ) { V [ i ] = A [ i ] . first + A [ i ] . second ; V1 [ i ] = A [ i ] . first - A [ i ] . second ; } sort ( V . begin ( ) , V . end ( ) ) ; sort ( V1 . begin ( ) , V1 . end ( ) ) ; int maximum = max ( V . back ( ) - V . front ( ) , V1 . back ( ) - V1 . front ( ) ) ; cout << maximum << endl ; } int main ( ) { int N = 3 ; vector < pair < int , int > > A = { { 1 , 2 } , { 2 , 3 } , { 3 , 4 } } ; MaxDist ( A , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; long dist ( pair < long , long > p1 , pair < long , long > p2 ) { long x0 = p1 . first - p2 . first ; long y0 = p1 . second - p2 . second ; return x0 * x0 + y0 * y0 ; } double maxDist ( pair < long , long > p [ ] , int n ) { double Max = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { Max = max ( Max , ( double ) dist ( p [ i ] , p [ j ] ) ) ; } } return sqrt ( Max ) ; } int main ( ) { int n = 5 ; pair < long , long > p [ n ] ; p [ 0 ] . first = 4 , p [ 0 ] . second = 0 ; p [ 1 ] . first = 0 , p [ 1 ] . second = 2 ; p [ 2 ] . first = -1 , p [ 2 ] . second = -7 ; p [ 3 ] . first = 1 , p [ 3 ] . second = 10 ; p [ 4 ] . first = 2 , p [ 4 ] . second = -3 ; cout << fixed << setprecision ( 14 ) << maxDist ( p , n ) << endl ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printArr ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; if ( arr [ 0 ] == arr [ n - 1 ] ) { cout << " No " << endl ; } else { cout << " Yes " << endl ; for ( int i = 0 ; i < n ; i ++ ) { cout << arr [ i ] << " ▁ " ; } } } int main ( ) { int arr [ ] = { 1 , 2 , 2 , 1 , 3 , 1 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; printArr ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <iostream>
#include <math.h>
using namespace std ; struct Node { int data ; struct Node * left ; struct Node * right ; Node ( int k ) { data = k ; left = right = NULL ; } } ; int minimumDepth ( Node * root , int level ) { if ( root == NULL ) return level ; level ++ ; return min ( minimumDepth ( root -> left , level ) , minimumDepth ( root -> right , level ) ) ; } int main ( ) { Node * root = new Node ( 1 ) ; root -> left = new Node ( 2 ) ; root -> right = new Node ( 3 ) ; root -> left -> left = new Node ( 4 ) ; root -> left -> right = new Node ( 5 ) ; cout << minimumDepth ( root , 0 ) ; return 0 ; }

Accumulator variables: level
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void maximumSum ( int a [ ] , int b [ ] , int k , int n ) { int i , j ; sort ( a , a + n ) ; sort ( b , b + n ) ; for ( i = 0 , j = n - 1 ; i < k ; i ++ , j -- ) { if ( a [ i ] < b [ j ] ) swap ( a [ i ] , b [ j ] ) ; else break ; } int sum = 0 ; for ( i = 0 ; i < n ; i ++ ) sum += a [ i ] ; cout << sum << endl ; } int main ( ) { int K = 1 ; int A [ ] = { 2 , 3 , 4 } ; int B [ ] = { 6 , 8 , 5 } ; int N = sizeof ( A ) / sizeof ( A [ 0 ] ) ; maximumSum ( A , B , K , N ) ; return 0 ; }

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

Index/key variables: i
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void CheckSort ( vector < int > arr , int k , int n ) { vector < int > sortarr ( arr . begin ( ) , arr . end ( ) ) ; sort ( sortarr . begin ( ) , sortarr . end ( ) ) ; if ( k == 1 ) printf ( " yes " ) ; else { int flag = 0 ; for ( int i = 0 ; i < n ; i ++ ) { flag = 0 ; for ( int j = i ; j < n ; j += k ) { if ( sortarr [ i ] == arr [ j ] ) { swap ( arr [ i ] , arr [ j ] ) ; flag = 1 ; break ; } if ( j + k >= n ) break ; } if ( flag == 0 ) break ; } if ( flag == 0 ) printf ( " Not ▁ possible ▁ to ▁ sort " ) ; else printf ( " Possible ▁ to ▁ sort " ) ; } } int main ( ) { int k = 3 ; vector < int > arr = { 1 , 5 , 6 , 9 , 2 , 3 , 5 , 9 } ; int n = arr . size ( ) ; CheckSort ( arr , k , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; struct Node * newNode ( int data ) { Node * temp = new Node ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } void replaceNode ( struct Node * node , int level = 0 ) { if ( node == NULL ) return ; node -> data = level ; replaceNode ( node -> left , level + 1 ) ; replaceNode ( node -> right , level + 1 ) ; } void printInorder ( struct Node * node ) { if ( node == NULL ) return ; printInorder ( node -> left ) ; cout << node -> data << " ▁ " ; printInorder ( node -> right ) ; } int main ( ) { struct Node * root = new struct Node ; root = newNode ( 3 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 5 ) ; root -> left -> left = newNode ( 1 ) ; root -> left -> right = newNode ( 4 ) ; cout << " Before ▁ Replacing ▁ Nodes STRNEWLINE " ; printInorder ( root ) ; replaceNode ( root ) ; cout << endl ; cout << " After ▁ Replacing ▁ Nodes STRNEWLINE " ; printInorder ( root ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define mod  1000000007
int power ( int x , unsigned int y , int p ) { int res = 1 ; x = x % p ; while ( y > 0 ) { if ( y & 1 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } int size [ 300005 ] ; int freq [ 300004 ] ; vector < pair < int , pair < int , int > > > edges ; void initialize ( int Arr [ ] , int N ) { for ( int i = 0 ; i < N ; i ++ ) { Arr [ i ] = i ; size [ i ] = 1 ; } } int root ( int Arr [ ] , int i ) { while ( Arr [ i ] != i ) { i = Arr [ i ] ; } return i ; } void weighted_union ( int Arr [ ] , int size [ ] , int A , int B ) { int root_A = root ( Arr , A ) ; int root_B = root ( Arr , B ) ; if ( size [ root_A ] < size [ root_B ] ) { Arr [ root_A ] = Arr [ root_B ] ; size [ root_B ] += size [ root_A ] ; } else { Arr [ root_B ] = Arr [ root_A ] ; size [ root_A ] += size [ root_B ] ; } } void AddEdge ( int a , int b , int w ) { edges . push_back ( { w , { a , b } } ) ; } void MakeTree ( ) { AddEdge ( 1 , 2 , 1 ) ; AddEdge ( 1 , 3 , 3 ) ; AddEdge ( 3 , 4 , 2 ) ; } int MinProduct ( ) { int result = 1 ; sort ( edges . begin ( ) , edges . end ( ) ) ; for ( int i = edges . size ( ) - 1 ; i >= 0 ; i -- ) { int curr_weight = edges [ i ] . first ; int Node1 = edges [ i ] . second . first ; int Node2 = edges [ i ] . second . second ; int Root1 = root ( freq , Node1 ) ; int Set1_size = size [ Root1 ] ; int Root2 = root ( freq , Node2 ) ; int Set2_size = size [ Root2 ] ; int prod = Set1_size * Set2_size ; int Product = power ( curr_weight , prod , mod ) ; result = ( ( result % mod ) * ( Product % mod ) ) % mod ; weighted_union ( freq , size , Node1 , Node2 ) ; } return result % mod ; } int main ( ) { int n = 4 ; initialize ( freq , n ) ; MakeTree ( ) ; cout << MinProduct ( ) ; }

Index/key variables: Root1, Root2, i, root_A, root_B
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; bool check ( int * arr , int n ) { int modify = 0 ; if ( arr [ n - 1 ] >= arr [ n - 2 ] ) { arr [ n - 1 ] = arr [ n - 2 ] - 1 ; modify ++ ; } if ( arr [ 0 ] <= arr [ 1 ] ) { arr [ 0 ] = arr [ 1 ] + 1 ; modify ++ ; } for ( int i = n - 2 ; i > 0 ; i -- ) { if ( ( arr [ i - 1 ] <= arr [ i ] && arr [ i + 1 ] <= arr [ i ] ) || ( arr [ i - 1 ] >= arr [ i ] && arr [ i + 1 ] >= arr [ i ] ) ) { arr [ i ] = ( arr [ i - 1 ] + arr [ i + 1 ] ) / 2 ; modify ++ ; if ( arr [ i ] == arr [ i - 1 ] arr [ i ] == arr [ i + 1 ] ) return false ; } } if ( modify > 1 ) return false ; return true ; } int main ( ) { int arr [ ] = { 10 , 5 , 11 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; if ( check ( arr , n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, modify
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define ll  long long int
bool sortbysec ( const pair < int , int > & a , const pair < int , int > & b ) { return ( a . second < b . second ) ; } void maxDisjointIntervals ( vector < pair < int , int > > list ) { sort ( list . begin ( ) , list . end ( ) , sortbysec ) ; cout << " [ " << list [ 0 ] . first << " , ▁ " << list [ 0 ] . second << " ] " << endl ; int r1 = list [ 0 ] . second ; for ( int i = 1 ; i < list . size ( ) ; i ++ ) { int l1 = list [ i ] . first ; int r2 = list [ i ] . second ; if ( l1 > r1 ) { cout << " [ " << l1 << " , ▁ " << r2 << " ] " << endl ; r1 = r2 ; } } } int main ( ) { int N = 4 ; vector < pair < int , int > > intervals = { { 1 , 4 } , { 2 , 3 } , { 4 , 6 } , { 8 , 9 } } ; maxDisjointIntervals ( intervals ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int next_pos = 1 ; void printIndices ( int n , pair < int , int > a [ ] ) { for ( int i = 0 ; i < n ; i ++ ) cout << a [ i ] . second << " ▁ " ; cout << endl ; } void printPermutations ( int n , int a [ ] , int k ) { pair < int , int > arr [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] . first = a [ i ] ; arr [ i ] . second = i ; } sort ( arr , arr + n ) ; int count = 1 ; for ( int i = 1 ; i < n ; i ++ ) if ( arr [ i ] . first == arr [ i - 1 ] . first ) count ++ ; if ( count < k ) { cout << " - 1" ; return ; } for ( int i = 0 ; i < k - 1 ; i ++ ) { printIndices ( n , arr ) ; for ( int j = next_pos ; j < n ; j ++ ) { if ( arr [ j ] . first == arr [ j - 1 ] . first ) { swap ( arr [ j ] , arr [ j - 1 ] ) ; next_pos = j + 1 ; break ; } } } printIndices ( n , arr ) ; } int main ( ) { int a [ ] = { 1 , 3 , 3 , 1 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; int k = 3 ; printPermutations ( n , a , k ) ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: count, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; class node { public : int data ; node * left ; node * right ; } ; int getWidth ( node * root , int level ) ; int height ( node * node ) ; node * newNode ( int data ) ; int getMaxWidth ( node * root ) { int maxWidth = 0 ; int width ; int h = height ( root ) ; int i ; for ( i = 1 ; i <= h ; i ++ ) { width = getWidth ( root , i ) ; if ( width > maxWidth ) maxWidth = width ; } return maxWidth ; } int getWidth ( node * root , int level ) { if ( root == NULL ) return 0 ; if ( level == 1 ) return 1 ; else if ( level > 1 ) return getWidth ( root -> left , level - 1 ) + getWidth ( root -> right , level - 1 ) ; } int height ( node * node ) { if ( node == NULL ) return 0 ; else { int lHeight = height ( node -> left ) ; int rHeight = height ( node -> right ) ; return ( lHeight > rHeight ) ? ( lHeight + 1 ) : ( rHeight + 1 ) ; } } node * newNode ( int data ) { node * Node = new node ( ) ; Node -> data = data ; Node -> left = NULL ; Node -> right = NULL ; return ( Node ) ; } int main ( ) { node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; root -> right -> right = newNode ( 8 ) ; root -> right -> right -> left = newNode ( 6 ) ; root -> right -> right -> right = newNode ( 7 ) ; cout << " Maximum ▁ width ▁ is ▁ " << getMaxWidth ( root ) << endl ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
Class/struct names: node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printAnswer ( vector < pair < int , int > > v , int n ) { vector < pair < int , pair < int , int > > > vec ; for ( int i = 0 ; i < n ; i ++ ) { vec . push_back ( { v [ i ] . first , { v [ i ] . second , i } } ) ; } sort ( vec . begin ( ) , vec . end ( ) ) ; vector < int > res ( n , 2 ) ; int maxR = vec [ 0 ] . second . first ; res [ vec [ 0 ] . second . second ] = 1 ; bool ok = false ; for ( int i = 1 ; i < n ; i ++ ) { if ( maxR >= vec [ i ] . first ) { res [ vec [ i ] . second . second ] = res [ vec [ i - 1 ] . second . second ] ; maxR = max ( maxR , vec [ i ] . second . first ) ; } else { ok = true ; break ; } } if ( ok ) { for ( auto x : res ) cout << x << " ▁ " ; cout << ' ' ; } else cout << " Not ▁ possible STRNEWLINE " ; } int main ( ) { vector < pair < int , int > > v = { { 2 , 8 } , { 3 , 4 } , { 5 , 8 } , { 9 , 10 } } ; int n = ( int ) v . size ( ) ; printAnswer ( v , n ) ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i, x
Boolean variables: ok
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countDistinct ( int arr [ ] , int n ) { unordered_set < int > s ; int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . find ( arr [ i ] ) == s . end ( ) ) { s . insert ( arr [ i ] ) ; res ++ ; } } return res ; } int main ( ) { int arr [ ] = { 6 , 10 , 5 , 4 , 9 , 120 , 4 , 6 , 10 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countDistinct ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, res, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int nextGap ( int gap ) { if ( gap <= 1 ) return 0 ; return ( int ) ceil ( gap / 2.0 ) ; } void swap ( int nums [ ] , int i , int j ) { int temp = nums [ i ] ; nums [ i ] = nums [ j ] ; nums [ j ] = temp ; } void inPlaceMerge ( int nums [ ] , int start , int end ) { int gap = end - start + 1 ; for ( gap = nextGap ( gap ) ; gap > 0 ; gap = nextGap ( gap ) ) { for ( int i = start ; i + gap <= end ; i ++ ) { int j = i + gap ; if ( nums [ i ] > nums [ j ] ) swap ( nums , i , j ) ; } } } void mergeSort ( int nums [ ] , int s , int e ) { if ( s == e ) return ; int mid = ( s + e ) / 2 ; mergeSort ( nums , s , mid ) ; mergeSort ( nums , mid + 1 , e ) ; inPlaceMerge ( nums , s , e ) ; } int main ( ) { int nums [ ] = { 12 , 11 , 13 , 5 , 6 , 7 } ; int nums_size = sizeof ( nums ) / sizeof ( nums [ 0 ] ) ; mergeSort ( nums , 0 , nums_size - 1 ) ; for ( int i = 0 ; i < nums_size ; i ++ ) { cout << nums [ i ] << " ▁ " ; } return 0 ; }

Index/key variables: i, j
Accumulator variables: i, stdc
Iterator variables: gap, i
C++ program:
#include <bits/stdc++.h>
#include <iostream>
using namespace std ; static int findOptimalSolution ( int a [ ] , int N ) { sort ( a , a + N ) ; int points = 0 ; for ( int i = 0 ; i < N ; i ++ ) { points += a [ i ] * i ; } return points ; } int main ( ) { int a [ ] = { 1 , 4 , 2 , 3 , 9 } ; int N = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << ( findOptimalSolution ( a , N ) ) ; return 0 ; }

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