dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class GFG { static boolean find ( char x [ ] , char c ) { for ( int i = 0 ; i < x . length ; i ++ ) if ( x [ i ] == c ) return true ; return false ; } static boolean find ( Vector < Character > v , char c ) { for ( int i = 0 ; i < v . size ( ) ; i ++ ) if ( v . get ( i ) == c ) return true ; return false ; } static void addAllVowel ( String str ) { char x [ ] = { ' A ' , ' E ' , ' I ' , ' O ' , ' U ' } ; Vector < Character > y = new Vector < > ( ) ; int length = str . length ( ) ; if ( length < 5 ) System . out . println ( " Impossible " ) ; else { for ( int i = 0 ; i < length ; i ++ ) { if ( find ( x , str . charAt ( i ) ) && ! find ( y , str . charAt ( i ) ) ) y . add ( str . charAt ( i ) ) ; } Vector < Character > z = new Vector < > ( ) ; for ( int i = 0 ; i < 5 ; i ++ ) if ( ! find ( y , x [ i ] ) ) z . add ( x [ i ] ) ; if ( z . size ( ) == 0 ) System . out . println ( str ) ; else { int cc = 0 ; Vector < Character > y1 = new Vector < > ( ) ; String ans = " " ; for ( int i = 0 ; i < length ; i ++ ) { if ( find ( x , str . charAt ( i ) ) && ! find ( y1 , str . charAt ( i ) ) ) { ans += str . charAt ( i ) ; y1 . add ( str . charAt ( i ) ) ; } else { ans += z . get ( cc ) ; cc ++ ; } if ( cc == z . size ( ) ) { for ( int j = i + 1 ; j < length ; j ++ ) ans += str . charAt ( j ) ; break ; } } System . out . println ( ans ) ; } } } public static void main ( String args [ ] ) { String str = " ABCDEFGHI " ; addAllVowel ( str ) ; } }

Index/key variables: i
Accumulator variables: ans, cc, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; import java . io . * ; class Pair { int x , y ; Pair ( int a , int b ) { this . x = a ; this . y = b ; } } class GFG { static int inf = Integer . MIN_VALUE ; public static int minimumDays ( int N , int D1 [ ] , int D2 [ ] ) { int ans = - inf ; ArrayList < Pair > list = new ArrayList < Pair > ( ) ; for ( int i = 0 ; i < N ; i ++ ) list . add ( new Pair ( D1 [ i ] , D2 [ i ] ) ) ; Collections . sort ( list , new Comparator < Pair > ( ) { @ Override public int compare ( Pair p1 , Pair p2 ) { return p1 . x - p2 . x ; } } ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( list . get ( i ) . y >= ans ) ans = list . get ( i ) . y ; else ans = list . get ( i ) . x ; } return ans ; } public static void main ( String [ ] args ) { int N = 3 ; int D1 [ ] = new int [ ] { 6 , 5 , 4 } ; int D2 [ ] = new int [ ] { 1 , 2 , 3 } ; System . out . print ( minimumDays ( N , D1 , D2 ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, Pair
Java program:
import java . io . * ; class GFG { static int solve ( int [ ] [ ] v , int n ) { int ans , ul , ll ; int first = 0 ; int second = 1 ; ll = v [ 0 ] [ first ] ; ul = v [ 0 ] [ second ] ; ans = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( ( v [ i ] [ first ] <= ul && v [ i ] [ first ] >= ll ) || ( v [ i ] [ second ] >= ll && v [ i ] [ second ] <= ul ) ) { if ( v [ i ] [ first ] > ll ) { ll = v [ i ] [ first ] ; } if ( v [ i ] [ second ] < ul ) { ul = v [ i ] [ second ] ; } } else if ( v [ i ] [ first ] > ul ) { ans += Math . abs ( ul - v [ i ] [ first ] ) ; ul = v [ i ] [ first ] ; ll = v [ i ] [ first ] ; } else if ( v [ i ] [ second ] < ll ) { ans += Math . abs ( ll - v [ i ] [ second ] ) ; ul = v [ i ] [ second ] ; ll = v [ i ] [ second ] ; } } return ans ; } public static void main ( String [ ] args ) { int [ ] [ ] v = { { 1 , 3 } , { 2 , 5 } , { 6 , 8 } , { 1 , 2 } , { 2 , 3 } } ; int n = 5 ; System . out . println ( solve ( v , n ) ) ; } }

Index/key variables: first, i, second
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static Vector < String > preProcess ( int n ) { Vector < String > preProcessedCubes = new Vector < > ( ) ; for ( int i = 1 ; i * i * i <= n ; i ++ ) { int iThCube = i * i * i ; String cubeString = String . valueOf ( iThCube ) ; preProcessedCubes . add ( cubeString ) ; } return preProcessedCubes ; } static String findLargestCubeUtil ( String num , Vector < String > preProcessedCubes ) { Collections . reverse ( preProcessedCubes ) ; int totalCubes = preProcessedCubes . size ( ) ; for ( int i = 0 ; i < totalCubes ; i ++ ) { String currCube = preProcessedCubes . get ( i ) ; int digitsInCube = currCube . length ( ) ; int index = 0 ; int digitsInNumber = num . length ( ) ; for ( int j = 0 ; j < digitsInNumber ; j ++ ) { if ( num . charAt ( j ) == currCube . charAt ( index ) ) { index ++ ; } if ( digitsInCube == index ) { return currCube ; } } } return " Not ▁ Possible " ; } static void findLargestCube ( int n ) { Vector < String > preProcessedCubes = preProcess ( n ) ; String num = String . valueOf ( n ) ; String ans = findLargestCubeUtil ( num , preProcessedCubes ) ; System . out . println ( " Largest ▁ Cube ▁ that ▁ can ▁ be ▁ formed ▁ from ▁ " + n + " ▁ is ▁ " + ans ) ; } public static void main ( String [ ] args ) { int n ; n = 4125 ; findLargestCube ( n ) ; n = 876 ; findLargestCube ( n ) ; } }

Accumulator variables: i, index, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int n , p ; static int rd [ ] = new int [ 1100 ] ; static int wt [ ] = new int [ 1100 ] ; static int cd [ ] = new int [ 1100 ] ; static List < Integer > a = new ArrayList < Integer > ( ) ; static List < Integer > b = new ArrayList < Integer > ( ) ; static List < Integer > c = new ArrayList < Integer > ( ) ; static int ans ; static int dfs ( int w ) { if ( cd [ w ] == 0 ) return w ; if ( wt [ w ] < ans ) ans = wt [ w ] ; return dfs ( cd [ w ] ) ; } static void solve ( int arr [ ] [ ] ) { int i = 0 ; while ( i < p ) { int q = arr [ i ] [ 0 ] ; int h = arr [ i ] [ 1 ] ; int t = arr [ i ] [ 2 ] ; cd [ q ] = h ; wt [ q ] = t ; rd [ h ] = q ; i ++ ; } a = new ArrayList < Integer > ( ) ; b = new ArrayList < Integer > ( ) ; c = new ArrayList < Integer > ( ) ; for ( int j = 1 ; j <= n ; ++ j ) if ( rd [ j ] == 0 && cd [ j ] > 0 ) { ans = 1000000000 ; int w = dfs ( j ) ; a . add ( j ) ; b . add ( w ) ; c . add ( ans ) ; } System . out . println ( a . size ( ) ) ; for ( int j = 0 ; j < a . size ( ) ; ++ j ) System . out . println ( a . get ( j ) + " ▁ " + b . get ( j ) + " ▁ " + c . get ( j ) ) ; } public static void main ( String args [ ] ) { n = 9 ; p = 6 ; for ( int i = 0 ; i < 1100 ; i ++ ) rd [ i ] = cd [ i ] = wt [ i ] = 0 ; int arr [ ] [ ] = { { 7 , 4 , 98 } , { 5 , 9 , 72 } , { 4 , 6 , 10 } , { 2 , 8 , 22 } , { 9 , 7 , 17 } , { 3 , 1 , 66 } } ; solve ( arr ) ; } }

Index/key variables: h, i, j, q, w
Accumulator variables: i
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; public class GfG { public static String noAdjacentDup ( String s1 ) { int n = s1 . length ( ) ; char [ ] s = s1 . toCharArray ( ) ; for ( int i = 1 ; i < n ; i ++ ) { if ( s [ i ] == s [ i - 1 ] ) { s [ i ] = ' a ' ; while ( s [ i ] == s [ i - 1 ] || ( i + 1 < n && s [ i ] == s [ i + 1 ] ) ) s [ i ] ++ ; i ++ ; } } return ( new String ( s ) ) ; } public static void main ( String argc [ ] ) { String s = " geeksforgeeks " ; System . out . println ( noAdjacentDup ( s ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GfG
Java program:
import java . io . * ; class GFG { static int winner ( int a [ ] , int n , int k ) { if ( k >= n - 1 ) return n ; int best = 0 , times = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] > best ) { best = a [ i ] ; if ( i == 1 ) times = 1 ; } else times += 1 ; if ( times >= k ) return best ; } return best ; } public static void main ( String args [ ] ) { int a [ ] = { 2 , 1 , 3 , 4 , 5 } ; int n = a . length ; int k = 2 ; System . out . println ( winner ( a , n , k ) ) ; } }

Index/key variables: i
Accumulator variables: i, times
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static void swap ( int a , int b ) { int temp = a ; a = b ; b = temp ; } static int minimumSquare ( int a , int b ) { int result = 0 , rem = 0 ; if ( a < b ) swap ( a , b ) ; while ( b > 0 ) { result += a / b ; rem = a % b ; a = b ; b = rem ; } return result ; } public static void main ( String [ ] args ) { int n = 13 , m = 29 ; System . out . println ( minimumSquare ( n , m ) ) ; } }

Accumulator variables: result
Class/struct names: GFG
Java program:
import java . util . * ; class maximizeSum { public static int maxSum ( int [ ] a , int k ) { PriorityQueue < Integer > pq = new PriorityQueue < > ( ) ; for ( int x : a ) pq . add ( x ) ; while ( k -- > 0 ) { int temp = pq . poll ( ) ; temp *= - 1 ; pq . add ( temp ) ; } int sum = 0 ; for ( int x : pq ) sum += x ; return sum ; } public static void main ( String [ ] args ) { int [ ] arr = { - 2 , 0 , 5 , - 1 , 2 } ; int k = 4 ; System . out . println ( maxSum ( arr , k ) ) ; } }

Accumulator variables: k, sum, temp
Iterator variables: x
Class/struct names: maximizeSum
Java program:
public class GFG { static int totalValidArrays ( int a [ ] , int b [ ] , int N ) { int dp [ ] [ ] = new int [ N + 1 ] [ b [ N - 1 ] + 1 ] ; int pref [ ] [ ] = new int [ N + 1 ] [ b [ N - 1 ] + 1 ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) for ( int j = 0 ; j < b [ N - 1 ] + 1 ; j ++ ) dp [ i ] [ j ] = 0 ; for ( int i = 0 ; i < N + 1 ; i ++ ) for ( int j = 0 ; j < b [ N - 1 ] + 1 ; j ++ ) pref [ i ] [ j ] = 0 ; dp [ 0 ] [ 0 ] = 1 ; for ( int i = 0 ; i <= b [ N - 1 ] ; i ++ ) { pref [ 0 ] [ i ] = 1 ; } for ( int i = 1 ; i <= N ; i ++ ) { for ( int j = a [ i - 1 ] ; j <= b [ i - 1 ] ; j ++ ) { dp [ i ] [ j ] += pref [ i - 1 ] [ j ] ; pref [ i ] [ j ] += dp [ i ] [ j ] ; } for ( int j = 0 ; j <= b [ N - 1 ] ; j ++ ) { if ( j > 0 ) { pref [ i ] [ j ] += pref [ i ] [ j - 1 ] ; } } } int ans = 0 ; for ( int i = a [ N - 1 ] ; i <= b [ N - 1 ] ; i ++ ) { ans += dp [ N ] [ i ] ; } return ans ; } public static void main ( String [ ] args ) { int A [ ] = { 1 , 1 } ; int B [ ] = { 2 , 3 } ; int N = A . length ; System . out . println ( totalValidArrays ( A , B , N ) ) ; } }

Index/key variables: N, i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static String s ; static int [ ] [ ] [ ] [ ] dp = new int [ 1024 ] [ 10 ] [ 2 ] [ 2 ] ; static boolean toBoolean ( int smaller ) { if ( smaller >= 1 ) return true ; else return false ; } static int calcCnt ( int mask , int len , int smaller , int started ) { + X3D3F3 : W3F3 : Y3F3 : X3 if ( len == s . length ( ) ) { if ( mask == 0 && started != 0 ) return 1 ; else return 0 ; } if ( dp [ mask ] [ len ] [ smaller ] [ started ] != - 1 ) return dp [ mask ] [ len ] [ smaller ] [ started ] ; int mx = 9 ; if ( smaller == 0 ) { mx = ( int ) s . charAt ( len ) - 48 ; } int ans = 0 ; if ( started != 0 ) { for ( int i = 0 ; i <= mx ; i ++ ) { ans += calcCnt ( mask ^ ( 1 << i ) , len + 1 , toBoolean ( smaller ) || ( i < ( int ) s . charAt ( len ) - 48 ) ? 1 : 0 , 1 ) ; } } else { ans = calcCnt ( mask , len + 1 , 1 , 0 ) ; for ( int i = 1 ; i <= mx ; i ++ ) { ans += calcCnt ( mask ^ ( 1 << i ) , len + 1 , toBoolean ( smaller ) || ( i < ( int ) s . charAt ( len ) - 48 ) ? 1 : 0 , 1 ) ; } } dp [ mask ] [ len ] [ smaller ] [ started ] = ans ; return ans ; } static int countInt ( int x ) { for ( int i = 0 ; i < 1024 ; i ++ ) { for ( int j = 0 ; j < 10 ; j ++ ) { for ( int k = 0 ; k < 2 ; k ++ ) { for ( int l = 0 ; l < 2 ; l ++ ) dp [ i ] [ j ] [ k ] [ l ] = - 1 ; } } } s = Integer . toString ( x ) ; return calcCnt ( 0 , 0 , 0 , 0 ) ; } static int countIntInRange ( int L , int R ) { return countInt ( R ) - countInt ( L - 1 ) ; } public static void main ( String [ ] args ) { int L = 32 , R = 1010 ; System . out . println ( countIntInRange ( L , R ) ) ; } }

Index/key variables: i, j, k, l, len, mask, smaller, started
Accumulator variables: ans, i, j, k, l
Iterator variables: i, j, k, l
Class/struct names: GFG
Java program:
class GFG { static class Query { int L , R ; public Query ( int l , int r ) { super ( ) ; L = l ; R = r ; } } ; static int MAX = 5000 ; static void minDifference ( int arr [ ] , int n , Query q [ ] , int m ) { for ( int i = 0 ; i < m ; i ++ ) { int L = q [ i ] . L , R = q [ i ] . R ; int ans = MAX ; for ( int j = L ; j < R ; j ++ ) { ans = Math . min ( ans , arr [ j ] ) ; } System . out . println ( ans ) ; } } static void minimumDifference ( int arr [ ] , Query q [ ] , int N , int m ) { int [ ] diff = new int [ N ] ; for ( int i = 0 ; i < N - 1 ; i ++ ) diff [ i ] = Math . abs ( arr [ i ] - arr [ i + 1 ] ) ; minDifference ( diff , N - 1 , q , m ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 6 , 1 , 8 , 3 , 4 } ; int N = arr . length ; Query Q [ ] = { new Query ( 0 , 3 ) , new Query ( 1 , 5 ) , new Query ( 4 , 5 ) } ; int M = Q . length ; minimumDifference ( arr , Q , N , M ) ; } }

Index/key variables: N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG, Query
Java program:
import java . io . * ; import java . util . * ; class GFG { public static int [ ] [ ] dp = new int [ 100 ] [ ( 1 << 4 ) ] ; public static HashMap < Integer , Integer > primeIndex = new HashMap < > ( ) ; public static int countSetBits ( int n ) { int count = 0 ; while ( n > 0 ) { count += n & 1 ; n >>= 1 ; } return count ; } public static int countOfNumbers ( int index , int mask , int N ) { if ( index == N + 1 ) { int countOfPrimes = countSetBits ( mask ) ; if ( countOfPrimes == 4 ) { return 1 ; } return 0 ; } int val = dp [ index ] [ mask ] ; if ( val != - 1 ) { return val ; } val = 0 ; if ( index == 1 ) { for ( int digit = ( N == 1 ? 0 : 1 ) ; digit <= 9 ; ++ digit ) { if ( primeIndex . containsKey ( digit ) ) { int newMask = mask | ( 1 << primeIndex . get ( digit ) ) ; val += countOfNumbers ( index + 1 , newMask , N ) ; } else { val += countOfNumbers ( index + 1 , mask , N ) ; } } } else { for ( int digit = 0 ; digit <= 9 ; ++ digit ) { if ( primeIndex . containsKey ( digit ) ) { int newMask = mask | ( 1 << primeIndex . get ( digit ) ) ; val += countOfNumbers ( index + 1 , newMask , N ) ; } else { val += countOfNumbers ( index + 1 , mask , N ) ; } } } return val ; } public static void main ( String [ ] args ) { for ( int i = 0 ; i < 100 ; i ++ ) { for ( int j = 0 ; j < ( 1 << 4 ) ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } primeIndex . put ( 2 , 0 ) ; primeIndex . put ( 3 , 1 ) ; primeIndex . put ( 5 , 2 ) ; primeIndex . put ( 7 , 3 ) ; int N = 4 ; System . out . println ( countOfNumbers ( 1 , 0 , N ) ) ; } }

Index/key variables: i, index, j, mask
Accumulator variables: count, i, j, val
Iterator variables: digit, i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int [ ] [ ] [ ] dp = new int [ 100 ] [ 1 << 5 ] [ 1 << 5 ] ; static int __builtin_popcount ( int n ) { int d , t = 0 ; while ( n > 0 ) { d = n % 2 ; n = n / 2 ; if ( d == 1 ) t ++ ; } return t ; } static int countOfNumbers ( int index , int evenMask , int oddMask , int N ) { if ( index == N + 1 ) { int countOfEvenDigits = __builtin_popcount ( evenMask ) ; int countOfOddDigits = __builtin_popcount ( oddMask ) ; if ( countOfOddDigits == countOfEvenDigits ) { return 1 ; } return 0 ; } int val = dp [ index ] [ evenMask ] [ oddMask ] ; if ( val != - 1 ) return val ; val = 0 ; if ( index == 1 ) { for ( int digit = ( N == 1 ? 0 : 1 ) ; digit <= 9 ; ++ digit ) { if ( ( digit & 1 ) != 0 ) { val += countOfNumbers ( index + 1 , evenMask , oddMask | ( 1 << ( digit / 2 ) ) , N ) ; } else { val += countOfNumbers ( index + 1 , evenMask | ( 1 << ( digit / 2 ) ) , oddMask , N ) ; } } } else { for ( int digit = 0 ; digit <= 9 ; ++ digit ) { if ( ( digit & 1 ) != 0 ) { val += countOfNumbers ( index + 1 , evenMask , oddMask | ( 1 << ( digit / 2 ) ) , N ) ; } else { val += countOfNumbers ( index + 1 , evenMask | ( 1 << ( digit / 2 ) ) , oddMask , N ) ; } } } return val ; } static void countNDigitNumber ( int N ) { for ( int i = 0 ; i < 100 ; i ++ ) { for ( int j = 0 ; j < ( 1 << 5 ) ; j ++ ) { for ( int k = 0 ; k < ( 1 << 5 ) ; k ++ ) { dp [ i ] [ j ] [ k ] = - 1 ; } } } System . out . println ( countOfNumbers ( 1 , 0 , 0 , N ) ) ; } public static void main ( String [ ] args ) { int N = 3 ; countNDigitNumber ( N ) ; } }

Index/key variables: evenMask, i, index, j, k, oddMask
Accumulator variables: i, j, k, t, val
Iterator variables: digit, i, j, k
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int countMinSteps ( String A , String B , int N ) { int [ ] dp = new int [ N + 1 ] ; for ( int i = 1 ; i <= N ; i ++ ) { dp [ i ] = 0 ; } for ( int i = 1 ; i <= N ; i ++ ) { if ( A . charAt ( i - 1 ) == B . charAt ( i - 1 ) ) { dp [ i ] = dp [ i - 1 ] ; } else { dp [ i ] = dp [ i - 1 ] + 1 ; } if ( i >= 2 && A . charAt ( i - 2 ) == B . charAt ( i - 1 ) && A . charAt ( i - 1 ) == B . charAt ( i - 2 ) ) { dp [ i ] = Math . min ( dp [ i ] , dp [ i - 2 ] + 1 ) ; } } return dp [ N ] ; } public static void main ( String [ ] args ) { String A = "0101" ; String B = "0011" ; int N = A . length ( ) ; System . out . println ( countMinSteps ( A , B , N ) ) ; } }

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { public static int [ ] [ ] [ ] dp = new int [ 50 ] [ 1 << 10 ] [ 2 ] ; public static int countOfNumbers ( int digit , int mask , int repeated , int n ) { if ( digit == n + 1 ) { if ( repeated == 1 ) { return 1 ; } return 0 ; } if ( repeated == 1 ) { return ( int ) Math . pow ( 10 , n - digit + 1 ) ; } int val = dp [ digit ] [ mask ] [ repeated ] ; if ( val != - 1 ) { return val ; } val = 0 ; if ( digit == 1 ) { for ( int i = ( n == 1 ? 0 : 1 ) ; i <= 9 ; ++ i ) { if ( ( mask & ( 1 << i ) ) > 0 ) { val += countOfNumbers ( digit + 1 , mask | ( 1 << i ) , 1 , n ) ; } else { val += countOfNumbers ( digit + 1 , mask | ( 1 << i ) , 0 , n ) ; } } } else { for ( int i = 0 ; i <= 9 ; ++ i ) { if ( ( mask & ( 1 << i ) ) > 0 ) { val += countOfNumbers ( digit + 1 , mask | ( 1 << i ) , 1 , n ) ; } else { val += countOfNumbers ( digit + 1 , mask | ( 1 << i ) , 0 , n ) ; } } } return val ; } public static void countNDigitNumber ( int N ) { for ( int i = 0 ; i < 50 ; i ++ ) { for ( int j = 0 ; j < 1 << 10 ; j ++ ) { for ( int k = 0 ; k < 2 ; k ++ ) { dp [ i ] [ j ] [ k ] = - 1 ; } } } System . out . println ( countOfNumbers ( 1 , 0 , 0 , N ) ) ; } public static void main ( String args [ ] ) { int N = 2 ; countNDigitNumber ( N ) ; } }

Index/key variables: digit, i, j, k, mask, repeated
Accumulator variables: i, j, k, val
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
import java . util . * ; public class Main { static String getMaximum ( String S , String T ) { if ( S . indexOf ( "0" ) > - 1 ) return T ; if ( T . indexOf ( "0" ) > - 1 ) return S ; return S . length ( ) > T . length ( ) ? S : T ; } static String recursion ( int [ ] arr , int idx , int N , int K , Vector < Vector < String > > dp ) { if ( K == 0 ) { return " " ; } if ( K < 0 idx == N ) { return "0" ; } if ( dp . get ( idx ) . get ( K ) != " - 1" ) return dp . get ( idx ) . get ( K ) ; String include = String . valueOf ( idx + 1 ) + recursion ( arr , 0 , N , K - arr [ idx ] , dp ) ; String exclude = recursion ( arr , idx + 1 , N , K , dp ) ; dp . get ( idx ) . set ( K , getMaximum ( include , exclude ) ) ; return dp . get ( idx ) . get ( K ) ; } static String largestNumber ( int [ ] arr , int N , int K ) { Vector < Vector < String > > dp = new Vector < Vector < String > > ( ) ; for ( int i = 0 ; i < N + 1 ; i ++ ) { dp . add ( new Vector < String > ( ) ) ; for ( int j = 0 ; j < K + 1 ; j ++ ) { dp . get ( i ) . add ( " - 1" ) ; } } String ans = recursion ( arr , 0 , N , K , dp ) ; return ans == " " ? "0" : ans ; } public static void main ( String [ ] args ) { int [ ] arr = { 3 , 12 , 9 , 5 , 3 , 4 , 6 , 5 , 10 } ; int K = 14 ; int N = arr . length ; System . out . print ( largestNumber ( arr , N , K ) ) ; } }

Index/key variables: idx
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: Main
Java program:
import java . util . * ; class GFG { static int dp [ ] [ ] = new int [ 100 ] [ 10 ] ; static int countOfNumbers ( int digit , int prev , int n ) { if ( digit == n + 1 ) { return 1 ; } int val = dp [ digit ] [ prev ] ; if ( val != - 1 ) { return val ; } val = 0 ; if ( digit == 1 ) { for ( int i = ( n == 1 ? 0 : 1 ) ; i <= 9 ; ++ i ) { val += countOfNumbers ( digit + 1 , i , n ) ; } } else { for ( int i = 0 ; i <= 9 ; ++ i ) { if ( ( i & prev ) == 0 ) { val += countOfNumbers ( digit + 1 , i , n ) ; } } } return val ; } public static void main ( String [ ] args ) { for ( int i = 0 ; i < 100 ; i ++ ) { for ( int j = 0 ; j < 10 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } int N = 3 ; System . out . println ( countOfNumbers ( 1 , 0 , N ) ) ; } }

Index/key variables: digit, i, j, prev
Accumulator variables: i, j, val
Iterator variables: i, j
Class/struct names: GFG
Java program:
public class Solution { static void preProcess ( int mat [ ] [ ] , int dp [ ] [ ] , int n , int m ) { for ( int i = 0 ; i < m ; i ++ ) { dp [ 0 ] [ i ] = mat [ 0 ] [ i ] ; } for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { dp [ i ] [ j ] = dp [ i - 1 ] [ j ] + mat [ i ] [ j ] ; } } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 1 ; j < m ; j ++ ) { dp [ i ] [ j ] += dp [ i ] [ j - 1 ] ; } } } static int sumQuery ( int dp [ ] [ ] , int tli , int tlj , int rbi , int rbj ) { int res = dp [ rbi ] [ rbj ] ; if ( tli > 0 ) res = res - dp [ tli - 1 ] [ rbj ] ; if ( tlj > 0 ) res = res - dp [ rbi ] [ tlj - 1 ] ; if ( tli > 0 && tlj > 0 ) res = res + dp [ tli - 1 ] [ tlj - 1 ] ; return res ; } static int [ ] maxSubMatrixSumQueries ( int [ ] [ ] mat , int n , int m , int [ ] [ ] queries , int q ) { int dp [ ] [ ] = new int [ n ] [ m ] ; preProcess ( mat , dp , n , m ) ; int maxSum [ ] = new int [ queries . length ] ; for ( int qi = 0 ; qi < q ; qi ++ ) { for ( int i = 0 ; i < n - queries [ qi ] [ 0 ] + 1 ; i ++ ) { for ( int j = 0 ; j < m - queries [ qi ] [ 1 ] + 1 ; j ++ ) { maxSum [ qi ] = Math . max ( maxSum [ qi ] , sumQuery ( dp , i , j , i + queries [ qi ] [ 0 ] - 1 , j + queries [ qi ] [ 1 ] - 1 ) ) ; } } } return maxSum ; } public static void main ( String args [ ] ) { int n = 3 , m = 4 ; int mat [ ] [ ] = { { 1 , 2 , 3 , 9 } , { 4 , 5 , 6 , 2 } , { 8 , 3 , 2 , 6 } } ; int Q = 3 ; int Queries [ ] [ ] = { { 1 , 1 } , { 2 , 2 } , { 3 , 3 } } ; int maxSum [ ] = maxSubMatrixSumQueries ( mat , n , m , Queries , Q ) ; for ( int i = 0 ; i < Q ; i ++ ) { System . out . print ( maxSum [ i ] + " ▁ " ) ; } } }

Index/key variables: i, j, m, n, qi, rbi, rbj
Accumulator variables: i, j, qi
Iterator variables: i, j, qi
Class/struct names: Solution
Java program:
import java . util . * ; class GFG { static int [ ] [ ] dp = new int [ 1005 ] [ 1005 ] ; static int KvisibleFromLeft ( int N , int K ) { if ( dp [ N ] [ K ] != - 1 ) return dp [ N ] [ K ] ; if ( N == K ) return dp [ N ] [ K ] = 1 ; if ( K == 1 ) { int ans = 1 ; for ( int i = 1 ; i < N ; i ++ ) ans *= i ; return dp [ N ] [ K ] = ans ; } return dp [ N ] [ K ] = KvisibleFromLeft ( N - 1 , K - 1 ) + ( N - 1 ) * KvisibleFromLeft ( N - 1 , K ) ; } public static void main ( String [ ] args ) { int N = 5 , K = 2 ; for ( int i = 0 ; i < 1005 ; i ++ ) { for ( int j = 0 ; j < 1005 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } System . out . print ( KvisibleFromLeft ( N , K ) ) ; } }

Index/key variables: K, N, i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG