dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool checkIsAP ( double arr [ ] , int n ) { if ( n == 1 ) return true ; sort ( arr , arr + n ) ; double d = arr [ 1 ] - arr [ 0 ] ; for ( int i = 2 ; i < n ; i ++ ) { if ( arr [ i ] - arr [ i - 1 ] != d ) { return false ; } } return true ; } bool checkIsGP ( double arr [ ] , int n ) { if ( n == 1 ) return true ; sort ( arr , arr + n ) ; double r = arr [ 1 ] / arr [ 0 ] ; for ( int i = 2 ; i < n ; i ++ ) { if ( arr [ i ] / arr [ i - 1 ] != r ) return false ; } return true ; } bool checkIsHP ( double arr [ ] , int n ) { if ( n == 1 ) { return true ; } double rec [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { rec [ i ] = ( ( 1 / arr [ i ] ) ) ; } if ( checkIsAP ( rec , n ) ) return true ; else return false ; } int main ( ) { double arr [ ] = { 1.0 / 5.0 , 1.0 / 10.0 , 1.0 / 15.0 , 1.0 / 20.0 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int flag = 0 ; if ( checkIsAP ( arr , n ) ) { cout << " Yes , ▁ An ▁ AP ▁ can ▁ be ▁ formed " << endl ; flag = 1 ; } if ( checkIsGP ( arr , n ) ) { cout << " Yes , ▁ A ▁ GP ▁ can ▁ be ▁ formed " << endl ; flag = 1 ; } if ( checkIsHP ( arr , n ) ) { cout << " Yes , ▁ A ▁ HP ▁ can ▁ be ▁ formed " << endl ; flag = 1 ; } else if ( flag == 0 ) { cout << " No " ; } return 0 ; }

Index/key variables: i, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int reversDigits ( int num ) { int rev_num = 0 ; while ( num > 0 ) { rev_num = rev_num * 10 + num % 10 ; num = num / 10 ; } return rev_num ; } void sortArr ( int arr [ ] , int n ) { vector < pair < int , int > > vp ; for ( int i = 0 ; i < n ; i ++ ) { vp . push_back ( make_pair ( reversDigits ( arr [ i ] ) , arr [ i ] ) ) ; } sort ( vp . begin ( ) , vp . end ( ) ) ; for ( int i = 0 ; i < vp . size ( ) ; i ++ ) cout << vp [ i ] . second << " ▁ " ; } int main ( ) { int arr [ ] = { 12 , 10 , 102 , 31 , 15 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sortArr ( 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 CountPairs ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; int count = 0 ; int l = 0 , r = n - 1 ; while ( l < r ) { if ( arr [ l ] + arr [ r ] > 0 ) { count += ( r - l ) ; r -- ; } else { l ++ ; } } return count ; } int main ( ) { int arr [ ] = { -7 , -1 , 3 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << CountPairs ( arr , n ) ; return 0 ; }

Index/key variables: l, r
Accumulator variables: count, l, r, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define N  3
#define M  3
void sortMat ( int data [ N ] [ M ] , int row , int col ) { int size = row * col ; for ( int i = 0 ; i < size ; i ++ ) { for ( int j = 0 ; j < size - 1 ; j ++ ) { if ( data [ j / col ] [ j % col ] > data [ ( j + 1 ) / col ] [ ( j + 1 ) % col ] ) { int temp = data [ j / col ] [ j % col ] ; data [ j / col ] [ j % col ] = data [ ( j + 1 ) / col ] [ ( j + 1 ) % col ] ; data [ ( j + 1 ) / col ] [ ( j + 1 ) % col ] = temp ; } } } } void printMat ( int mat [ N ] [ M ] , int row , int col ) { for ( int i = 0 ; i < row ; i ++ ) { for ( int j = 0 ; j < col ; j ++ ) { cout << mat [ i ] [ j ] << " ▁ " ; } cout << endl ; } } int main ( ) { int mat [ N ] [ M ] = { { 5 , 4 , 7 } , { 1 , 3 , 8 } , { 2 , 9 , 6 } } ; int row = N ; int col = M ; sortMat ( mat , row , col ) ; printMat ( mat , row , col ) ; return 0 ; }

Index/key variables: M, N, i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void overlap ( vector < pair < int , int > > v ) { int ans = 0 ; int count = 0 ; vector < pair < int , char > > data ; for ( int i = 0 ; i < v . size ( ) ; i ++ ) { data . push_back ( { v [ i ] . first , ' x ' } ) ; data . push_back ( { v [ i ] . second , ' y ' } ) ; } sort ( data . begin ( ) , data . end ( ) ) ; for ( int i = 0 ; i < data . size ( ) ; i ++ ) { if ( data [ i ] . second == ' x ' ) count ++ ; if ( data [ i ] . second == ' y ' ) count -- ; ans = max ( ans , count ) ; } cout << ans << endl ; } int main ( ) { vector < pair < int , int > > v = { { 1 , 2 } , { 2 , 4 } , { 3 , 6 } } ; overlap ( v ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool canBeEqual ( int a , int b , int c , int k ) { int arr [ 3 ] ; arr [ 0 ] = a ; arr [ 1 ] = b ; arr [ 2 ] = c ; sort ( arr , arr + 3 ) ; int diff = 2 * arr [ 2 ] - arr [ 1 ] - arr [ 0 ] ; k = k - diff ; if ( k < 0 k % 3 != 0 ) return false ; return true ; } int main ( ) { int a1 = 6 , b1 = 3 , c1 = 2 , k1 = 7 ; if ( canBeEqual ( a1 , b1 , c1 , k1 ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > orgazineInOrder ( vector < int > vec , vector < int > op , int n ) { vector < int > result ( n ) ; sort ( vec . begin ( ) , vec . end ( ) ) ; int i = 0 , j = n - 1 , k = 0 ; while ( i <= j && k <= n - 2 ) { if ( op [ k ] == ' < ' ) { result [ k ] = vec [ i ++ ] ; } else { result [ k ] = vec [ j -- ] ; } k ++ ; } result [ n - 1 ] = vec [ i ] ; return result ; } int main ( ) { vector < int > vec ( { 8 , 2 , 7 , 1 , 5 , 9 } ) ; vector < int > op ( { ' > ' , ' > ' , ' < ' , ' > ' , ' < ' } ) ; vector < int > result = orgazineInOrder ( vec , op , vec . size ( ) ) ; for ( int i = 0 ; i < result . size ( ) ; i ++ ) { cout << result [ i ] << " ▁ " ; } return 0 ; }

Index/key variables: i, k
Accumulator variables: i, j, k, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getDistance ( int arr [ ] [ 2 ] , int n , int a , int b ) { vector < pair < int , int > > vp ; for ( int i = 0 ; i < n ; i ++ ) { vp . push_back ( { arr [ i ] [ 0 ] , arr [ i ] [ 1 ] } ) ; } sort ( vp . begin ( ) , vp . end ( ) ) ; vector < int > pos ; for ( int i = 0 ; i < vp . size ( ) ; i ++ ) { int height = vp [ i ] . first ; int k = vp [ i ] . second ; pos . insert ( pos . begin ( ) + k , height ) ; } int first = -1 , second = -1 ; for ( int i = 0 ; i < pos . size ( ) ; i ++ ) { if ( pos [ i ] == a ) first = i ; if ( pos [ i ] == b ) second = i ; } return abs ( first - second ) ; } int main ( ) { int arr [ ] [ 2 ] = { { 5 , 0 } , { 3 , 0 } , { 2 , 0 } , { 6 , 4 } , { 1 , 0 } , { 4 , 3 } } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int a = 6 , b = 5 ; cout << getDistance ( arr , n , a , b ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findSum ( int * arr , int n , int k ) { int ans = arr [ n - k - 1 ] - arr [ 0 ] ; for ( int i = 1 ; i <= k ; i ++ ) { ans = min ( arr [ n - 1 - ( k - i ) ] - arr [ i ] , ans ) ; } return ans ; } int32_t main ( ) { int arr [ ] = { 1 , 2 , 100 , 120 , 140 } ; int k = 2 ; int n = sizeof ( arr ) / sizeof ( int ) ; cout << findSum ( arr , n , k ) ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findMin ( int * arr , int n ) { int ans = 1 ; for ( int i = 0 ; i < n ; i ++ ) { int j = i + 1 ; while ( j < n and arr [ j ] > = arr [ j - 1 ] ) j ++ ; ans = max ( ans , j - i ) ; i = j - 1 ; } return n - ans ; } int main ( ) { int arr [ ] = { 3 , 2 , 1 } ; int n = sizeof ( arr ) / sizeof ( int ) ; cout << findMin ( arr , n ) ; return 0 ; }

Index/key variables: j
Accumulator variables: i, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countSubSeq ( int a [ ] , int n , int k ) { sort ( a , a + n ) ; vector < int > arr ; for ( int i = 0 ; i < n ; ) { int count = 1 , x = a [ i ] ; i ++ ; while ( i < n && a [ i ] == x ) { count ++ ; i ++ ; } arr . push_back ( count ) ; } int m = arr . size ( ) ; n = min ( m , k ) ; int count = 1 ; int dp [ n + 1 ] [ m + 1 ] ; for ( int i = 0 ; i <= m ; i ++ ) dp [ 0 ] [ i ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = m ; j >= 0 ; j -- ) { if ( j > m - i ) dp [ i ] [ j ] = 0 ; else { dp [ i ] [ j ] = dp [ i ] [ j + 1 ] + arr [ j ] * dp [ i - 1 ] [ j + 1 ] ; } } count = count + dp [ i ] [ 0 ] ; } return count ; } int main ( ) { int a [ ] = { 2 , 2 , 3 , 3 , 5 } ; int n = sizeof ( a ) / sizeof ( int ) ; int k = 3 ; cout << countSubSeq ( a , n , k ) ; 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 ; int countUnvisited ( int n , int m ) { int X = ( m * n ) - m - n ; queue < int > queue ; queue . push ( X ) ; int count = 0 ; while ( queue . size ( ) > 0 ) { int curr = queue . front ( ) ; queue . pop ( ) ; count ++ ; if ( curr - m > 0 ) queue . push ( curr - m ) ; if ( curr - n > 0 ) queue . push ( curr - n ) ; } return count ; } int main ( ) { int n = 2 , m = 5 ; cout << countUnvisited ( n , m ) ; return 0 ; }

Accumulator variables: count, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; string partOdd ( string s ) { string st = " " ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( i % 2 != 0 ) st += s [ i ] ; } return st ; } string partEven ( string str ) { string s = " " ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( i % 2 == 0 ) s += str [ i ] ; } return s ; } bool canBeMadeEqual ( string s1 , string s2 ) { string even_s1 = partEven ( s1 ) ; string even_s2 = partEven ( s2 ) ; string odd_s1 = partOdd ( s1 ) ; string odd_s2 = partOdd ( s2 ) ; sort ( even_s1 . begin ( ) , even_s1 . end ( ) ) ; sort ( even_s2 . begin ( ) , even_s2 . end ( ) ) ; sort ( odd_s1 . begin ( ) , odd_s1 . end ( ) ) ; sort ( odd_s2 . begin ( ) , odd_s2 . end ( ) ) ; if ( even_s1 == even_s2 and odd_s1 == odd_s2 ) return true ; return false ; } int main ( ) { string s1 = " cdab " ; string s2 = " abcd " ; if ( canBeMadeEqual ( s1 , s2 ) ) cout << " Yes " << endl ; else cout << " No " << endl ; }

Index/key variables: i
Accumulator variables: i, s, st, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void sortStack ( stack < int > & input , int k ) { stack < int > tmpStack ; while ( ! input . empty ( ) ) { int tmp = input . top ( ) ; input . pop ( ) ; while ( ! tmpStack . empty ( ) ) { int tmpStackMod = tmpStack . top ( ) % k ; int tmpMod = tmp % k ; if ( ( tmpStackMod > tmpMod ) || ( tmpStackMod == tmpMod && tmpStack . top ( ) > tmp ) ) { input . push ( tmpStack . top ( ) ) ; tmpStack . pop ( ) ; } else break ; } tmpStack . push ( tmp ) ; } while ( ! tmpStack . empty ( ) ) { input . push ( tmpStack . top ( ) ) ; tmpStack . pop ( ) ; } while ( ! input . empty ( ) ) { cout << input . top ( ) << " ▁ " ; input . pop ( ) ; } } int main ( ) { stack < int > input ; input . push ( 10 ) ; input . push ( 3 ) ; input . push ( 2 ) ; input . push ( 6 ) ; input . push ( 12 ) ; int k = 4 ; sortStack ( input , k ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int MAX = 1000 ; bool lineExists ( int x [ ] , int y [ ] , int v [ ] , int n ) { int size = ( 2 * MAX ) + 1 ; long arr [ size ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) { arr [ x [ i ] + MAX ] += v [ i ] ; } for ( int i = 1 ; i < size ; i ++ ) arr [ i ] += arr [ i - 1 ] ; if ( arr [ size - 1 ] == 0 ) return true ; if ( arr [ size - 1 ] - arr [ 0 ] == 0 ) return true ; for ( int i = 1 ; i < size - 1 ; i ++ ) { if ( arr [ i - 1 ] == arr [ size - 1 ] - arr [ i - 1 ] ) return true ; if ( arr [ i - 1 ] == arr [ size - 1 ] - arr [ i ] ) return true ; if ( arr [ i ] == arr [ size - 1 ] - arr [ i ] ) return true ; } if ( arr [ size - 2 ] == 0 ) return true ; return false ; } int main ( ) { int x [ ] = { -3 , 5 , 8 } ; int y [ ] = { 8 , 7 , 9 } ; int v [ ] = { 8 , 2 , 10 } ; int n = sizeof ( x ) / sizeof ( int ) ; if ( lineExists ( x , y , v , n ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: i, size
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maxSum ( int a [ ] , int n ) { sort ( a , a + n ) ; int sum = 0 ; for ( int i = 0 ; i < n - 1 ; i += 2 ) { sum += a [ i ] ; } return sum ; } int main ( ) { int arr [ ] = { 1 , 3 , 2 , 1 , 4 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << maxSum ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printArr ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) cout << arr [ i ] << " ▁ " ; } void sortWithRemainder ( int arr [ ] , int n , int k ) { vector < int > v [ k ] ; for ( int i = 0 ; i < n ; i ++ ) { v [ arr [ i ] % k ] . push_back ( arr [ i ] ) ; } for ( int i = 0 ; i < k ; i ++ ) sort ( v [ i ] . begin ( ) , v [ i ] . end ( ) ) ; int j = 0 ; for ( int i = 0 ; i < k ; i ++ ) { for ( vector < int > :: iterator it = v [ i ] . begin ( ) ; it != v [ i ] . end ( ) ; it ++ ) { arr [ j ] = * it ; j ++ ; } } printArr ( arr , n ) ; } int main ( ) { int arr [ ] = { 10 , 7 , 2 , 6 , 12 , 3 , 33 , 46 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 4 ; sortWithRemainder ( arr , n , k ) ; return 0 ; }

Index/key variables: i, j, k
Accumulator variables: i, it, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool customSort ( string s1 , string s2 ) { int count_a1 = 0 , count_b1 = 0 ; for ( int i = 0 ; i < s1 . size ( ) ; i ++ ) { if ( s1 [ i ] == ' a ' ) count_a1 ++ ; else count_b1 ++ ; } int count_a2 = 0 , count_b2 = 0 ; for ( int i = 0 ; i < s2 . size ( ) ; i ++ ) { if ( s2 [ i ] == ' a ' ) count_a2 ++ ; else count_b2 ++ ; } if ( count_a1 * count_b2 > count_b1 * count_a2 ) { return 1 ; } else { return 0 ; } } string concatenateStrings ( string S [ ] , int N ) { string str = " " ; for ( int i = 0 ; i < N ; i ++ ) str += S [ i ] ; return str ; } int getMaxScore ( string S [ ] , int N ) { sort ( S , S + N , customSort ) ; string combined_string = concatenateStrings ( S , N ) ; int final_score = 0 , count_a = 0 ; for ( int i = 0 ; i < combined_string . size ( ) ; i ++ ) { if ( combined_string [ i ] == ' a ' ) { count_a ++ ; } else { final_score += count_a ; } } return final_score ; } int main ( ) { string S [ ] = { " bab " , " aa " , " ba " , " b " } ; int N = sizeof ( S ) / sizeof ( string ) ; cout << getMaxScore ( S , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count_a, count_a1, count_a2, count_b1, count_b2, final_score, i, stdc, str
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minOperations ( vector < int > ar , int k ) { sort ( ar . begin ( ) , ar . end ( ) ) ; int opsNeeded = 0 ; for ( int i = 0 ; i < k ; i ++ ) { opsNeeded += ar [ k - 1 ] - ar [ i ] ; } int ans = opsNeeded ; for ( int i = k ; i < ar . size ( ) ; i ++ ) { opsNeeded = opsNeeded - ( ar [ i - 1 ] - ar [ i - k ] ) ; opsNeeded += ( k - 1 ) * ( ar [ i ] - ar [ i - 1 ] ) ; ans = min ( ans , opsNeeded ) ; } return ans ; } int main ( ) { vector < int > arr = { 3 , 1 , 9 , 100 } ; int n = arr . size ( ) ; int k = 3 ; cout << minOperations ( arr , k ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, opsNeeded, stdc
Iterator variables: i
C++ program:
#include <iostream>
#include <string>
using namespace std ; int x = -1 ; string heap [ 1000 ] ; void heapForm ( string k ) { x ++ ; heap [ x ] = k ; int child = x ; string tmp ; int index = x / 2 ; while ( index >= 0 ) { if ( heap [ index ] > heap [ child ] ) { tmp = heap [ index ] ; heap [ index ] = heap [ child ] ; heap [ child ] = tmp ; child = index ; index = index / 2 ; } else { break ; } } } void heapSort ( ) { int left1 , right1 ; while ( x >= 0 ) { string k ; k = heap [ 0 ] ; cout << k << " ▁ " ; heap [ 0 ] = heap [ x ] ; x = x - 1 ; string tmp ; int index = 0 ; int length = x ; left1 = 1 ; right1 = left1 + 1 ; while ( left1 <= length ) { if ( heap [ index ] <= heap [ left1 ] && heap [ index ] <= heap [ right1 ] ) { break ; } else { if ( heap [ left1 ] < heap [ right1 ] ) { tmp = heap [ index ] ; heap [ index ] = heap [ left1 ] ; heap [ left1 ] = tmp ; index = left1 ; } else { tmp = heap [ index ] ; heap [ index ] = heap [ right1 ] ; heap [ right1 ] = tmp ; index = right1 ; } } left1 = 2 * left1 ; right1 = left1 + 1 ; } } } void sort ( string k [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) { heapForm ( k [ i ] ) ; } heapSort ( ) ; } int main ( ) { string arr [ ] = { " banana " , " orange " , " apple " , " pineapple " , " berries " , " lichi " } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sort ( arr , n ) ; }

Index/key variables: child, i, index, left1, right1, x
Accumulator variables: i, x
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int getNumber ( int n , int k ) { int arr [ n ] ; int i = 0 ; int odd = 1 ; while ( odd <= n ) { arr [ i ++ ] = odd ; odd += 2 ; } int even = 2 ; while ( even <= n ) { arr [ i ++ ] = even ; even += 2 ; } return arr [ k - 1 ] ; } int main ( ) { int n = 8 , k = 5 ; cout << getNumber ( n , k ) ; return 0 ; }

Index/key variables: n
Accumulator variables: even, i, odd, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printArr ( int arr [ ] , int n ) { for ( int i = 0 ; i < n ; i ++ ) cout << arr [ i ] << " ▁ " ; } void UpdateArr ( int arr [ ] , int n ) { int i = 0 , j = n - 1 ; while ( i < j ) { int temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; i += 2 ; j -= 2 ; } printArr ( arr , n ) ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; UpdateArr ( arr , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define N  20
int fact [ N ] ; void pre ( ) { fact [ 0 ] = 1 ; for ( int i = 1 ; i < N ; i ++ ) { fact [ i ] = i * fact [ i - 1 ] ; } } int CountPermutation ( int a [ ] , int n ) { int ways = 1 ; sort ( a , a + n ) ; int size = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( a [ i ] == a [ i - 1 ] ) { size ++ ; } else { ways *= fact [ size ] ; size = 1 ; } } ways *= fact [ size ] ; return ways ; } int main ( ) { int a [ ] = { 1 , 2 , 4 , 4 , 2 , 4 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; pre ( ) ; cout << CountPermutation ( a , n ) ; return 0 ; }

Index/key variables: N, i, size
Accumulator variables: i, size, stdc, ways
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int Next_greater ( int a [ ] , int n , int x ) { sort ( a , a + n ) ; int low = 0 , high = n - 1 , ans = x + 1 ; while ( low <= high ) { int mid = ( low + high ) / 2 ; if ( a [ mid ] <= ans ) { if ( a [ mid ] == ans ) { ans ++ ; high = n - 1 ; } low = mid + 1 ; } else high = mid - 1 ; } return ans ; } int main ( ) { int a [ ] = { 1 , 5 , 10 , 4 , 7 } , x = 4 ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << Next_greater ( a , n , x ) ; return 0 ; }

Index/key variables: mid
Accumulator variables: ans, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MAX  100000
void xorOnSortedArray ( int arr [ ] , int n , int k , int x ) { int arr1 [ MAX + 1 ] = { 0 } ; int arr2 [ MAX + 1 ] = { 0 } ; int xor_val [ MAX + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) arr1 [ arr [ i ] ] ++ ; for ( int i = 0 ; i <= MAX ; i ++ ) xor_val [ i ] = i ^ x ; while ( k -- ) { int count = 0 ; for ( int i = 0 ; i <= MAX ; i ++ ) { int store = arr1 [ i ] ; if ( arr1 [ i ] > 0 ) { if ( count % 2 == 0 ) { int div = ceil ( ( float ) arr1 [ i ] / 2 ) ; arr1 [ i ] = arr1 [ i ] - div ; arr2 [ xor_val [ i ] ] += div ; } else if ( count % 2 != 0 ) { int div = arr1 [ i ] / 2 ; arr1 [ i ] = arr1 [ i ] - div ; arr2 [ xor_val [ i ] ] += div ; } } count = count + store ; } for ( int i = 0 ; i <= MAX ; i ++ ) { arr1 [ i ] = arr1 [ i ] + arr2 [ i ] ; arr2 [ i ] = 0 ; } } int min = INT_MAX ; int max = INT_MIN ; for ( int i = 0 ; i <= MAX ; i ++ ) { if ( arr1 [ i ] > 0 ) { if ( min > i ) min = i ; if ( max < i ) max = i ; } } cout << min << " ▁ " << max << endl ; } int main ( ) { int arr [ ] = { 605 , 986 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int k = 548 , x = 569 ; xorOnSortedArray ( arr , n , k , x ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, k, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void printArrangement ( int a [ ] , int n ) { sort ( a , a + n ) ; int b [ n ] ; int low = 0 , high = n - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 0 ) b [ low ++ ] = a [ i ] ; else b [ high -- ] = a [ i ] ; } for ( int i = 0 ; i < n ; i ++ ) { if ( i == 0 ) { if ( b [ n - 1 ] + b [ 1 ] <= b [ i ] ) { cout << -1 ; return ; } } else if ( i == ( n - 1 ) ) { if ( b [ n - 2 ] + b [ 0 ] <= b [ i ] ) { cout << -1 ; return ; } } else { if ( b [ i - 1 ] + b [ i + 1 ] <= b [ i ] ) { cout << -1 ; return ; } } } for ( int i = 0 ; i < n ; i ++ ) cout << b [ i ] << " ▁ " ; } int main ( ) { int a [ ] = { 1 , 4 , 4 , 3 , 2 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; printArrangement ( a , n ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: high, i, low, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > findSubarray ( int a [ ] , int k , int n ) { vector < vector < int > > vec ; for ( int i = 0 ; i < n - k + 1 ; i ++ ) { vector < int > temp ; for ( int j = i ; j < i + k ; j ++ ) { temp . push_back ( a [ j ] ) ; } vec . push_back ( temp ) ; } sort ( vec . begin ( ) , vec . end ( ) ) ; return vec [ vec . size ( ) - 1 ] ; } int main ( ) { int a [ ] = { 1 , 4 , 3 , 2 , 5 } ; int k = 4 ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; vector < int > ans = findSubarray ( a , k , n ) ; for ( auto it : ans ) cout << it << " ▁ " ; }

Index/key variables: j
Accumulator variables: i, j, stdc
Iterator variables: i, it, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct val { int first ; int second ; } ; bool comparator ( struct val p1 , struct val p2 ) { return ( p1 . second < p2 . second ) ; } int maxChainLen ( struct val p [ ] , int n ) { int l = 1 ; sort ( p , p + n , comparator ) ; int s = p [ 0 ] . second ; for ( int i = 1 ; i < n ; i ++ ) { if ( p [ i ] . first > s ) { l ++ ; s = p [ i ] . second ; } } return l ; } int main ( ) { val p [ ] = { { 5 , 24 } , { 39 , 60 } , { 15 , 28 } , { 27 , 40 } , { 50 , 90 } } ; int n = sizeof ( p ) / sizeof ( p [ 0 ] ) ; cout << maxChainLen ( p , n ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, l, stdc
Iterator variables: i
Class/struct names: val
C++ program:
#include <bits/stdc++.h>
using namespace std ; float knapSack ( int W , float wt [ ] , float val [ ] , int n ) { float maxratio = INT_MIN ; int maxindex = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ( val [ i ] / wt [ i ] ) > maxratio ) { maxratio = ( val [ i ] / wt [ i ] ) ; maxindex = i ; } } return ( W * maxratio ) ; } int main ( ) { float val [ ] = { 14 , 27 , 44 , 19 } ; float wt [ ] = { 6 , 7 , 9 , 8 } ; int n = sizeof ( val ) / sizeof ( val [ 0 ] ) ; int W = 50 ; cout << knapSack ( W , wt , val , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void sortArray ( int a [ ] , int n ) { vector < int > ans ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] >= 0 ) ans . push_back ( a [ i ] ) ; } sort ( ans . begin ( ) , ans . end ( ) ) ; int j = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] >= 0 ) { a [ i ] = ans [ j ] ; j ++ ; } } for ( int i = 0 ; i < n ; i ++ ) cout << a [ i ] << " ▁ " ; } int main ( ) { int arr [ ] = { 2 , -6 , -3 , 8 , 4 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; sortArray ( arr , n ) ; return 0 ; }

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