dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; void split ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; int count = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] - arr [ i - 1 ] == 1 ) { count = 2 ; break ; } } cout << count << endl ; } int main ( ) { int arr [ ] = { 2 , 4 , 6 } ; int n = sizeof ( arr ) / sizeof ( int ) ; split ( arr , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool check ( string str1 , string str2 ) { vector < bool > mark ( 26 , false ) ; int n = str1 . size ( ) , m = str2 . size ( ) ; for ( int i = 0 ; i < n ; i ++ ) { mark [ str1 [ i ] - ' a ' ] = true ; } for ( int i = 0 ; i < m ; i ++ ) { if ( mark [ str2 [ i ] - ' a ' ] ) return true ; } return false ; } int main ( ) { string str1 = " abca " , str2 = " efad " ; if ( check ( str1 , str2 ) ) cout << " Yes " ; else cout << " No " ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void FindPairs ( int n , int k ) { cout << 1 << " ▁ " << n << endl ; k -- ; for ( long long i = 2 ; i <= sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { cout << 1 << " ▁ " << i << endl ; k -- ; if ( k == 0 ) break ; if ( i != n / i ) { cout << 1 << " ▁ " << n / i << endl ; k -- ; } if ( k == 0 ) break ; } } } int main ( ) { int N = 100 ; int K = 5 ; FindPairs ( N , K ) ; return 0 ; }

Accumulator variables: i, k, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void dfs ( int u , vector < int > adj [ ] , int * vis , int * inDeg , int * outDeg ) { vis [ u ] = 1 ; for ( auto v : adj [ u ] ) { outDeg [ u ] = 1 ; inDeg [ v ] = 1 ; if ( vis [ v ] == 0 ) { dfs ( v , adj , vis , inDeg , outDeg ) ; } } } int findMinimumEdges ( int source [ ] , int N , int M , int dest [ ] ) { vector < int > adj [ N + 1 ] ; for ( int i = 0 ; i < M ; i ++ ) { adj [ source [ i ] ] . push_back ( dest [ i ] ) ; } int inDeg [ N + 1 ] = { 0 } ; int outDeg [ N + 1 ] = { 0 } ; int vis [ N + 1 ] = { 0 } ; dfs ( 1 , adj , vis , inDeg , outDeg ) ; int minEdges = 0 ; int totalIndegree = 0 ; int totalOutdegree = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { if ( inDeg [ i ] == 1 ) totalIndegree ++ ; if ( outDeg [ i ] == 1 ) totalOutdegree ++ ; } minEdges = max ( N - totalIndegree , N - totalOutdegree ) ; return minEdges ; } int main ( ) { int N = 5 , M = 5 ; int source [ ] = { 1 , 3 , 1 , 3 , 4 } ; int destination [ ] = { 2 , 2 , 3 , 4 , 5 } ; cout << findMinimumEdges ( source , N , M , destination ) ; return 0 ; }

Index/key variables: i, u, v
Accumulator variables: i, stdc, totalIndegree, totalOutdegree
Iterator variables: i, v
C++ program:
#include <bits/stdc++.h>
using namespace std ; int PermuteTheArray ( int A [ ] , int n ) { int arr [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { arr [ A [ i ] - 1 ] = i ; } int mini = n , maxi = 0 ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { mini = min ( mini , arr [ i ] ) ; maxi = max ( maxi , arr [ i ] ) ; if ( maxi - mini == i ) count ++ ; } return count ; } int main ( ) { int A [ ] = { 4 , 5 , 1 , 3 , 2 , 6 } ; cout << PermuteTheArray ( A , 6 ) ; return 0 ; }

Index/key variables: i, n
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > findLargest ( int beg , int end , vector < int > arr , int n ) { if ( beg == end ) { vector < int > compared ( n , 0 ) ; compared [ 0 ] = 1 ; compared [ 1 ] = arr [ beg ] ; return compared ; } vector < int > compared1 = findLargest ( beg , ( beg + end ) / 2 , arr , n ) ; vector < int > compared2 = findLargest ( ( beg + end ) / 2 + 1 , end , arr , n ) ; if ( compared1 [ 1 ] > compared2 [ 1 ] ) { int k = compared1 [ 0 ] + 1 ; compared1 [ 0 ] = k ; compared1 [ k ] = compared2 [ 1 ] ; return compared1 ; } else { int k = compared2 [ 0 ] + 1 ; compared2 [ 0 ] = k ; compared2 [ k ] = compared1 [ 1 ] ; return compared2 ; } } void findSecondLargest ( int end , vector < int > arr ) { vector < int > compared1 = findLargest ( 0 , end - 1 , arr , end ) ; vector < int > compared2 = findLargest ( 2 , compared1 [ 0 ] + 2 , compared1 , compared1 [ 0 ] ) ; cout << compared2 [ 1 ] ; } int main ( ) { int N = 10 ; vector < int > arr { 20 , 1990 , 12 , 1110 , 1 , 59 , 12 , 15 , 120 , 1110 } ; findSecondLargest ( N , arr ) ; return 0 ; }

Index/key variables: beg, k
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int CountsubString ( char str [ ] , int n ) { int c = 0 ; for ( int len = 1 ; len <= n ; len ++ ) { for ( int i = 0 ; i <= n - len ; i ++ ) { int j = i + len - 1 ; char temp = str [ i ] , f = 0 ; if ( j == i ) { c ++ ; continue ; } int k = i + 1 ; while ( temp > str [ k ] && k <= j ) { temp = str [ k ] ; k ++ ; } if ( k > j ) { c ++ ; f = 2 ; } while ( temp < str [ k ] && k <= j && f != 2 ) { temp = str [ k ] ; k ++ ; } if ( k > j && f != 2 ) { c ++ ; f = 0 ; } } } return c ; } int main ( ) { char str [ ] = " bade " ; cout << CountsubString ( str , strlen ( str ) ) ; return 0 ; }

Index/key variables: i, k
Accumulator variables: c, i, k, len, stdc
Iterator variables: i, len
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool isSubsetSum ( int arr [ ] , int n , int sum ) { bool subset [ n + 1 ] [ sum + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) subset [ i ] [ 0 ] = true ; for ( int i = 1 ; i <= sum ; i ++ ) subset [ 0 ] [ i ] = false ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= sum ; j ++ ) { if ( j < arr [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] ; if ( j >= arr [ i - 1 ] ) subset [ i ] [ j ] = subset [ i - 1 ] [ j ] || subset [ i - 1 ] [ j - arr [ i - 1 ] ] ; } } return subset [ n ] [ sum ] ; } int findSum ( int * arr , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; } int val = sqrt ( sum ) ; for ( int i = val ; i >= 0 ; i -- ) { if ( isSubsetSum ( arr , n , i * i ) ) { return i * i ; } } return 0 ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findSum ( arr , n ) << endl ; return 0 ; }

Index/key variables: i, j, n, sum
Accumulator variables: i, j, stdc, sum
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findsubArray ( int arr [ ] , int N , int K ) { int res = N + 1 ; for ( int i = 0 ; i < N ; i ++ ) { int curr_prod = 1 ; for ( int j = i ; j < N ; j ++ ) { curr_prod = curr_prod * arr [ j ] ; if ( curr_prod % N == K && res > ( j - i + 1 ) ) { res = min ( res , j - i + 1 ) ; break ; } } } return ( res == N + 1 ) ? 0 : res ; } int main ( ) { int arr [ ] = { 2 , 2 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int K = 1 ; int answer = findsubArray ( arr , N , K ) ; if ( answer != 0 ) cout << answer ; else cout << " - 1" ; return 0 ; }

Index/key variables: j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int maximumCount ( int A [ ] , int B [ ] , int n ) { queue < int > q ; unordered_set < int > s ; for ( int i = 0 ; i < n ; i ++ ) { s . insert ( B [ i ] ) ; q . push ( B [ i ] ) ; } int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . find ( A [ i ] ) == s . end ( ) ) continue ; while ( ! q . empty ( ) && q . front ( ) != A [ i ] ) { s . erase ( q . front ( ) ) ; q . pop ( ) ; count ++ ; } if ( A [ i ] == q . front ( ) ) { q . pop ( ) ; s . erase ( A [ i ] ) ; } if ( q . empty ( ) ) break ; } cout << count << endl ; } int main ( ) { int N = 4 ; int A [ ] = { 1 , 2 , 3 , 4 } ; int B [ ] = { 1 , 2 , 4 , 3 } ; maximumCount ( A , B , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int N = 3 , M = 3 ; bool checkBitonic ( int arr [ ] , int n ) { int i , j , f = 0 ; for ( i = 1 ; i < n ; i ++ ) { if ( arr [ i ] > arr [ i - 1 ] ) continue ; if ( arr [ i ] == arr [ i - 1 ] ) return false ; else { f = 1 ; break ; } } if ( i == n ) return true ; for ( j = i + 1 ; j < n ; j ++ ) { if ( arr [ j ] < arr [ j - 1 ] ) continue ; if ( arr [ i ] == arr [ i - 1 ] ) return false ; else { if ( f == 1 ) return false ; } } return true ; } void check ( int arr [ N ] [ M ] ) { int f = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( ! checkBitonic ( arr [ i ] , M ) ) { cout << " NO " << endl ; return ; } } for ( int i = 0 ; i < N ; i ++ ) { int temp [ N ] ; for ( int j = 0 ; j < N ; j ++ ) { temp [ j ] = arr [ j ] [ i ] ; } if ( ! checkBitonic ( temp , N ) ) { cout << " NO " << endl ; return ; } } cout << " YES " ; } int main ( ) { int m [ N ] [ M ] = { { 1 , 2 , 3 } , { 3 , 4 , 5 } , { 2 , 6 , 4 } } ; check ( m ) ; 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 ; int getMaxGcd ( int N ) { int maxGcd = INT_MIN , A , B ; for ( int i = 1 ; i <= sqrt ( N ) ; i ++ ) { if ( N % i == 0 ) { A = i , B = N / i ; maxGcd = max ( maxGcd , __gcd ( A , B ) ) ; } } return maxGcd ; } int main ( ) { int N = 18 ; cout << getMaxGcd ( N ) ; return 0 ; }

Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool can_place ( int A [ ] , int n , int B , int mid ) { int count = 1 ; int last_position = A [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( A [ i ] - last_position >= mid ) { last_position = A [ i ] ; count ++ ; if ( count == B ) { return true ; } } } return false ; } int find_min_difference ( int A [ ] , int n , int B ) { sort ( A , A + n ) ; int s = 0 ; int e = A [ n - 1 ] - A [ 0 ] ; int ans = 0 ; while ( s <= e ) { long long int mid = ( s + e ) / 2 ; if ( can_place ( A , n , B , mid ) ) { ans = mid ; s = mid + 1 ; } else { e = mid - 1 ; } } return ans ; } int main ( ) { int A [ ] = { 1 , 2 , 3 , 5 } ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; int B = 3 ; int min_difference = find_min_difference ( A , n , B ) ; cout << min_difference ; return 0 ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countTriplets ( int A [ ] , int N ) { int ans = 0 ; map < int , int > map ; for ( int j = N - 2 ; j >= 1 ; j -- ) { map [ A [ j + 1 ] ] ++ ; for ( int i = 0 ; i < j ; i ++ ) { int target = A [ i ] * A [ j ] ; if ( map . find ( target ) != map . end ( ) ) ans += map [ target ] ; } } return ans ; } int main ( ) { int N = 5 ; int A [ ] = { 2 , 3 , 4 , 6 , 12 } ; cout << countTriplets ( A , N ) ; return 0 ; }

Index/key variables: i, j, target
Accumulator variables: ans, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; void MissingPoint ( vector < pair < int , int > > V , int N ) { map < int , int > mp ; for ( int i = 0 ; i < V . size ( ) ; i ++ ) { mp [ V [ i ] . first ] ++ ; } int x , y ; for ( auto it : mp ) { if ( it . second % 2 == 1 ) { x = it . first ; break ; } } mp . clear ( ) ; for ( int i = 0 ; i < V . size ( ) ; i ++ ) { mp [ V [ i ] . second ] ++ ; } for ( auto it : mp ) { if ( it . second % 2 == 1 ) { y = it . first ; break ; } } cout << x << " ▁ " << y ; } int main ( ) { int N = 2 ; vector < pair < int , int > > V ; V . push_back ( { 1 , 1 } ) ; V . push_back ( { 1 , 2 } ) ; V . push_back ( { 4 , 6 } ) ; V . push_back ( { 2 , 1 } ) ; V . push_back ( { 9 , 6 } ) ; V . push_back ( { 9 , 3 } ) ; V . push_back ( { 4 , 3 } ) ; MissingPoint ( V , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i, it
C++ program:
#include <bits/stdc++.h>
using namespace std ; int sign ( int x ) { if ( x > 0 ) return 1 ; else return -1 ; } int findMaxSum ( int arr [ ] , int size ) { int max_sum = 0 , pres , i , j ; for ( i = 0 ; i < size ; i ++ ) { pres = arr [ i ] ; j = i ; while ( j < size && sign ( arr [ i ] ) == sign ( arr [ j ] ) ) { pres = max ( pres , arr [ j ] ) ; j ++ ; } max_sum = max_sum + pres ; i = j - 1 ; } return max_sum ; } int main ( ) { int arr [ ] = { -2 , 8 , 3 , 8 , -4 , -15 , 5 , -2 , -3 , 1 } ; int size = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findMaxSum ( arr , size ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool groupInKConsecutive ( vector < int > & arr , int K ) { map < int , int > count ; for ( int h : arr ) { ++ count [ h ] ; } for ( auto c : count ) { int cur = c . first ; int n = c . second ; if ( n > 0 ) { for ( int i = 1 ; i < K ; ++ i ) { if ( ! count . count ( cur + i ) ) { return false ; } count [ cur + i ] -= n ; if ( count [ cur + i ] < 0 ) return false ; } } } return true ; } int main ( ) { vector < int > arr = { 1 , 2 , 3 , 6 , 2 , 3 , 4 , 7 , 8 } ; int k = 3 ; if ( groupInKConsecutive ( arr , k ) ) { cout << " True " ; } else { cout << " False " ; } }

Index/key variables: h
Accumulator variables: stdc
Iterator variables: c, h, i
C++ program:
#include <iostream>
using namespace std ; int countSubAllOnes ( string s ) { int l = 0 , r = 0 , ans = 0 ; while ( l <= r ) { if ( r == s . length ( ) ) { ans += ( ( r - l ) * ( r - l + 1 ) ) / 2 ; break ; } if ( s [ r ] == '1' ) r ++ ; else { ans += ( ( r - l ) * ( r - l + 1 ) ) / 2 ; l = r + 1 ; r ++ ; } } return ans ; } void flip ( string & s ) { for ( int i = 0 ; s [ i ] ; i ++ ) { if ( s [ i ] == '1' ) s [ i ] = '0' ; else s [ i ] = '1' ; } cout << s << endl ; } int countSubAllZerosOnes ( string s ) { int only_1s = countSubAllOnes ( s ) ; flip ( s ) ; cout << s << endl ; int only_0s = countSubAllOnes ( s ) ; return only_0s + only_1s ; } int main ( ) { string s = "011" ; cout << countSubAllZerosOnes ( s ) << endl ; return 0 ; }

Index/key variables: i, r
Accumulator variables: ans, i, r
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; bool sumSquare ( int p ) { return ( p - 1 ) % 4 == 0 ; } bool isPrime ( int n ) { if ( n <= 1 ) return false ; if ( n <= 3 ) return true ; if ( n % 2 == 0 n % 3 == 0 ) return false ; for ( int i = 5 ; i * i <= n ; i = i + 6 ) if ( n % i == 0 || n % ( i + 2 ) == 0 ) return false ; return true ; } int countOfPrimes ( int L , int R ) { int count = 0 ; for ( int i = L ; i <= R ; i ++ ) { if ( isPrime ( i ) ) { if ( sumSquare ( i ) ) count ++ ; } } return count ; } int main ( ) { int L = 5 , R = 41 ; cout << countOfPrimes ( L , R ) ; }

Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int count_elements ( int arr [ ] , int n ) { int count = 1 ; int max = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] > max ) { count += 1 ; max = arr [ i ] ; } } return count ; } int main ( ) { int arr [ ] = { 2 , 1 , 4 , 6 , 3 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << ( count_elements ( arr , n ) ) ; }

Index/key variables: i
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void subString ( char str [ ] , int n ) { int c = 0 ; for ( int len = 1 ; len <= n ; len ++ ) { for ( int i = 0 ; i <= n - len ; i ++ ) { int j = i + len - 1 ; char temp = str [ i ] , f = 0 ; if ( j == i ) { c ++ ; continue ; } int k = i + 1 ; while ( temp < str [ k ] && k <= j ) { temp = str [ k ] ; k ++ ; f = 2 ; } if ( k > j ) { c ++ ; f = 2 ; } while ( temp > str [ k ] && k <= j && f != 2 ) { k ++ ; f = 0 ; } if ( k > j && f != 2 ) { c ++ ; f = 0 ; } } } cout << c << endl ; } int main ( ) { char str [ ] = " bade " ; subString ( str , strlen ( str ) ) ; return 0 ; }

Index/key variables: i, k
Accumulator variables: c, i, k, len, stdc
Iterator variables: i, len
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findNumberDivByPowerofTwo ( int ar [ ] , int k , int n ) { int found = -1 , m = k ; while ( m > 0 ) { int l = 0 ; int r = n - 1 ; while ( l <= r ) { int mid = ( l + r ) / 2 ; if ( ar [ mid ] == m ) { found = m ; break ; } else if ( ar [ mid ] > m ) { r = mid - 1 ; } else if ( ar [ mid ] < m ) { l = mid + 1 ; } } if ( found != -1 ) { break ; } m = m / 2 ; } return found ; } int main ( ) { int arr [ ] = { 3 , 5 , 7 , 8 , 10 } ; int k = 4 , n = 5 ; cout << findNumberDivByPowerofTwo ( arr , k , n ) ; }

Index/key variables: mid
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findSubset ( int * a , int n ) { int sum = 0 ; int cnt = 0 ; vector < int > v ; for ( int i = 1 ; i <= n ; i ++ ) { if ( a [ i - 1 ] - i <= 0 ) { sum += a [ i - 1 ] - i ; cnt += 1 ; } else { v . push_back ( a [ i - 1 ] - i ) ; } } sort ( v . begin ( ) , v . end ( ) ) ; int ptr = 0 ; while ( ptr < v . size ( ) && sum + v [ ptr ] <= 0 ) { cnt += 1 ; ptr += 1 ; sum += v [ ptr ] ; } return cnt ; } int main ( ) { int arr [ ] = { 4 , 1 , 6 , 7 , 8 , 2 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << findSubset ( arr , n ) << endl ; }

Index/key variables: ptr
Accumulator variables: cnt, i, ptr, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void setElement ( int * arr , int n , int index , int x ) { arr [ index ] = x ; } int getCount ( int * arr , int n , int l , int r ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] >= l && arr [ i ] <= r ) { count ++ ; } } return count ; } void SolveQuery ( int arr [ ] , int n , vector < pair < int , pair < int , int > > > Q ) { int x ; for ( int i = 0 ; i < Q . size ( ) ; i ++ ) { if ( Q [ i ] . first == 1 ) { x = getCount ( arr , n , Q [ i ] . second . first , Q [ i ] . second . second ) ; cout << x << " ▁ " ; } else { setElement ( arr , n , Q [ i ] . second . first , Q [ i ] . second . second ) ; } } } int main ( ) { int arr [ ] = { 1 , 2 , 2 , 3 , 4 , 4 , 5 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; vector < pair < int , pair < int , int > > > Q = { { 1 , { 3 , 5 } } , { 1 , { 2 , 4 } } , { 1 , { 1 , 2 } } , { 2 , { 1 , 7 } } , { 1 , { 1 , 2 } } } ; SolveQuery ( arr , n , Q ) ; return 0 ; }

Index/key variables: i, index
Accumulator variables: count, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < int > generateSequence ( int * freq , int n ) { map < int , int > m ; int total = 0 ; for ( int i = 0 ; i < n ; i ++ ) { m [ i ] = freq [ i ] ; total += freq [ i ] ; } for ( int i = 0 ; i < n ; i ++ ) { if ( m [ i ] ) { vector < int > sequence ; auto mcopy = m ; mcopy [ i ] -- ; sequence . push_back ( i ) ; int last = i ; for ( int i = 0 ; i < total - 1 ; i ++ ) { if ( mcopy [ last - 1 ] ) { mcopy [ last - 1 ] -- ; sequence . push_back ( last - 1 ) ; last -- ; } else if ( mcopy [ last + 1 ] ) { mcopy [ last + 1 ] -- ; sequence . push_back ( last + 1 ) ; last ++ ; } else break ; } if ( sequence . size ( ) == total ) { return sequence ; } } } vector < int > empty ; return empty ; } void PrintSequence ( int freq [ ] , int n ) { vector < int > sequence = generateSequence ( freq , n ) ; if ( sequence . size ( ) == 0 ) { cout << " - 1" ; } else { for ( int i = 0 ; i < sequence . size ( ) ; i ++ ) { cout << sequence [ i ] << " ▁ " ; } } } int main ( ) { int freq [ ] = { 2 , 2 , 2 , 3 , 1 } ; int N = 5 ; PrintSequence ( freq , N ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, last, stdc, total
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void getMinimumDistance ( int a [ ] , int n ) { set < int > min_set ; set < int > max_set ; int max = 0 , min = INT_MAX ; map < int , int > frequency ; for ( int i = 0 ; i < n ; i ++ ) { frequency [ a [ i ] ] += 1 ; } for ( int i = 0 ; i < n ; i ++ ) { int count = frequency [ a [ i ] ] ; if ( count == max ) { max_set . insert ( a [ i ] ) ; } else if ( count > max ) { max_set . clear ( ) ; max = count ; max_set . insert ( a [ i ] ) ; } if ( count == min ) { min_set . insert ( a [ i ] ) ; } else if ( count < min ) { min_set . clear ( ) ; min = count ; min_set . insert ( a [ i ] ) ; } } int min_dist = INT_MAX ; int last_min_found = -1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( min_set . find ( a [ i ] ) != min_set . end ( ) ) last_min_found = i ; if ( max_set . find ( a [ i ] ) != max_set . end ( ) && last_min_found != -1 ) { if ( ( i - last_min_found ) < min_dist ) min_dist = i - last_min_found ; } } last_min_found = -1 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( min_set . find ( a [ i ] ) != min_set . end ( ) ) last_min_found = i ; if ( max_set . find ( a [ i ] ) != max_set . end ( ) && last_min_found != -1 ) { if ( ( last_min_found - i ) > min_dist ) min_dist = last_min_found - i ; } } cout << ( min_dist ) ; } int main ( ) { int arr [ ] = { 1 , 1 , 2 , 3 , 2 , 3 , 3 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; getMinimumDistance ( arr , N ) ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
#include <iostream>
using namespace std ; void printSubsequenceString ( string str , long long k ) { int n = str . size ( ) ; int i ; vector < long long > factors ; for ( long long i = 2 ; i <= sqrt ( k ) ; i ++ ) { while ( k % i == 0 ) { factors . push_back ( i ) ; k /= i ; } } if ( k > 1 ) factors . push_back ( k ) ; vector < long long > count ( n , 1 ) ; int index = 0 ; while ( factors . size ( ) > 0 ) { count [ index ++ ] *= factors . back ( ) ; factors . pop_back ( ) ; if ( index == n ) index = 0 ; } string s ; for ( i = 0 ; i < n ; i ++ ) { while ( count [ i ] -- > 0 ) { s += str [ i ] ; } } cout << s ; } int main ( ) { string str = " code " ; long long k = 20 ; printSubsequenceString ( str , k ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, index, k, s, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void changeArr ( int input [ ] , int N ) { int newArray [ N ] ; copy ( input , input + N , newArray ) ; sort ( newArray , newArray + N ) ; int i ; map < int , int > ranks ; int rank = 1 ; for ( int index = 0 ; index < N ; index ++ ) { int element = newArray [ index ] ; if ( ranks [ element ] == 0 ) { ranks [ element ] = rank ; rank ++ ; } } for ( int index = 0 ; index < N ; index ++ ) { int element = input [ index ] ; input [ index ] = ranks [ input [ index ] ] ; } } int main ( ) { int arr [ ] = { 100 , 2 , 70 , 2 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; changeArr ( arr , N ) ; cout << " [ " ; for ( int i = 0 ; i < N - 1 ; i ++ ) { cout << arr [ i ] << " , ▁ " ; } cout << arr [ N - 1 ] << " ] " ; return 0 ; }

Index/key variables: N, element, i, index
Accumulator variables: i, index, rank, stdc
Iterator variables: i, index
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findPair ( int arr [ ] , int n ) { int i , j ; if ( n < 2 ) { cout << " - 1" << endl ; } set < int > hashMap ; for ( int k = 0 ; k < n ; k ++ ) { hashMap . insert ( arr [ k ] ) ; } for ( i = 0 ; i < n - 1 ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { int sum = arr [ i ] + arr [ j ] ; if ( hashMap . find ( sum ) == hashMap . end ( ) ) { cout << " ( " << arr [ i ] << " , ▁ " << arr [ j ] << " ) " << endl ; } } } } int main ( ) { int arr [ ] = { 2 , 4 , 2 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; findPair ( arr , n ) ; return 0 ; }

Index/key variables: i, j, k
Accumulator variables: i, j, k, stdc
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
#define ll  long long int
using namespace std ; ll findLengthOfMaxSubset ( int arr [ ] , int n , int m ) { set < int > s ; int answer = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int tmp = arr [ i ] ; if ( tmp != m ) { s . insert ( tmp ) ; answer ++ ; } } int min = 1 ; while ( s . count ( min ) ) { min ++ ; } if ( min != m ) { answer = -1 ; } return answer ; } int main ( ) { int arr [ ] = { 1 , 2 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int M = 3 ; cout << findLengthOfMaxSubset ( arr , N , M ) ; return 0 ; }

Index/key variables: i
Accumulator variables: answer, i, min, stdc
Iterator variables: i