dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <iostream>
#include <climits>
using namespace std ; int maxSubArraySum ( int a [ ] , int size ) { int max_so_far = INT_MIN , max_ending_here = 0 ; for ( int i = 0 ; i < size ; i ++ ) { max_ending_here = max_ending_here + a [ i ] ; if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ; if ( max_ending_here < 0 ) max_ending_here = 0 ; } return max_so_far ; } int main ( ) { int a [ ] = { -2 , -3 , 4 , -1 , -2 , 1 , 5 , -3 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; int max_sum = maxSubArraySum ( a , n ) ; cout << " Maximum ▁ contiguous ▁ sum ▁ is ▁ " << max_sum ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; vector < vector < int > > solve ( vector < vector < int > > arr , int n ) { vector < vector < int > > ans ( n , vector < int > ( n , 0 ) ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { ans [ i ] [ j ] = arr [ j ] [ ( i + j ) % n ] ; } } return ans ; } void show ( vector < vector < int > > arr , int n ) { vector < vector < int > > res = solve ( arr , n ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { cout << res [ i ] [ j ] << " ▁ " ; } cout << endl ; } } vector < vector < int > > makeArray ( int n ) { vector < vector < int > > arr ( n , vector < int > ( n , 0 ) ) ; int c = 1 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { arr [ i ] [ j ] = c ; c ++ ; } } return arr ; } int main ( ) { int n = 5 ; vector < vector < int > > arr = makeArray ( n ) ; show ( arr , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: c, i, j, stdc
Iterator variables: i, j
C++ program:
#include <climits>
int maxSubarraySum ( int arr [ ] , int size ) { int max_ending_here = 0 , max_so_far = INT_MIN ; for ( int i = 0 ; i < size ; i ++ ) { if ( arr [ i ] <= max_ending_here + arr [ i ] ) { max_ending_here += arr [ i ] ; } else { max_ending_here = arr [ i ] ; } if ( max_ending_here > max_so_far ) max_so_far = max_ending_here ; } return max_so_far ; }

Index/key variables: i
Accumulator variables: i, max_ending_here
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findMinRooms ( string slots [ ] , int n , int m ) { int counts [ m ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = 0 ; j < m ; j ++ ) if ( slots [ i ] [ j ] == '1' ) counts [ j ] ++ ; return * max_element ( counts , counts + m ) ; } int main ( ) { int n = 3 , m = 7 ; string slots [ n ] = { "0101011" , "0011001" , "0110111" } ; cout << findMinRooms ( slots , n , m ) ; return 0 ; }

Index/key variables: i, j, m, n
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <iostream>
using namespace std ; int maxSubArraySum ( int a [ ] , int size ) { int max_so_far = a [ 0 ] ; int curr_max = a [ 0 ] ; for ( int i = 1 ; i < size ; i ++ ) { curr_max = max ( a [ i ] , curr_max + a [ i ] ) ; max_so_far = max ( max_so_far , curr_max ) ; } return max_so_far ; } int main ( ) { int a [ ] = { -2 , -3 , 4 , -1 , -2 , 1 , 5 , -3 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; int max_sum = maxSubArraySum ( a , n ) ; cout << " Maximum ▁ contiguous ▁ sum ▁ is ▁ " << max_sum ; return 0 ; }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
C++ program:
#include <iostream>
#include <climits>
using namespace std ; int maxSubArraySum ( int a [ ] , int size ) { int max_so_far = INT_MIN , max_ending_here = 0 , start = 0 , end = 0 , s = 0 ; for ( int i = 0 ; i < size ; i ++ ) { max_ending_here += a [ i ] ; if ( max_so_far < max_ending_here ) { max_so_far = max_ending_here ; start = s ; end = i ; } if ( max_ending_here < 0 ) { max_ending_here = 0 ; s = i + 1 ; } } cout << " Maximum ▁ contiguous ▁ sum ▁ is ▁ " << max_so_far << endl ; cout << " Starting ▁ index ▁ " << start << endl << " Ending ▁ index ▁ " << end << endl ; } int main ( ) { int a [ ] = { -2 , -3 , 4 , -1 , -2 , 1 , 5 , -3 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; int max_sum = maxSubArraySum ( a , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, max_ending_here
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; void countCurrency ( int amount ) { int notes [ 9 ] = { 2000 , 500 , 200 , 100 , 50 , 20 , 10 , 5 , 1 } ; int noteCounter [ 9 ] = { 0 } ; for ( int i = 0 ; i < 9 ; i ++ ) { if ( amount >= notes [ i ] ) { noteCounter [ i ] = amount / notes [ i ] ; amount = amount - noteCounter [ i ] * notes [ i ] ; } } cout << " Currency ▁ Count ▁ - > " << endl ; for ( int i = 0 ; i < 9 ; i ++ ) { if ( noteCounter [ i ] != 0 ) { cout << notes [ i ] << " ▁ : ▁ " << noteCounter [ i ] << endl ; } } } int main ( ) { int amount = 868 ; countCurrency ( amount ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minSum ( int A [ ] , int n ) { int min_val = * min_element ( A , A + n ) ; return ( min_val * ( n - 1 ) ) ; } int main ( ) { int A [ ] = { 3 , 6 , 2 , 8 , 7 , 5 } ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << minSum ( A , n ) ; return 0 ; }

Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; void NextFit ( int blockSize [ ] , int m , int processSize [ ] , int n ) { int allocation [ n ] , j = 0 ; memset ( allocation , -1 , sizeof ( allocation ) ) ; for ( int i = 0 ; i < n ; i ++ ) { while ( j < m ) { if ( blockSize [ j ] >= processSize [ i ] ) { allocation [ i ] = j ; blockSize [ j ] -= processSize [ i ] ; break ; } j = ( j + 1 ) % m ; } } cout << " Process No . Process Size Block no . " ; for ( int i = 0 ; i < n ; i ++ ) { cout << " ▁ " << i + 1 << " TABSYMBOL TABSYMBOL " << processSize [ i ] << " TABSYMBOL TABSYMBOL " ; if ( allocation [ i ] != -1 ) cout << allocation [ i ] + 1 ; else cout << " Not ▁ Allocated " ; cout << endl ; } } int main ( ) { int blockSize [ ] = { 5 , 10 , 20 } ; int processSize [ ] = { 10 , 20 , 5 } ; int m = sizeof ( blockSize ) / sizeof ( blockSize [ 0 ] ) ; int n = sizeof ( processSize ) / sizeof ( processSize [ 0 ] ) ; NextFit ( blockSize , m , processSize , n ) ; return 0 ; }

Index/key variables: i, j, n
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int main ( ) { int price [ ] = { 2 , 30 , 15 , 10 , 8 , 25 , 80 } ; int n = 7 ; int profit = 0 ; for ( int i = 1 ; i < n ; i ++ ) { int sub = price [ i ] - price [ i - 1 ] ; if ( sub > 0 ) profit += sub ; } cout << " Maximum ▁ Profit = " << profit ; return 0 ; }

Index/key variables: i
Accumulator variables: i, profit
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; struct Node * left , * right ; } ; struct Node * newnode ( int data ) { struct Node * node = new Node ; node -> data = data ; node -> left = node -> right = NULL ; return ( node ) ; } bool printPathUtil ( Node * node , unordered_set < int > & s , int root_data ) { if ( node == NULL ) return false ; int rem = root_data - node -> data ; if ( s . find ( rem ) != s . end ( ) ) return true ; s . insert ( node -> data ) ; bool res = printPathUtil ( node -> left , s , root_data ) || printPathUtil ( node -> right , s , root_data ) ; s . erase ( node -> data ) ; return res ; } bool isPathSum ( Node * root ) { unordered_set < int > s ; return printPathUtil ( root -> left , s , root -> data ) || printPathUtil ( root -> right , s , root -> data ) ; } int main ( ) { struct Node * root = newnode ( 8 ) ; root -> left = newnode ( 5 ) ; root -> right = newnode ( 4 ) ; root -> left -> left = newnode ( 9 ) ; root -> left -> right = newnode ( 7 ) ; root -> left -> right -> left = newnode ( 1 ) ; root -> left -> right -> right = newnode ( 12 ) ; root -> left -> right -> right -> right = newnode ( 2 ) ; root -> right -> right = newnode ( 11 ) ; root -> right -> right -> left = newnode ( 3 ) ; isPathSum ( root ) ? cout << " Yes " : cout << " No " ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void findMinAvgSubarray ( int arr [ ] , int n , int k ) { if ( n < k ) return ; int res_index = 0 ; int curr_sum = 0 ; for ( int i = 0 ; i < k ; i ++ ) curr_sum += arr [ i ] ; int min_sum = curr_sum ; for ( int i = k ; i < n ; i ++ ) { curr_sum += arr [ i ] - arr [ i - k ] ; if ( curr_sum < min_sum ) { min_sum = curr_sum ; res_index = ( i - k + 1 ) ; } } cout << " Subarray ▁ between ▁ [ " << res_index << " , ▁ " << res_index + k - 1 << " ] ▁ has ▁ minimum ▁ average " ; } int main ( ) { int arr [ ] = { 3 , 7 , 90 , 20 , 10 , 50 , 40 } ; int k = 3 ; int n = sizeof arr / sizeof arr [ 0 ] ; findMinAvgSubarray ( arr , n , k ) ; return 0 ; }

Index/key variables: i
Accumulator variables: curr_sum, i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; const int seg [ 10 ] = { 6 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 } ; int computeSegment ( int x ) { if ( x == 0 ) return seg [ 0 ] ; int count = 0 ; while ( x ) { count += seg [ x % 10 ] ; x /= 10 ; } return count ; } int elementMinSegment ( int arr [ ] , int n ) { int minseg = computeSegment ( arr [ 0 ] ) ; int minindex = 0 ; for ( int i = 1 ; i < n ; i ++ ) { int temp = computeSegment ( arr [ i ] ) ; if ( temp < minseg ) { minseg = temp ; minindex = i ; } } return arr [ minindex ] ; } int main ( ) { int arr [ ] = { 489 , 206 , 745 , 123 , 756 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << elementMinSegment ( arr , n ) << endl ; return 0 ; }

Index/key variables: i, minindex
Accumulator variables: count, i, stdc, x
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; void findLargest ( int m , int s ) { if ( s == 0 ) { ( m == 1 ) ? cout << " Largest ▁ number ▁ is ▁ " << 0 : cout << " Not ▁ possible " ; return ; } if ( s > 9 * m ) { cout << " Not ▁ possible " ; return ; } int res [ m ] ; for ( int i = 0 ; i < m ; i ++ ) { if ( s >= 9 ) { res [ i ] = 9 ; s -= 9 ; } else { res [ i ] = s ; s = 0 ; } } cout << " Largest ▁ number ▁ is ▁ " ; for ( int i = 0 ; i < m ; i ++ ) cout << res [ i ] ; } int main ( ) { int s = 9 , m = 2 ; findLargest ( m , s ) ; return 0 ; }

Index/key variables: i, m
Accumulator variables: i, s
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int min ( int a , int b ) { return ( a < b ) ? a : b ; } int findOverlappingPair ( string str1 , string str2 , string & str ) { int max = INT_MIN ; int len1 = str1 . length ( ) ; int len2 = str2 . length ( ) ; for ( int i = 1 ; i <= min ( len1 , len2 ) ; i ++ ) { if ( str1 . compare ( len1 - i , i , str2 , 0 , i ) == 0 ) { if ( max < i ) { max = i ; str = str1 + str2 . substr ( i ) ; } } } for ( int i = 1 ; i <= min ( len1 , len2 ) ; i ++ ) { if ( str1 . compare ( 0 , i , str2 , len2 - i , i ) == 0 ) { if ( max < i ) { max = i ; str = str2 + str1 . substr ( i ) ; } } } return max ; } string findShortestSuperstring ( string arr [ ] , int len ) { while ( len != 1 ) { int max = INT_MIN ; int l , r ; string resStr ; for ( int i = 0 ; i < len ; i ++ ) { for ( int j = i + 1 ; j < len ; j ++ ) { string str ; int res = findOverlappingPair ( arr [ i ] , arr [ j ] , str ) ; if ( max < res ) { max = res ; resStr . assign ( str ) ; l = i , r = j ; } } } len -- ; if ( max == INT_MIN ) arr [ 0 ] += arr [ len ] ; else { arr [ l ] = resStr ; arr [ r ] = arr [ len ] ; } } return arr [ 0 ] ; } int main ( ) { string arr [ ] = { " catgc " , " ctaagt " , " gcta " , " ttca " , " atgcatc " } ; int len = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " The ▁ Shortest ▁ Superstring ▁ is ▁ " << findShortestSuperstring ( arr , len ) ; return 0 ; }

Index/key variables: i, j, l, len, r
Accumulator variables: i, j, len, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minJumps ( int arr [ ] , int n ) { if ( n == 1 ) return 0 ; int res = INT_MAX ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( i + arr [ i ] >= n - 1 ) { int sub_res = minJumps ( arr , i + 1 ) ; if ( sub_res != INT_MAX ) res = min ( res , sub_res + 1 ) ; } } return res ; } int main ( ) { int arr [ ] = { 1 , 3 , 6 , 3 , 2 , 3 , 6 , 8 , 9 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Minimum ▁ number ▁ of ▁ jumps ▁ to " ; cout << " ▁ reach ▁ the ▁ end ▁ is ▁ " << minJumps ( 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 dp [ 1001 ] [ 3001 ] ; int recBananaCnt ( int A , int B , int C ) { if ( B <= A ) { return 0 ; } if ( B <= C ) { return B - A ; } if ( A == 0 ) { return B ; } if ( dp [ A ] [ B ] != -1 ) { return dp [ A ] [ B ] ; } int maxCount = INT_MIN ; int tripCount = B % C == 0 ? ( ( 2 * B ) / C ) - 1 : ( ( 2 * B ) / C ) + 1 ; for ( int i = 1 ; i <= A ; i ++ ) { int curCount = recBananaCnt ( A - i , B - tripCount * i , C ) ; if ( curCount > maxCount ) { maxCount = curCount ; dp [ A ] [ B ] = maxCount ; } } return maxCount ; } int maxBananaCnt ( int A , int B , int C ) { memset ( dp , -1 , sizeof ( dp ) ) ; return recBananaCnt ( A , B , C ) ; } int main ( ) { int A = 1000 ; int B = 3000 ; int C = 1000 ; cout << maxBananaCnt ( A , B , C ) ; return 0 ; }

Index/key variables: A, B
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int calculate ( int position , int used , int unused , int P , int M , vector < vector < vector < int > > > & dp ) { if ( position == P ) { return unused == 0 ? 1 : 0 ; } if ( dp [ position ] [ used ] [ unused ] != -1 ) return dp [ position ] [ used ] [ unused ] ; int result = 0 ; if ( unused > 0 ) { result += calculate ( position + 1 , used + 1 , unused - 1 , P , M , dp ) * unused ; } if ( used > M ) { result += calculate ( position + 1 , used , unused , P , M , dp ) * ( used - M ) ; } return dp [ position ] [ used ] [ unused ] = result ; } int solve ( int N , int P , int M ) { vector < vector < vector < int > > > dp ( 101 , vector < vector < int > > ( 101 , vector < int > ( 101 , -1 ) ) ) ; return calculate ( 0 , 0 , N , P , M , dp ) ; } int main ( ) { int N = 2 , M = 0 , P = 3 ; cout << solve ( N , P , M ) ; }

Index/key variables: position, unused, used
Accumulator variables: result, stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int minJumps ( int arr [ ] , int n ) { int * jumps = new int [ n ] ; int min ; jumps [ n - 1 ] = 0 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( arr [ i ] == 0 ) jumps [ i ] = INT_MAX ; else if ( arr [ i ] >= n - i - 1 ) jumps [ i ] = 1 ; else { min = INT_MAX ; for ( int j = i + 1 ; j < n && j <= arr [ i ] + i ; j ++ ) { if ( min > jumps [ j ] ) min = jumps [ j ] ; } if ( min != INT_MAX ) jumps [ i ] = min + 1 ; else jumps [ i ] = min ; } } return jumps [ 0 ] ; } int main ( ) { int arr [ ] = { 1 , 3 , 6 , 1 , 0 , 9 } ; int size = sizeof ( arr ) / sizeof ( int ) ; cout << " Minimum ▁ number ▁ of ▁ jumps ▁ to ▁ reach " << " ▁ end ▁ is ▁ " << minJumps ( arr , size ) ; 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 ; int dp [ 100 ] [ 1000 ] ; bool prime [ 1005 ] ; void SieveOfEratosthenes ( int n ) { prime [ 0 ] = prime [ 1 ] = false ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i <= n ; i += p ) prime [ i ] = false ; } } } int countOfNumbers ( int index , int sum , int N ) { if ( index == N + 1 ) { if ( prime [ sum ] == true ) { return 1 ; } return 0 ; } int & val = dp [ index ] [ sum ] ; if ( val != -1 ) { return val ; } val = 0 ; if ( index == 1 ) { for ( int digit = ( N == 1 ? 0 : 1 ) ; digit <= 9 ; ++ digit ) { val += countOfNumbers ( index + 1 , sum + digit , N ) ; } } else { for ( int digit = 0 ; digit <= 9 ; ++ digit ) { val += countOfNumbers ( index + 1 , sum + digit , N ) ; } } return val ; } int main ( ) { memset ( dp , -1 , sizeof dp ) ; memset ( prime , true , sizeof ( prime ) ) ; SieveOfEratosthenes ( 1000 ) ; int N = 6 ; cout << countOfNumbers ( 1 , 0 , N ) ; return 0 ; }

Index/key variables: i, index, p, sum
Accumulator variables: i, p, stdc, val
Iterator variables: digit, i, p
C++ program:
#include <bits/stdc++.h>
using namespace std ; map < string , int > memo ; int dfs ( int V [ ] , int left , int K ) { int q = 0 ; string key = " " ; for ( int i = 0 ; i < K ; i ++ ) { key = key + to_string ( V [ i ] ) ; } key += to_string ( left ) ; if ( memo . find ( key ) != memo . end ( ) ) return memo [ key ] ; else if ( left == 0 ) { for ( int i = 1 ; i < K ; ++ i ) if ( V [ i ] > 0 ) { V [ i ] -- ; q = max ( q , 1 + dfs ( V , K - i , K ) ) ; V [ i ] ++ ; } } else { for ( int i = 1 ; i < K ; ++ i ) { if ( V [ i ] > 0 ) { V [ i ] -- ; int nleft = i <= left ? left - i : K + left - i ; q = max ( q , dfs ( V , nleft , K ) ) ; V [ i ] ++ ; } } } if ( memo . find ( key ) != memo . end ( ) ) memo [ key ] = q ; else memo [ key ] = q ; return q ; } int maxGroups ( int K , int arr [ ] ) { int V [ K ] ; memset ( V , 0 , sizeof ( V ) ) ; for ( int i = 0 ; i < 6 ; i ++ ) V [ arr [ i ] % K ] ++ ; int ans = V [ 0 ] + dfs ( V , 0 , K ) ; return ans ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 , 6 } ; int K = 3 ; cout << maxGroups ( K , arr ) ; return 0 ; }

Index/key variables: K, i, key
Accumulator variables: i, key, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int alternatingSum ( int arr [ ] , int n ) { int sum = 0 ; int sumSoFar = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( i % 2 == 1 ) { sumSoFar -= arr [ i ] ; } else { sumSoFar = max ( sumSoFar + arr [ i ] , arr [ i ] ) ; } sum = max ( sum , sumSoFar ) ; } sumSoFar = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( i % 2 == 0 ) { sumSoFar -= arr [ i ] ; } else { sumSoFar = max ( sumSoFar + arr [ i ] , arr [ i ] ) ; } sum = max ( sum , sumSoFar ) ; } return sum ; } int main ( ) { int arr [ ] = { -4 , -10 , 3 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; int ans = alternatingSum ( arr , n ) ; cout << ans << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc, sumSoFar
Iterator variables: i
C++ program:
#include <iostream>
using namespace std ; int smallestSubWithSum ( int arr [ ] , int n , int x ) { int curr_sum = 0 , min_len = n + 1 ; int start = 0 , end = 0 ; while ( end < n ) { while ( curr_sum <= x && end < n ) curr_sum += arr [ end ++ ] ; while ( curr_sum > x && start < n ) { if ( end - start < min_len ) min_len = end - start ; curr_sum -= arr [ start ++ ] ; } } return min_len ; } int main ( ) { int arr1 [ ] = { 1 , 4 , 45 , 6 , 10 , 19 } ; int x = 51 ; int n1 = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; int res1 = smallestSubWithSum ( arr1 , n1 , x ) ; ( res1 == n1 + 1 ) ? cout << " Not ▁ possible STRNEWLINE " : cout << res1 << endl ; int arr2 [ ] = { 1 , 10 , 5 , 2 , 7 } ; int n2 = sizeof ( arr2 ) / sizeof ( arr2 [ 0 ] ) ; x = 9 ; int res2 = smallestSubWithSum ( arr2 , n2 , x ) ; ( res2 == n2 + 1 ) ? cout << " Not ▁ possible STRNEWLINE " : cout << res2 << endl ; int arr3 [ ] = { 1 , 11 , 100 , 1 , 0 , 200 , 3 , 2 , 1 , 250 } ; int n3 = sizeof ( arr3 ) / sizeof ( arr3 [ 0 ] ) ; x = 280 ; int res3 = smallestSubWithSum ( arr3 , n3 , x ) ; ( res3 == n3 + 1 ) ? cout << " Not ▁ possible STRNEWLINE " : cout << res3 << endl ; return 0 ; }

Accumulator variables: curr_sum, end, start
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int data ; Node * left , * right ; } ; Node * getNode ( int data ) { Node * newNode = ( Node * ) malloc ( sizeof ( Node ) ) ; newNode -> data = data ; newNode -> left = newNode -> right = NULL ; return newNode ; } void sumOfLongRootToLeafPath ( Node * root , int sum , int len , int & maxLen , int & maxSum ) { if ( ! root ) { if ( maxLen < len ) { maxLen = len ; maxSum = sum ; } else if ( maxLen == len && maxSum < sum ) maxSum = sum ; return ; } sumOfLongRootToLeafPath ( root -> left , sum + root -> data , len + 1 , maxLen , maxSum ) ; sumOfLongRootToLeafPath ( root -> right , sum + root -> data , len + 1 , maxLen , maxSum ) ; } int sumOfLongRootToLeafPathUtil ( Node * root ) { if ( ! root ) return 0 ; int maxSum = INT_MIN , maxLen = 0 ; sumOfLongRootToLeafPath ( root , 0 , 0 , maxLen , maxSum ) ; return maxSum ; } int main ( ) { Node * root = getNode ( 4 ) ; root -> left = getNode ( 2 ) ; root -> right = getNode ( 5 ) ; root -> left -> left = getNode ( 7 ) ; root -> left -> right = getNode ( 1 ) ; root -> right -> left = getNode ( 2 ) ; root -> right -> right = getNode ( 3 ) ; root -> left -> right -> left = getNode ( 6 ) ; cout << " Sum ▁ = ▁ " << sumOfLongRootToLeafPathUtil ( root ) ; return 0 ; }

Accumulator variables: stdc
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int numberOfArrays ( int n , int l ) { int dp [ l + 1 ] [ n + 1 ] ; memset ( dp , 0 , sizeof dp ) ; dp [ 0 ] [ 1 ] = 1 ; for ( int i = 0 ; i < l ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { for ( int k = j ; k <= n ; k += j ) { dp [ i + 1 ] [ k ] += dp [ i ] [ j ] ; } } } int ans = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { ans += dp [ l ] [ i ] ; } return ans ; } int main ( ) { int N = 2 , L = 4 ; cout << numberOfArrays ( N , L ) ; return 0 ; }

Index/key variables: i, j, k, l
Accumulator variables: ans, i, j, k, stdc
Iterator variables: i, j, k
C++ program:
#include <bits/stdc++.h>
using namespace std ; int countMinOperations ( unsigned int target [ ] , int n ) { int result = 0 ; while ( 1 ) { int zero_count = 0 ; int i ; for ( i = 0 ; i < n ; i ++ ) { if ( target [ i ] & 1 ) break ; else if ( target [ i ] == 0 ) zero_count ++ ; } if ( zero_count == n ) return result ; if ( i == n ) { for ( int j = 0 ; j < n ; j ++ ) target [ j ] = target [ j ] / 2 ; result ++ ; } for ( int j = i ; j < n ; j ++ ) { if ( target [ j ] & 1 ) { target [ j ] -- ; result ++ ; } } } } int main ( ) { unsigned int arr [ ] = { 16 , 16 , 16 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Minimum ▁ number ▁ of ▁ steps ▁ required ▁ to ▁ " " get ▁ the ▁ given ▁ target ▁ array ▁ is ▁ " << countMinOperations ( arr , n ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: i, j, result, stdc, zero_count
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int recursiveChoosing ( int arr [ ] , int start , int M , map < pair < int , int > , int > dp , int N ) { pair < int , int > key ( start , M ) ; if ( start >= N ) { return 0 ; } if ( N - start <= 2 * M ) { int Sum = 0 ; for ( int i = start ; i < N ; i ++ ) { Sum = Sum + arr [ i ] ; } return Sum ; } int sum = 0 ; for ( int i = start ; i < N ; i ++ ) { sum = sum + arr [ i ] ; } int total = sum ; if ( dp . find ( key ) != dp . end ( ) ) { return dp [ key ] ; } int psa = 0 ; for ( int x = 1 ; x < 2 * M + 1 ; x ++ ) { int psb = recursiveChoosing ( arr , start + x , max ( x , M ) , dp , N ) ; psa = max ( psa , total - psb ) ; } dp [ key ] = psa ; return dp [ key ] ; } int main ( ) { int arr [ ] = { 2 , 7 , 9 , 4 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; map < pair < int , int > , int > dp ; cout << recursiveChoosing ( arr , 0 , 1 , dp , N ) ; return 0 ; }

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