dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > parent , size ; int find_set ( int v ) { if ( v == parent [ v ] ) return v ; return parent [ v ] = find_set ( parent [ v ] ) ; } int union_sets ( int a , int b ) { a = find_set ( a ) ; b = find_set ( b ) ; if ( a != b ) { if ( size [ a ] < size [ b ] ) swap ( a , b ) ; parent [ b ] = a ; size [ a ] += size [ b ] ; return 1 ; } return 0 ; } void MST ( int houses [ ] [ 2 ] , int n ) { vector < pair < int , pair < int , int > > > v ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { int p = abs ( houses [ i ] [ 0 ] - houses [ j ] [ 0 ] ) ; p += abs ( houses [ i ] [ 1 ] - houses [ j ] [ 1 ] ) ; v . push_back ( { p , { i , j } } ) ; } } parent . resize ( n ) ; size . resize ( n ) ; sort ( v . begin ( ) , v . end ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) { parent [ i ] = i , size [ i ] = 1 ; } int ans = 0 ; for ( auto x : v ) { if ( union_sets ( x . second . first , x . second . second ) ) { ans += x . first ; } } cout << ans ; } int main ( ) { int houses [ ] [ 2 ] = { { 0 , 0 } , { 2 , 2 } , { 3 , 10 } , { 5 , 2 } , { 7 , 0 } } ; int N = sizeof ( houses ) / sizeof ( houses [ 0 ] ) ; MST ( houses , N ) ; return 0 ; }

Index/key variables: a, b, i, j, v
Accumulator variables: ans, i, j, p, stdc
Iterator variables: i, j, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; void firstSubsequence ( string s ) { int isMax = -1 ; for ( int i = 0 ; i < s . length ( ) - 1 ; i ++ ) { if ( s [ i ] > s [ i + 1 ] ) { isMax = i ; break ; } } if ( isMax >= 0 ) { s . erase ( isMax , 1 ) ; } else { s . erase ( s . length ( ) - 1 , 1 ) ; } cout << s ; } int main ( ) { string S = " geeksforgeeks " ; firstSubsequence ( S ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int largeProduct ( vector < int > A , vector < int > B , int N ) { if ( N == 0 ) return 0 ; priority_queue < int , vector < int > , greater < int > > pq ; for ( int i = 0 ; i < N ; i ++ ) pq . push ( A [ i ] ) ; sort ( B . begin ( ) , B . end ( ) ) ; for ( int i = 0 ; i < N ; i ++ ) { int minn = pq . top ( ) ; pq . pop ( ) ; int maximized_element = max ( minn * B [ i ] , minn + B [ i ] ) ; pq . push ( maximized_element ) ; } int max_product = 1 ; while ( pq . size ( ) > 0 ) { max_product *= pq . top ( ) ; pq . pop ( ) ; } return max_product ; } int main ( ) { vector < int > A = { 1 , 1 , 10 } ; vector < int > B = { 1 , 1 , 1 } ; int N = 3 ; cout << largeProduct ( A , B , N ) ; }

Index/key variables: i
Accumulator variables: i, max_product, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX_PATH_SIZE  1000
struct Node { char data ; Node * left , * right ; } ; Node * newNode ( char data ) { struct Node * temp = new Node ; temp -> data = data ; temp -> left = temp -> right = NULL ; return temp ; } struct PATH { int Hd ; char key ; } ; void printPath ( vector < PATH > path , int size ) { int minimum_Hd = INT_MAX ; PATH p ; for ( int it = 0 ; it < size ; it ++ ) { p = path [ it ] ; minimum_Hd = min ( minimum_Hd , p . Hd ) ; } for ( int it = 0 ; it < size ; it ++ ) { p = path [ it ] ; int noOfUnderScores = abs ( p . Hd - minimum_Hd ) ; for ( int i = 0 ; i < noOfUnderScores ; i ++ ) cout << " _ ▁ " ; cout << p . key << endl ; } cout << " = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = " << endl ; } void printAllPathsUtil ( Node * root , vector < PATH > & AllPath , int HD , int order ) { if ( root == NULL ) return ; if ( root -> left == NULL && root -> right == NULL ) { AllPath [ order ] = ( PATH { HD , root -> data } ) ; printPath ( AllPath , order + 1 ) ; return ; } AllPath [ order ] = ( PATH { HD , root -> data } ) ; printAllPathsUtil ( root -> left , AllPath , HD - 1 , order + 1 ) ; printAllPathsUtil ( root -> right , AllPath , HD + 1 , order + 1 ) ; } void printAllPaths ( Node * root ) { if ( root == NULL ) return ; vector < PATH > Allpaths ( MAX_PATH_SIZE ) ; printAllPathsUtil ( root , Allpaths , 0 , 0 ) ; } int main ( ) { Node * root = newNode ( ' A ' ) ; root -> left = newNode ( ' B ' ) ; root -> right = newNode ( ' C ' ) ; root -> left -> left = newNode ( ' D ' ) ; root -> left -> right = newNode ( ' E ' ) ; root -> right -> left = newNode ( ' F ' ) ; root -> right -> right = newNode ( ' G ' ) ; printAllPaths ( root ) ; return 0 ; }

Index/key variables: it, order
Accumulator variables: i, it, stdc
Iterator variables: i, it
Class/struct names: Node, PATH
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minsteps ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ans += abs ( arr [ i ] - pow ( 2 , i ) ) ; } return ans ; } int main ( ) { int arr [ ] = { 1 , 8 , 2 , 10 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << minsteps ( 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 printArray ( int arr [ ] , int size ) ; void swap ( int arr [ ] , int fi , int si , int d ) ; void leftRotate ( int arr [ ] , int d , int n ) { if ( d == 0 d == n ) return ; if ( n - d == d ) { swap ( arr , 0 , n - d , d ) ; return ; } if ( d < n - d ) { swap ( arr , 0 , n - d , d ) ; leftRotate ( arr , d , n - d ) ; } else { swap ( arr , 0 , d , n - d ) ; leftRotate ( arr + n - d , 2 * d - n , d ) ; } } void printArray ( int arr [ ] , int size ) { int i ; for ( i = 0 ; i < size ; i ++ ) cout << arr [ i ] << " ▁ " ; cout << endl ; } void swap ( int arr [ ] , int fi , int si , int d ) { int i , temp ; for ( i = 0 ; i < d ; i ++ ) { temp = arr [ fi + i ] ; arr [ fi + i ] = arr [ si + i ] ; arr [ si + i ] = temp ; } } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 } ; leftRotate ( arr , 2 , 7 ) ; printArray ( arr , 7 ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findCost ( int * a , int n ) { sort ( a , a + n , greater < int > ( ) ) ; int count = 0 ; for ( int j = 0 ; j < n ; j ++ ) { int p = a [ j ] - j ; a [ j ] = 0 ; if ( p < 0 ) { p = 0 ; continue ; } count += p ; } return count ; } int main ( ) { int arr [ ] = { 1 , 6 , 7 , 4 , 2 , 5 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findCost ( arr , N ) ; return 0 ; }

Index/key variables: j
Accumulator variables: count, j, stdc
Iterator variables: j
C++ program:
void leftRotate ( int arr [ ] , int d , int n ) { int i , j ; if ( d == 0 d == n ) return ; i = d ; j = n - d ; while ( i != j ) { if ( i < j ) { swap ( arr , d - i , d + j - i , i ) ; j -= i ; } else { swap ( arr , d - i , d , j ) ; i -= j ; } } swap ( arr , d - i , d , i ) ; }

Accumulator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countPairs ( int arr [ ] , int n ) { int ans = 0 ; unordered_map < int , int > count ; for ( int i = 0 ; i < n ; i ++ ) { if ( count [ arr [ i ] ] != 0 ) ans += count [ arr [ i ] ] ; count [ arr [ i ] ] ++ ; } return ans ; } int main ( ) { int arr [ ] = { 1 , 2 , 1 , 1 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countPairs ( arr , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int INF = 1e9 + 7 ; int N , M ; vector < int > edges [ 200005 ] ; int dist [ 2 ] [ 200000 ] ; void bfs ( int * dist , int s ) { int q [ 200000 ] ; fill ( dist , dist + N , INF ) ; int qh = 0 , qt = 0 ; q [ qh ++ ] = s ; dist [ s ] = 0 ; while ( qt < qh ) { int x = q [ qt ++ ] ; for ( int y : edges [ x ] ) { if ( dist [ y ] == INF ) { dist [ y ] = dist [ x ] + 1 ; q [ qh ++ ] = y ; } } } } void shortestPathCost ( int selected [ ] , int K ) { vector < pair < int , int > > data ; bfs ( dist [ 0 ] , 0 ) ; bfs ( dist [ 1 ] , N - 1 ) ; for ( int i = 0 ; i < K ; i ++ ) { data . emplace_back ( dist [ 0 ] [ selected [ i ] ] - dist [ 1 ] [ selected [ i ] ] , selected [ i ] ) ; } sort ( data . begin ( ) , data . end ( ) ) ; int best = 0 ; int MAX = - INF ; for ( auto it : data ) { int a = it . second ; best = max ( best , MAX + dist [ 1 ] [ a ] ) ; MAX = max ( MAX , dist [ 0 ] [ a ] ) ; } printf ( " % d STRNEWLINE " , min ( dist [ 0 ] [ N - 1 ] , best + 1 ) ) ; } int main ( ) { N = 5 , M = 4 ; int K = 2 ; int selected [ ] = { 1 , 3 } ; sort ( selected , selected + K ) ; edges [ 0 ] . push_back ( 1 ) ; edges [ 1 ] . push_back ( 0 ) ; edges [ 1 ] . push_back ( 2 ) ; edges [ 2 ] . push_back ( 1 ) ; edges [ 2 ] . push_back ( 3 ) ; edges [ 3 ] . push_back ( 2 ) ; edges [ 3 ] . push_back ( 4 ) ; edges [ 4 ] . push_back ( 3 ) ; shortestPathCost ( selected , K ) ; return 0 ; }

Index/key variables: a, i, s, x, y
Accumulator variables: i, qh, qt, stdc
Iterator variables: i, it, y
C++ program:
#include <iostream>
using namespace std ; void rotate ( int arr [ ] , int n ) { int i = 0 , j = n - 1 ; while ( i != j ) { swap ( arr [ i ] , arr [ j ] ) ; i ++ ; } } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } , i ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Given ▁ array ▁ is ▁ STRNEWLINE " ; for ( i = 0 ; i < n ; i ++ ) cout << arr [ i ] << " ▁ " ; rotate ( arr , n ) ; cout << " Rotated array is " ; for ( i = 0 ; i < n ; i ++ ) cout << arr [ i ] << " ▁ " ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define ll  long long int
int removeElements ( ll arr [ ] , int n ) { sort ( arr , arr + n , greater < int > ( ) ) ; ll ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ans += arr [ i ] * pow ( 2 , i ) ; } return ans ; } int main ( ) { int n = 4 ; ll arr [ n ] = { 3 , 1 , 2 , 3 } ; cout << removeElements ( arr , n ) ; }

Index/key variables: i, n
Accumulator variables: ans, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printMatrix ( int grid [ ] [ 5 ] , int m , int n ) { vector < int > A ; for ( int i = 0 ; i < m ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { if ( j == n - 1 || ( i == m - 1 ) j == 0 i == 0 ) A . push_back ( grid [ i ] [ j ] ) ; } } sort ( A . begin ( ) , A . end ( ) ) ; for ( int i = 0 ; i < n ; i ++ ) cout << A [ i ] << " ▁ " ; cout << endl ; for ( int i = 0 ; i < m - 2 ; i ++ ) { cout << A [ A . size ( ) - i - 1 ] << " ▁ " ; for ( int j = 1 ; j < n - 1 ; j ++ ) cout << grid [ i + 1 ] [ j ] << " ▁ " ; cout << ( A [ n + i ] ) << endl ; } reverse ( A . begin ( ) + n + m - 2 , A . begin ( ) + n + m + n - 2 ) ; for ( int i = n + m - 2 ; i < n + m - 2 + n ; i ++ ) cout << A [ i ] << " ▁ " ; [ n + m - 2 : n + m - 2 + n ] << endl ; } int main ( ) { int m = 4 , n = 5 ; int grid [ ] [ 5 ] = { { 1 , 2 , 3 , 4 , 0 } , { 1 , 1 , 1 , 1 , 2 } , { 1 , 2 , 2 , 2 , 4 } , { 1 , 9 , 3 , 1 , 7 } } ; printMatrix ( grid , m , 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 * right ; struct Node * down ; Node ( int x ) { data = x ; right = NULL ; down = NULL ; } } ; void printList ( Node * Node ) { while ( Node != NULL ) { printf ( " % d ▁ " , Node -> data ) ; Node = Node -> down ; } } struct compare { bool operator() ( Node * a , Node * b ) { return a -> data > b -> data ; } } ; Node * flatten ( Node * root ) { Node * ptr = root ; Node * head = NULL ; priority_queue < Node * , vector < Node * > , compare > pq ; while ( ptr != NULL ) { pq . push ( ptr ) ; ptr = ptr -> right ; } while ( ! pq . empty ( ) ) { Node * temp = pq . top ( ) ; pq . pop ( ) ; if ( temp -> down != NULL ) { pq . push ( temp -> down ) ; } if ( head == NULL ) { head = temp ; ptr = temp ; ptr -> right = NULL ; } else { ptr -> down = temp ; ptr = temp ; ptr -> right = NULL ; } } return head ; } void push ( Node * * head_ref , int new_data ) { Node * new_node = ( Node * ) malloc ( sizeof ( Node ) ) ; new_node -> right = NULL ; new_node -> data = new_data ; new_node -> down = ( * head_ref ) ; ( * head_ref ) = new_node ; } int main ( ) { Node * root = NULL ; push ( & root , 30 ) ; push ( & root , 8 ) ; push ( & root , 7 ) ; push ( & root , 5 ) ; push ( & ( root -> right ) , 20 ) ; push ( & ( root -> right ) , 10 ) ; push ( & ( root -> right -> right ) , 50 ) ; push ( & ( root -> right -> right ) , 22 ) ; push ( & ( root -> right -> right ) , 19 ) ; push ( & ( root -> right -> right -> right ) , 45 ) ; push ( & ( root -> right -> right -> right ) , 40 ) ; push ( & ( root -> right -> right -> right ) , 35 ) ; push ( & ( root -> right -> right -> right ) , 20 ) ; root = flatten ( root ) ; printList ( root ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node, compare
C++ program:
#include <bits/stdc++.h>
using namespace std ; string findLargest ( string s ) { int len = s . size ( ) ; int loccur [ 26 ] ; memset ( loccur , -1 , sizeof ( loccur ) ) ; for ( int i = len - 1 ; i >= 0 ; -- i ) { int chI = s [ i ] - ' a ' ; if ( loccur [ chI ] == -1 ) { loccur [ chI ] = i ; } } string sorted_s = s ; sort ( sorted_s . begin ( ) , sorted_s . end ( ) , greater < int > ( ) ) ; for ( int i = 0 ; i < len ; ++ i ) { if ( s [ i ] != sorted_s [ i ] ) { int chI = sorted_s [ i ] - ' a ' ; int last_occ = loccur [ chI ] ; swap ( s [ i ] , s [ last_occ ] ) ; break ; } } return s ; } int main ( ) { string s = " yrstvw " ; cout << findLargest ( s ) ; return 0 ; }

Index/key variables: chI, i, last_occ
Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; bool pairInSortedRotated ( int arr [ ] , int n , int x ) { int i ; for ( i = 0 ; i < n - 1 ; i ++ ) if ( arr [ i ] > arr [ i + 1 ] ) break ; int l = ( i + 1 ) % n ; int r = i ; while ( l != r ) { if ( arr [ l ] + arr [ r ] == x ) return true ; if ( arr [ l ] + arr [ r ] < x ) l = ( l + 1 ) % n ; else r = ( n + r - 1 ) % n ; } return false ; } int main ( ) { int arr [ ] = { 11 , 15 , 6 , 8 , 9 , 10 } ; int sum = 16 ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; if ( pairInSortedRotated ( arr , n , sum ) ) cout << " Array ▁ has ▁ two ▁ elements ▁ with ▁ sum ▁ 16" ; else cout << " Array ▁ doesn ' t ▁ have ▁ two ▁ elements ▁ with ▁ sum ▁ 16 ▁ " ; return 0 ; }

Index/key variables: i, l, r
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int pairsInSortedRotated ( int arr [ ] , int n , int x ) { int i ; for ( i = 0 ; i < n - 1 ; i ++ ) if ( arr [ i ] > arr [ i + 1 ] ) break ; int l = ( i + 1 ) % n ; int r = i ; int cnt = 0 ; while ( l != r ) { if ( arr [ l ] + arr [ r ] == x ) { cnt ++ ; if ( l == ( r - 1 + n ) % n ) { return cnt ; } l = ( l + 1 ) % n ; r = ( r - 1 + n ) % n ; } else if ( arr [ l ] + arr [ r ] < x ) l = ( l + 1 ) % n ; else r = ( n + r - 1 ) % n ; } return cnt ; } int main ( ) { int arr [ ] = { 11 , 15 , 6 , 7 , 9 , 10 } ; int sum = 16 ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << pairsInSortedRotated ( arr , n , sum ) ; return 0 ; }

Index/key variables: i, l, r
Accumulator variables: cnt, i, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int maxSum ( int arr [ ] , int n ) { int arrSum = 0 ; int currVal = 0 ; for ( int i = 0 ; i < n ; i ++ ) { arrSum = arrSum + arr [ i ] ; currVal = currVal + ( i * arr [ i ] ) ; } int maxVal = currVal ; for ( int j = 1 ; j < n ; j ++ ) { currVal = currVal + arrSum - n * arr [ n - j ] ; if ( currVal > maxVal ) maxVal = currVal ; } return maxVal ; } int main ( void ) { int arr [ ] = { 10 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Max sum is " return 0 ; }

Index/key variables: i
Accumulator variables: i, j
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left , * right ; } ; void printOddNodes ( Node * root , bool isOdd = true ) { if ( root == NULL ) return ; if ( isOdd ) cout << root -> data << " ▁ " ; printOddNodes ( root -> left , ! isOdd ) ; printOddNodes ( root -> right , ! isOdd ) ; } struct Node * newNode ( int data ) { struct Node * node = new Node ; node -> data = data ; node -> left = node -> right = NULL ; return ( node ) ; } int main ( ) { struct Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; printOddNodes ( root ) ; return 0 ; }

Accumulator variables: stdc
Boolean variables: isOdd
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxSum ( int arr [ ] , int n ) { int res = INT_MIN ; for ( int i = 0 ; i < n ; i ++ ) { int curr_sum = 0 ; for ( int j = 0 ; j < n ; j ++ ) { int index = ( i + j ) % n ; curr_sum += j * arr [ index ] ; } res = max ( res , curr_sum ) ; } return res ; } int main ( ) { int arr [ ] = { 8 , 3 , 1 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maxSum ( arr , n ) << endl ; return 0 ; }

Index/key variables: index
Accumulator variables: curr_sum, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxSum ( int arr [ ] , int n ) { int cum_sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) cum_sum += arr [ i ] ; int curr_val = 0 ; for ( int i = 0 ; i < n ; i ++ ) curr_val += i * arr [ i ] ; int res = curr_val ; for ( int i = 1 ; i < n ; i ++ ) { int next_val = curr_val - ( cum_sum - arr [ i - 1 ] ) + arr [ i - 1 ] * ( n - 1 ) ; curr_val = next_val ; res = max ( res , next_val ) ; } return res ; } int main ( ) { int arr [ ] = { 8 , 3 , 1 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maxSum ( arr , n ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: cum_sum, curr_val, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int solve ( vector < int > arr , int n ) { int k = arr . size ( ) ; bool mp [ n + 2 ] ; for ( int i = 0 ; i <= n ; i ++ ) { mp [ i ] = 0 ; } for ( int i = 0 ; i < k ; i ++ ) { mp [ arr [ i ] ] = 1 ; } int leftSegment = arr [ 0 ] - 1 ; for ( int i = 1 ; i < k ; i ++ ) { leftSegment = max ( leftSegment , arr [ i ] - arr [ i - 1 ] - 1 ) ; } int rightSegment = n - arr [ k - 1 ] ; int maxSegment = max ( leftSegment , rightSegment ) ; int tim ; if ( maxSegment & 1 ) tim = ( maxSegment / 2 ) + 1 ; else tim = maxSegment / 2 ; return tim ; } int main ( ) { int N = 5 ; vector < int > arr = { 1 , 4 } ; cout << solve ( arr , N ) ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countRotations ( int arr [ ] , int n ) { int min = arr [ 0 ] , min_index ; for ( int i = 0 ; i < n ; i ++ ) { if ( min > arr [ i ] ) { min = arr [ i ] ; min_index = i ; } } return min_index ; } int main ( ) { int arr [ ] = { 15 , 18 , 2 , 3 , 6 , 12 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countRotations ( 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 countRotations ( int arr [ ] , int low , int high ) { if ( high < low ) return 0 ; if ( high == low ) return low ; int mid = low + ( high - low ) / 2 ; if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) return ( mid + 1 ) ; if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) return mid ; if ( arr [ high ] > arr [ mid ] ) return countRotations ( arr , low , mid - 1 ) ; return countRotations ( arr , mid + 1 , high ) ; } int main ( ) { int arr [ ] = { 15 , 18 , 2 , 3 , 6 , 12 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countRotations ( arr , 0 , n - 1 ) ; return 0 ; }

Index/key variables: high, mid
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void preprocess ( int arr [ ] , int n , int temp [ ] ) { for ( int i = 0 ; i < n ; i ++ ) temp [ i ] = temp [ i + n ] = arr [ i ] ; } void leftRotate ( int arr [ ] , int n , int k , int temp [ ] ) { int start = k % n ; for ( int i = start ; i < start + n ; i ++ ) cout << temp [ i ] << " ▁ " ; cout << endl ; } int main ( ) { int arr [ ] = { 1 , 3 , 5 , 7 , 9 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int temp [ 2 * n ] ; preprocess ( arr , n , temp ) ; int k = 2 ; leftRotate ( arr , n , k , temp ) ; k = 3 ; leftRotate ( arr , n , k , temp ) ; k = 4 ; leftRotate ( arr , n , k , temp ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void Desired_Array ( vector < int > & v ) { int n = v . size ( ) ; sort ( v . begin ( ) , v . end ( ) ) ; int i = n - 1 ; while ( i > 0 ) { int p = v [ n - 1 ] ; for ( int j = n - 1 ; j >= i ; j -- ) { v [ j + 1 ] = v [ j ] ; } v [ i ] = p ; i -- ; } for ( auto x : v ) cout << x << " ▁ " ; cout << " STRNEWLINE " ; } int main ( ) { vector < int > v = { 1 , 2 , 3 , 4 , 5 } ; Desired_Array ( v ) ; vector < int > v1 = { 1 , 12 , 2 , 10 , 4 , 16 , 6 } ; Desired_Array ( v1 ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: j, x
C++ program:
#include <bits/stdc++.h>
using namespace std ; void leftRotate ( int arr [ ] , int n , int k ) { for ( int i = k ; i < k + n ; i ++ ) cout << arr [ i % n ] << " ▁ " ; } int main ( ) { int arr [ ] = { 1 , 3 , 5 , 7 , 9 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 2 ; leftRotate ( arr , n , k ) ; cout << endl ; k = 3 ; leftRotate ( arr , n , k ) ; cout << endl ; k = 4 ; leftRotate ( arr , n , k ) ; cout << endl ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int * sortArrays ( int arr [ ] , int length ) { for ( int j = 0 ; j < length - 1 ; j ++ ) { if ( arr [ j ] > arr [ j + 1 ] ) { int temp = arr [ j ] ; arr [ j ] = arr [ j + 1 ] ; arr [ j + 1 ] = temp ; j = -1 ; } } return arr ; } int main ( ) { int arr [ ] = { 1 , 2 , 99 , 9 , 8 , 7 , 6 , 0 , 5 , 4 , 3 } ; int length = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; string str ; for ( int i : arr ) { str += to_string ( i ) + " ▁ " ; } cout << " Original ▁ array : ▁ [ " << str << " ] " << endl ; int * arr1 ; arr1 = sortArrays ( arr , length ) ; string str1 ; for ( int i = 0 ; i < length ; i ++ ) { str1 += to_string ( arr1 [ i ] ) + " ▁ " ; } cout << " Sorted ▁ array : ▁ [ " << ( str1 ) << " ] " ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc, str, str1
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; char * sortArrays ( char arr [ ] , int length ) { for ( int j = 0 ; j < length - 1 ; j ++ ) { int d1 = arr [ j ] ; int d2 = arr [ j + 1 ] ; if ( d1 > d2 ) { char temp = arr [ j ] ; arr [ j ] = arr [ j + 1 ] ; arr [ j + 1 ] = temp ; j = -1 ; } } return arr ; } int main ( ) { string geeks = " GEEKSFORGEEKS " ; int n = geeks . length ( ) ; char arr [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ i ] = geeks [ i ] ; } cout << " Original ▁ array : ▁ [ " ; for ( int i = 0 ; i < n ; i ++ ) { cout << arr [ i ] ; if ( i + 1 != n ) cout << " , ▁ " ; } cout << " ] " << endl ; char * ansarr ; ansarr = sortArrays ( arr , n ) ; cout << " Sorted ▁ array : ▁ [ " ; for ( int i = 0 ; i < n ; i ++ ) { cout << ansarr [ i ] ; if ( i + 1 != n ) cout << " , ▁ " ; } cout << " ] " << endl ; }

Index/key variables: i, j, n
Accumulator variables: i, j, stdc
Iterator variables: i, j