dhyuti-n/xlcost-variable-roles huggingface dataset:
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findSubset ( long long int arr [ ] , int n , long long int k ) { vector < long long int > vect1 , vect2 , subset1 , subset2 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > k ) continue ; if ( i <= n / 2 ) vect1 . push_back ( arr [ i ] ) ; else vect2 . push_back ( arr [ i ] ) ; } for ( int i = 0 ; i < ( 1 << vect1 . size ( ) ) ; i ++ ) { long long value = 1 ; for ( int j = 0 ; j < vect1 . size ( ) ; j ++ ) { if ( i & ( 1 << j ) ) value *= vect1 [ j ] ; } if ( value <= k ) subset1 . push_back ( value ) ; } for ( int i = 0 ; i < ( 1 << vect2 . size ( ) ) ; i ++ ) { long long value = 1 ; for ( int j = 0 ; j < vect2 . size ( ) ; j ++ ) { if ( i & ( 1 << j ) ) value *= vect2 [ j ] ; } if ( value <= k ) subset2 . push_back ( value ) ; } sort ( subset2 . begin ( ) , subset2 . end ( ) ) ; long long count = 0 ; for ( int i = 0 ; i < subset1 . size ( ) ; i ++ ) count += upper_bound ( subset2 . begin ( ) , subset2 . end ( ) , ( k / subset1 [ i ] ) ) - subset2 . begin ( ) ; count -- ; return count ; } int main ( ) { long long int arr [ ] = { 4 , 2 , 3 , 6 , 5 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; long long int k = 25 ; cout << findSubset ( arr , n , k ) ; return 0 ; }

Index/key variables: i, j
Accumulator variables: count, i, j, stdc, value
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int dp [ 100 ] [ 3 ] ; int maxSum ( int * arr , int i , int n , int prev , bool is_selected ) { if ( i == n ) { return 0 ; } int cur = abs ( arr [ i ] ) % 2 ; if ( dp [ i ] [ prev ] != -1 ) { return dp [ i ] [ prev ] ; } if ( i == n - 1 && is_selected == 0 ) return dp [ i ] [ prev ] = arr [ i ] ; if ( cur != prev ) { dp [ i ] [ prev ] = arr [ i ] + maxSum ( arr , i + 1 , n , cur , 1 ) ; } dp [ i ] [ prev ] = max ( dp [ i ] [ prev ] , maxSum ( arr , i + 1 , n , prev , is_selected ) ) ; return dp [ i ] [ prev ] ; } void maxSumUtil ( int arr [ ] , int n ) { memset ( dp , -1 , sizeof ( dp ) ) ; cout << maxSum ( arr , 0 , n , 2 , 0 ) ; } int main ( ) { int arr [ ] = { 1 , 2 , 6 , 8 , -5 , 10 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; maxSumUtil ( arr , N ) ; return 0 ; }

Index/key variables: i, prev
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findMinOps ( int arr [ ] , int n ) { int ans = 0 ; for ( int i = 0 , j = n - 1 ; i <= j ; ) { if ( arr [ i ] == arr [ j ] ) { i ++ ; j -- ; } else if ( arr [ i ] > arr [ j ] ) { j -- ; arr [ j ] += arr [ j + 1 ] ; ans ++ ; } else { i ++ ; arr [ i ] += arr [ i - 1 ] ; ans ++ ; } } return ans ; } int main ( ) { int arr [ ] = { 1 , 4 , 5 , 9 , 1 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Count ▁ of ▁ minimum ▁ operations ▁ is ▁ " << findMinOps ( arr , n ) << endl ; return 0 ; }

Index/key variables: i, j
Accumulator variables: ans, i, j, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findSmallest ( int arr [ ] , int n ) { int res = 1 ; for ( int i = 0 ; i < n && arr [ i ] <= res ; i ++ ) res = res + arr [ i ] ; return res ; } int main ( ) { int arr1 [ ] = { 1 , 3 , 4 , 5 } ; int n1 = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; cout << findSmallest ( arr1 , n1 ) << endl ; int arr2 [ ] = { 1 , 2 , 6 , 10 , 11 , 15 } ; int n2 = sizeof ( arr2 ) / sizeof ( arr2 [ 0 ] ) ; cout << findSmallest ( arr2 , n2 ) << endl ; int arr3 [ ] = { 1 , 1 , 1 , 1 } ; int n3 = sizeof ( arr3 ) / sizeof ( arr3 [ 0 ] ) ; cout << findSmallest ( arr3 , n3 ) << endl ; int arr4 [ ] = { 1 , 1 , 3 , 4 } ; int n4 = sizeof ( arr4 ) / sizeof ( arr4 [ 0 ] ) ; cout << findSmallest ( arr4 , n4 ) << endl ; return 0 ; }

Index/key variables: i
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; unordered_set < int > s ; void countXOR ( int arr [ ] , int comb [ ] , int start , int end , int index , int r ) { if ( index == r ) { int new_xor = 0 ; for ( int j = 0 ; j < r ; j ++ ) { new_xor ^= comb [ j ] ; } s . insert ( new_xor ) ; return ; } for ( int i = start ; i <= end && end - i + 1 >= r - index ; i ++ ) { comb [ index ] = arr [ i ] ; countXOR ( arr , comb , i + 1 , end , index + 1 , r ) ; } } void maxSizeSet ( int arr [ ] , int N ) { for ( int r = 2 ; r <= N ; r ++ ) { int comb [ r + 1 ] ; countXOR ( arr , comb , 0 , N - 1 , 0 , r ) ; } cout << s . size ( ) << endl ; } int main ( ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; maxSizeSet ( arr , N ) ; return 0 ; }

Index/key variables: i, index, j
Accumulator variables: i, j, new_xor, r, stdc
Iterator variables: i, j, r
C++ program:
#include <bits/stdc++.h>
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 ; } } return ( end - start + 1 ) ; } int main ( ) { int a [ ] = { -2 , -3 , 4 , -1 , -2 , 1 , 5 , -3 } ; int n = sizeof ( a ) / sizeof ( a [ 0 ] ) ; cout << maxSubArraySum ( a , n ) ; return 0 ; }

Index/key variables: i
Accumulator variables: i, max_ending_here, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int LongSubarrSeq ( int arr1 [ ] , int arr2 [ ] , int M , int N ) { int maxL = 0 ; int DP [ M + 1 ] [ N + 1 ] ; for ( int i = 1 ; i <= M ; i ++ ) { for ( int j = 1 ; j <= N ; j ++ ) { if ( arr1 [ i - 1 ] == arr2 [ j - 1 ] ) { DP [ i ] [ j ] = 1 + DP [ i - 1 ] [ j - 1 ] ; } else { DP [ i ] [ j ] = DP [ i ] [ j - 1 ] ; } } } for ( int i = 1 ; i <= M ; i ++ ) { for ( int j = 1 ; j <= N ; j ++ ) { maxL = max ( maxL , DP [ i ] [ j ] ) ; } } return maxL ; } int main ( ) { int arr1 [ ] = { 4 , 2 , 3 , 1 , 5 , 6 } ; int M = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; int arr2 [ ] = { 3 , 1 , 4 , 6 , 5 , 2 } ; int N = sizeof ( arr2 ) / sizeof ( arr2 [ 0 ] ) ; cout << LongSubarrSeq ( arr1 , arr2 , M , N ) << endl ; 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 ; int findMinDiff ( int arr [ ] , int n ) { int diff = INT_MAX ; for ( int i = 0 ; i < n - 1 ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) if ( abs ( arr [ i ] - arr [ j ] ) < diff ) diff = abs ( arr [ i ] - arr [ j ] ) ; return diff ; } int main ( ) { int arr [ ] = { 1 , 5 , 3 , 19 , 18 , 25 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Minimum ▁ difference ▁ is ▁ " << findMinDiff ( arr , 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 ; int findLongestSubstring ( int posA , int posB , string & A , string & B , bool canSkip , int n , vector < vector < vector < int > > > & dp ) { if ( posA >= n posB >= n ) { return 0 ; } if ( dp [ posA ] [ posB ] [ canSkip ] != -1 ) { return dp [ posA ] [ posB ] [ canSkip ] ; } int op1 = 0 ; int op2 = 0 ; int op3 = 0 ; if ( A [ posA ] == B [ posB ] ) { op1 = 1 + findLongestSubstring ( posA + 1 , posB + 1 , A , B , 0 , n , dp ) ; } if ( canSkip ) { op2 = findLongestSubstring ( posA + 1 , posB , A , B , canSkip , n , dp ) ; } op3 = findLongestSubstring ( posA , posB + 1 , A , B , canSkip , n , dp ) ; return dp [ posA ] [ posB ] [ canSkip ] = max ( op1 , max ( op2 , op3 ) ) ; } void minOperations ( string A , string B , int N ) { vector < vector < vector < int > > > dp ( N , vector < vector < int > > ( N , vector < int > ( 2 , -1 ) ) ) ; cout << N - findLongestSubstring ( 0 , 0 , A , B , 1 , N , dp ) ; } int main ( ) { string A = " abab " ; string B = " baba " ; int N = A . size ( ) ; minOperations ( A , B , N ) ; return 0 ; }

Index/key variables: canSkip, posA, posB
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define MOD  1000000007
int dp [ 5005 ] [ 12 ] [ 12 ] ; int findCountUtil ( int N , int maxDigit [ ] , int position = 0 , int previous = 0 , int count = 1 ) { if ( position == N ) { return 1 ; } int & ans = dp [ position ] [ previous ] [ count ] ; if ( ans != -1 ) { return ans ; } ans = 0 ; for ( int i = 0 ; i <= 9 ; ++ i ) { if ( count == 0 && previous != i ) { ans = ( ans + ( findCountUtil ( N , maxDigit , position + 1 , i , maxDigit [ i ] - 1 ) ) % MOD ) % MOD ; } else if ( count != 0 ) { ans = ( ans + ( findCountUtil ( N , maxDigit , position + 1 , i , ( previous == i && position != 0 ) ? count - 1 : maxDigit [ i ] - 1 ) ) % MOD ) % MOD ; } } return ans ; } void findCount ( int N , int maxDigit [ ] ) { int ans = findCountUtil ( N , maxDigit ) ; cout << ans ; } int main ( ) { int N = 2 ; int maxDigit [ 10 ] = { 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 } ; memset ( dp , -1 , sizeof ( dp ) ) ; findCount ( N , maxDigit ) ; return 0 ; }

Index/key variables: count, i, position, previous
Accumulator variables: stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findMinDiff ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; int diff = INT_MAX ; for ( int i = 0 ; i < n - 1 ; i ++ ) if ( arr [ i + 1 ] - arr [ i ] < diff ) diff = arr [ i + 1 ] - arr [ i ] ; return diff ; } int main ( ) { int arr [ ] = { 1 , 5 , 3 , 19 , 18 , 25 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << " Minimum ▁ difference ▁ is ▁ " << findMinDiff ( 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 main ( ) { int a = 2 , b = 10 ; int size = abs ( b - a ) + 1 ; int * array = new int [ size ] ; for ( int i = a ; i <= b ; i ++ ) if ( i % 2 == 0 i % 5 == 0 ) array [ i - a ] = 1 ; cout << " MULTIPLES ▁ of ▁ 2 ▁ and ▁ 5 : STRNEWLINE " ; for ( int i = a ; i <= b ; i ++ ) if ( array [ i - a ] == 1 ) cout << i << " ▁ " ; return 0 ; }

Index/key variables: size
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <stdio.h>
#include <stdlib.h>
int max ( int l , int r ) { return ( l > r ? l : r ) ; } struct Node { int data ; struct Node * left , * right ; } ; struct Node * newNode ( int data ) { struct Node * node = ( struct Node * ) malloc ( sizeof ( struct Node ) ) ; node -> data = data ; node -> left = node -> right = NULL ; return node ; } void print ( struct Node * root ) { if ( root != NULL ) { print ( root -> left ) ; printf ( " % d ▁ " , root -> data ) ; print ( root -> right ) ; } } struct Node * pruneUtil ( struct Node * root , int k , int * sum ) { if ( root == NULL ) return NULL ; int lsum = * sum + ( root -> data ) ; int rsum = lsum ; root -> left = pruneUtil ( root -> left , k , & lsum ) ; root -> right = pruneUtil ( root -> right , k , & rsum ) ; * sum = max ( lsum , rsum ) ; if ( * sum < k ) { free ( root ) ; root = NULL ; } return root ; } struct Node * prune ( struct Node * root , int k ) { int sum = 0 ; return pruneUtil ( root , k , & sum ) ; } int main ( ) { int k = 45 ; struct Node * root = newNode ( 1 ) ; root -> left = newNode ( 2 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 5 ) ; root -> right -> left = newNode ( 6 ) ; root -> right -> right = newNode ( 7 ) ; root -> left -> left -> left = newNode ( 8 ) ; root -> left -> left -> right = newNode ( 9 ) ; root -> left -> right -> left = newNode ( 12 ) ; root -> right -> right -> left = newNode ( 10 ) ; root -> right -> right -> left -> right = newNode ( 11 ) ; root -> left -> left -> right -> left = newNode ( 13 ) ; root -> left -> left -> right -> right = newNode ( 14 ) ; root -> left -> left -> right -> right -> left = newNode ( 15 ) ; printf ( " Tree ▁ before ▁ truncation STRNEWLINE " ) ; print ( root ) ; root = prune ( root , k ) ; printf ( " Tree after truncation " print ( root ) ; return 0 ; }

Class/struct names: Node
C++ program:
#include <iostream>
using namespace std ; struct Node { int data ; struct Node * left , * right ; Node ( int data ) { this -> data = data ; left = right = NULL ; } } ; void printPostorder ( struct Node * node ) { if ( node == NULL ) return ; printPostorder ( node -> left ) ; printPostorder ( node -> right ) ; cout << node -> data << " ▁ " ; } void printInorder ( struct Node * node ) { if ( node == NULL ) return ; printInorder ( node -> left ) ; cout << node -> data << " ▁ " ; printInorder ( node -> right ) ; } void printPreorder ( struct Node * node ) { if ( node == NULL ) return ; cout << node -> data << " ▁ " ; printPreorder ( node -> left ) ; printPreorder ( node -> right ) ; } int main ( ) { struct Node * root = new Node ( 1 ) ; root -> left = new Node ( 2 ) ; root -> right = new Node ( 3 ) ; root -> left -> left = new Node ( 4 ) ; root -> left -> right = new Node ( 5 ) ; cout << " Preorder traversal of binary tree is " ; printPreorder ( root ) ; cout << " Inorder traversal of binary tree is " ; printInorder ( root ) ; cout << " Postorder traversal of binary tree is " ; printPostorder ( root ) ; return 0 ; }

Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; void swapEvenOdd ( int arr [ ] , int N ) { stack < pair < int , int > > stack ; stack . push ( { 0 , arr [ 0 ] } ) ; for ( int i = 1 ; i < N ; i ++ ) { if ( ! stack . empty ( ) ) { if ( arr [ i ] % 2 != stack . top ( ) . second % 2 ) { pair < int , int > pop = stack . top ( ) ; stack . pop ( ) ; int index = pop . first , val = pop . second ; arr [ index ] = arr [ i ] ; arr [ i ] = val ; } else stack . push ( { i , arr [ i ] } ) ; } else stack . push ( { i , arr [ i ] } ) ; } for ( int i = 0 ; i < N ; i ++ ) cout << arr [ i ] << " ▁ " ; } int main ( ) { int arr [ ] = { 1 , 3 , 2 , 4 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; swapEvenOdd ( arr , N ) ; return 0 ; }

Index/key variables: i, index
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define M  100
int mxSubSum ( int i , int * arr , int j , int dp [ ] [ M ] ) { if ( i == 0 ) { return dp [ i ] [ j ] = max ( 0 , arr [ i ] ) ; } if ( dp [ i ] [ j ] != -1 ) { return dp [ i ] [ j ] ; } int X = max ( 0 , arr [ i ] + mxSubSum ( i - 1 , arr , j , dp ) ) ; if ( j == 0 ) { return dp [ i ] [ j ] = X ; } int Y = mxSubSum ( i - 1 , arr , j - 1 , dp ) ; return dp [ i ] [ j ] = max ( X , Y ) ; } int MaximumSubarraySum ( int n , int * arr , int k ) { int dp [ M ] [ M ] ; memset ( dp , -1 , sizeof ( dp ) ) ; mxSubSum ( n - 1 , arr , k , dp ) ; int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j <= k ; j ++ ) { res = max ( res , dp [ i ] [ j ] ) ; } } if ( * max_element ( arr , arr + n ) < 0 ) { res = * max_element ( arr , arr + n ) ; } return res ; } int main ( ) { int arr [ ] = { -2 , 1 , 3 , -2 , 4 , -7 , 20 } ; int K = 1 ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << MaximumSubarraySum ( N , arr , K ) << endl ; return 0 ; }

Index/key variables: M, i, j
Accumulator variables: i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define INF  10000
void minCost ( int arr [ ] , int n ) { sort ( arr , arr + n ) ; int m = 2 * n ; int cost [ n + 1 ] [ m + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= m ; j ++ ) { cost [ i ] [ j ] = INF ; } } cost [ 0 ] [ 0 ] = 0 ; int prev = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { prev = cost [ i - 1 ] [ 0 ] ; for ( int j = 1 ; j <= m ; j ++ ) { cost [ i ] [ j ] = min ( cost [ i ] [ j ] , prev + abs ( j - arr [ i - 1 ] ) ) ; prev = min ( prev , cost [ i - 1 ] [ j ] ) ; } } int minCost = INF ; for ( int j = 1 ; j <= m ; j ++ ) { minCost = min ( minCost , cost [ n ] [ j ] ) ; } cout << minCost ; } int main ( ) { int arr [ ] = { 4 , 2 , 4 , 4 , 5 , 2 } ; int N = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; minCost ( arr , N ) ; 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 ; bool checkbit ( int array [ ] , int index ) { return array [ index >> 5 ] & ( 1 << ( index & 31 ) ) ; } void setbit ( int array [ ] , int index ) { array [ index >> 5 ] |= ( 1 << ( index & 31 ) ) ; } int main ( ) { int a = 2 , b = 10 ; int size = abs ( b - a ) ; size = ceil ( size / 32 ) ; int * array = new int [ size ] ; for ( int i = a ; i <= b ; i ++ ) if ( i % 2 == 0 i % 5 == 0 ) setbit ( array , i - a ) ; cout << " MULTIPLES ▁ of ▁ 2 ▁ and ▁ 5 : STRNEWLINE " ; for ( int i = a ; i <= b ; i ++ ) if ( checkbit ( array , i - a ) ) cout << i << " ▁ " ; return 0 ; }

Index/key variables: size
Accumulator variables: i, stdc
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; int longestCommonSum ( bool arr1 [ ] , bool arr2 [ ] , int n ) { int maxLen = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int sum1 = 0 , sum2 = 0 ; for ( int j = i ; j < n ; j ++ ) { sum1 += arr1 [ j ] ; sum2 += arr2 [ j ] ; if ( sum1 == sum2 ) { int len = j - i + 1 ; if ( len > maxLen ) maxLen = len ; } } } return maxLen ; } int main ( ) { bool arr1 [ ] = { 0 , 1 , 0 , 1 , 1 , 1 , 1 } ; bool arr2 [ ] = { 1 , 1 , 1 , 1 , 1 , 0 , 1 } ; int n = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; cout << " Length ▁ of ▁ the ▁ longest ▁ common ▁ span ▁ with ▁ same ▁ " " sum ▁ is ▁ " << longestCommonSum ( arr1 , arr2 , n ) ; return 0 ; }

Index/key variables: j
Accumulator variables: i, j, stdc, sum1, sum2
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int findNumberOfLIS ( vector < int > nums ) { if ( nums . size ( ) == 0 ) return 0 ; int n = nums . size ( ) ; vector < int > dp_l ( n , 1 ) ; vector < int > dp_c ( n , 1 ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( nums [ i ] <= nums [ j ] ) continue ; if ( dp_l [ j ] + 1 > dp_l [ i ] ) { dp_l [ i ] = dp_l [ j ] + 1 ; dp_c [ i ] = dp_c [ j ] ; } else if ( dp_l [ j ] + 1 == dp_l [ i ] ) dp_c [ i ] += dp_c [ j ] ; } } int max_length = 0 ; for ( int i : dp_l ) max_length = max ( i , max_length ) ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( dp_l [ i ] == max_length ) count += dp_c [ i ] ; } return count ; } int main ( ) { vector < int > arr = { 1 , 3 , 5 , 4 , 7 } ; cout << findNumberOfLIS ( arr ) << endl ; }

Index/key variables: i, j
Accumulator variables: count, i, j, stdc
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; struct Node { int val ; Node * left , * right ; } ; struct Node * newNode ( int data ) { struct Node * temp = ( struct Node * ) malloc ( sizeof ( struct Node ) ) ; temp -> val = data ; temp -> left = NULL ; temp -> right = NULL ; return temp ; } bool checkEvenOddLevel ( Node * root ) { if ( root == NULL ) return true ; queue < Node * > q ; q . push ( root ) ; int level = 0 ; while ( q . empty ( ) ) { vector < int > vec ; int size = q . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { Node * node = q . front ( ) ; vec . push_back ( node -> val ) ; if ( node -> left != NULL ) q . push ( node -> left ) ; if ( node -> right != NULL ) q . push ( node -> right ) ; } if ( level % 2 == 0 ) { for ( int i = 0 ; i < vec . size ( ) - 1 ; i ++ ) { if ( vec [ i + 1 ] > vec [ i ] ) continue ; return false ; } } else if ( level % 2 == 1 ) { for ( int i = 0 ; i < vec . size ( ) - 1 ; i ++ ) { if ( vec [ i + 1 ] < vec [ i ] ) continue ; return false ; } } level ++ ; } return true ; } int main ( ) { Node * root = NULL ; root = newNode ( 2 ) ; root -> left = newNode ( 6 ) ; root -> right = newNode ( 3 ) ; root -> left -> left = newNode ( 4 ) ; root -> left -> right = newNode ( 7 ) ; root -> right -> right = newNode ( 11 ) ; root -> left -> left -> left = newNode ( 10 ) ; root -> left -> left -> right = newNode ( 5 ) ; root -> left -> right -> right = newNode ( 1 ) ; if ( checkEvenOddLevel ( root ) ) cout << " YES " ; else cout << " NO " ; }

Index/key variables: i
Accumulator variables: i, level, stdc
Iterator variables: i
Class/struct names: Node
C++ program:
#include <bits/stdc++.h>
using namespace std ; int longestCommonSum ( bool arr1 [ ] , bool arr2 [ ] , int n ) { int arr [ n ] ; for ( int i = 0 ; i < n ; i ++ ) arr [ i ] = arr1 [ i ] - arr2 [ i ] ; unordered_map < int , int > hM ; int sum = 0 ; int max_len = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; if ( sum == 0 ) max_len = i + 1 ; if ( hM . find ( sum ) != hM . end ( ) ) max_len = max ( max_len , i - hM [ sum ] ) ; else hM [ sum ] = i ; } return max_len ; } int main ( ) { bool arr1 [ ] = { 0 , 1 , 0 , 1 , 1 , 1 , 1 } ; bool arr2 [ ] = { 1 , 1 , 1 , 1 , 1 , 0 , 1 } ; int n = sizeof ( arr1 ) / sizeof ( arr1 [ 0 ] ) ; cout << longestCommonSum ( arr1 , arr2 , n ) ; return 0 ; }

Index/key variables: i, n, sum
Accumulator variables: i, stdc, sum
Iterator variables: i
C++ program:
#include <bits/stdc++.h>
using namespace std ; #define maxN  20
int dp [ maxN ] [ maxN ] [ 27 ] [ maxN ] ; int solve ( string & s , int n , int idx , int k , char last = 123 , int count = 0 ) { if ( k < 0 ) return n + 1 ; if ( idx == n ) return 0 ; int & ans = dp [ idx ] [ k ] [ last - ' a ' ] [ count ] ; if ( ans != -1 ) return ans ; ans = n + 1 ; ans = min ( ans , solve ( s , n , idx + 1 , k - 1 , last , count ) ) ; int inc = 0 ; if ( count == 1 count == 9 count == 99 ) inc = 1 ; if ( last == s [ idx ] ) { ans = min ( ans , inc + solve ( s , n , idx + 1 , k , s [ idx ] , count + 1 ) ) ; } else { ans = min ( ans , 1 + solve ( s , n , idx + 1 , k , s [ idx ] , 1 ) ) ; } return ans ; } int MinRunLengthEncoding ( string & s , int n , int k ) { memset ( dp , -1 , sizeof ( dp ) ) ; return solve ( s , n , 0 , k ) ; } int main ( ) { string S = " abbbcdcdd " ; int N = 9 , K = 2 ; cout << MinRunLengthEncoding ( S , N , K ) ; return 0 ; }

Index/key variables: count, idx, k, maxN
Accumulator variables: stdc
C++ program:
#include <bits/stdc++.h>
using namespace std ; long mElementsWithMaxSum ( vector < vector < int > > matrix , int M , int block , vector < vector < int > > dp ) { if ( block == matrix . size ( ) ) return 0 ; if ( dp [ block ] [ M ] != -1 ) return dp [ block ] [ M ] ; long ans = mElementsWithMaxSum ( matrix , M , block + 1 , dp ) ; for ( int i = 0 ; i < matrix [ block ] . size ( ) ; i ++ ) { for ( int j = i ; j < matrix [ block ] . size ( ) ; j ++ ) { if ( j - i + 1 <= M ) { ans = max ( ans , matrix [ block ] [ j ] - ( ( i - 1 ) >= 0 ? matrix [ block ] [ i - 1 ] : 0 ) + mElementsWithMaxSum ( matrix , M - j + i - 1 , block + 1 , dp ) ) ; } } } return dp [ block ] [ M ] = ans ; } void preComputing ( vector < vector < int > > matrix , int N ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < matrix [ i ] . size ( ) ; j ++ ) { matrix [ i ] [ j ] = ( j > 0 ? matrix [ i ] [ j - 1 ] : 0 ) + matrix [ i ] [ j ] ; } } } void mElementsWithMaxSumUtil ( vector < vector < int > > matrix , int M , int N ) { preComputing ( matrix , N ) ; long sum = 10 ; vector < vector < int > > dp ; dp . resize ( N + 5 ) ; for ( int i = 0 ; i < N + 5 ; i ++ ) for ( int j = 0 ; j < M + 5 ; j ++ ) dp [ i ] . push_back ( -1 ) ; sum += mElementsWithMaxSum ( matrix , M , 0 , dp ) ; cout << sum ; } int main ( ) { int N = 3 ; int M = 4 ; vector < vector < int > > matrix = { { 2 , 3 , 5 } , { -1 , 7 } , { 8 , 10 } } ; mElementsWithMaxSumUtil ( matrix , M , N ) ; }

Index/key variables: M, block, i, j
Accumulator variables: i, j, stdc, sum
Iterator variables: i, j
C++ program:
#include <bits/stdc++.h>
using namespace std ; int lastRemaining ( int n , map < int , int > & dp ) { if ( dp . find ( n ) != dp . end ( ) ) return dp [ n ] ; if ( n == 1 ) return 1 ; else dp [ n ] = 2 * ( 1 + n / 2 - lastRemaining ( n / 2 , dp ) ) ; return dp [ n ] ; } int main ( ) { int N = 5 ; map < int , int > dp ; cout << lastRemaining ( N , dp ) ; return 0 ; }

Index/key variables: n
Accumulator variables: stdc