dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
class GFG { static int lcs ( String X , String Y , int m , int n ) { if ( m == 0 n == 0 ) { return 0 ; } if ( X . charAt ( m - 1 ) == Y . charAt ( n - 1 ) ) { return 1 + lcs ( X , Y , m - 1 , n - 1 ) ; } else { return Math . max ( lcs ( X , Y , m , n - 1 ) , lcs ( X , Y , m - 1 , n ) ) ; } } public static void main ( String [ ] args ) { String X = " AGGTAB " ; String Y = " GXTXAYB " ; int m = X . length ( ) ; int n = Y . length ( ) ; System . out . println ( " Length ▁ of ▁ LCS : ▁ " + lcs ( X , Y , m , n ) ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int countPaths ( int n ) { int zB = 1 ; int zADC = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int nzB = zADC * 3 ; int nzADC = ( zADC * 2 + zB ) ; zB = nzB ; zADC = nzADC ; } return zB ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . println ( countPaths ( n ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
public class GFG { static int dp [ ] [ ] = new int [ 8 ] [ 8 ] ; static int getsteps ( int x , int y , int tx , int ty ) { if ( x == tx && y == ty ) { return dp [ 0 ] [ 0 ] ; if ( dp [ Math . abs ( x - tx ) ] [ Math . abs ( y - ty ) ] != 0 ) { return dp [ Math . abs ( x - tx ) ] [ Math . abs ( y - ty ) ] ; } else { int x1 , y1 , x2 , y2 ; if ( x <= tx ) { if ( y <= ty ) { x1 = x + 2 ; y1 = y + 1 ; x2 = x + 1 ; y2 = y + 2 ; } else { x1 = x + 2 ; y1 = y - 1 ; x2 = x + 1 ; y2 = y - 2 ; } } else if ( y <= ty ) { x1 = x - 2 ; y1 = y + 1 ; x2 = x - 1 ; y2 = y + 2 ; } else { x1 = x - 2 ; y1 = y - 1 ; x2 = x - 1 ; y2 = y - 2 ; } dp [ Math . abs ( x - tx ) ] [ Math . abs ( y - ty ) ] = Math . min ( getsteps ( x1 , y1 , tx , ty ) , getsteps ( x2 , y2 , tx , ty ) ) + 1 ; dp [ Math . abs ( y - ty ) ] [ Math . abs ( x - tx ) ] = dp [ Math . abs ( x - tx ) ] [ Math . abs ( y - ty ) ] ; return dp [ Math . abs ( x - tx ) ] [ Math . abs ( y - ty ) ] ; } } static public void main ( String [ ] args ) { int i , n , x , y , tx , ty , ans ; n = 100 ; x = 4 ; y = 5 ; tx = 1 ; ty = 1 ; if ( ( x == 1 && y == 1 && tx == 2 && ty == 2 ) || ( x == 2 && y == 2 && tx == 1 && ty == 1 ) ) { ans = 4 ; } else if ( ( x == 1 && y == n && tx == 2 && ty == n - 1 ) || ( x == 2 && y == n - 1 && tx == 1 && ty == n ) ) { ans = 4 ; } else if ( ( x == n && y == 1 && tx == n - 1 && ty == 2 ) || ( x == n - 1 && y == 2 && tx == n && ty == 1 ) ) { ans = 4 ; } else if ( ( x == n && y == n && tx == n - 1 && ty == n - 1 ) || ( x == n - 1 && y == n - 1 && tx == n && ty == n ) ) { ans = 4 ; } else { dp [ 1 ] [ 0 ] = 3 ; dp [ 0 ] [ 1 ] = 3 ; dp [ 1 ] [ 1 ] = 2 ; dp [ 2 ] [ 0 ] = 2 ; dp [ 0 ] [ 2 ] = 2 ; dp [ 2 ] [ 1 ] = 1 ; dp [ 1 ] [ 2 ] = 1 ; ans = getsteps ( x , y , tx , ty ) ; } System . out . println ( ans ) ; } }

Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; import java . lang . * ; class GFG { static void getMinimumPenalty ( String x , String y , int pxy , int pgap ) { int dp [ ] [ ] = new int [ n + m + 1 ] [ n + m + 1 ] ; for ( int [ ] x1 : dp ) Arrays . fill ( x1 , 0 ) ; for ( i = 0 ; i <= ( n + m ) ; i ++ ) { dp [ i ] [ 0 ] = i * pgap ; dp [ 0 ] [ i ] = i * pgap ; } for ( i = 1 ; i <= m ; i ++ ) { for ( j = 1 ; j <= n ; j ++ ) { if ( x . charAt ( i - 1 ) == y . charAt ( j - 1 ) ) { dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] ; } else { dp [ i ] [ j ] = Math . min ( Math . min ( dp [ i - 1 ] [ j - 1 ] + pxy , dp [ i - 1 ] [ j ] + pgap ) , dp [ i ] [ j - 1 ] + pgap ) ; } } } i = m ; j = n ; int xpos = l ; int ypos = l ; int xans [ ] = new int [ l + 1 ] ; int yans [ ] = new int [ l + 1 ] ; while ( ! ( i == 0 j == 0 ) ) { if ( x . charAt ( i - 1 ) == y . charAt ( j - 1 ) ) { xans [ xpos -- ] = ( int ) x . charAt ( i - 1 ) ; yans [ ypos -- ] = ( int ) y . charAt ( j - 1 ) ; i -- ; j -- ; } else if ( dp [ i - 1 ] [ j - 1 ] + pxy == dp [ i ] [ j ] ) { xans [ xpos -- ] = ( int ) x . charAt ( i - 1 ) ; yans [ ypos -- ] = ( int ) y . charAt ( j - 1 ) ; i -- ; j -- ; } else if ( dp [ i - 1 ] [ j ] + pgap == dp [ i ] [ j ] ) { xans [ xpos -- ] = ( int ) x . charAt ( i - 1 ) ; yans [ ypos -- ] = ( int ) ' _ ' ; i -- ; } else if ( dp [ i ] [ j - 1 ] + pgap == dp [ i ] [ j ] ) { xans [ xpos -- ] = ( int ) ' _ ' ; yans [ ypos -- ] = ( int ) y . charAt ( j - 1 ) ; j -- ; } } while ( xpos > 0 ) { if ( i > 0 ) xans [ xpos -- ] = ( int ) x . charAt ( -- i ) ; else xans [ xpos -- ] = ( int ) ' _ ' ; } while ( ypos > 0 ) { if ( j > 0 ) yans [ ypos -- ] = ( int ) y . charAt ( -- j ) ; else yans [ ypos -- ] = ( int ) ' _ ' ; } int id = 1 ; for ( i = l ; i >= 1 ; i -- ) { if ( ( char ) yans [ i ] == ' _ ' && ( char ) xans [ i ] == ' _ ' ) { id = i + 1 ; break ; } } System . out . print ( " Minimum ▁ Penalty ▁ in ▁ " + " aligning ▁ the ▁ genes ▁ = ▁ " ) ; System . out . print ( dp [ m ] [ n ] + "NEW_LINE"); System . out . println ( " The ▁ aligned ▁ genes ▁ are ▁ : " ) ; for ( i = id ; i <= l ; i ++ ) { System . out . print ( ( char ) xans [ i ] ) ; } System . out . print ( "NEW_LINE"); for ( i = id ; i <= l ; i ++ ) { System . out . print ( ( char ) yans [ i ] ) ; } return ; } public static void main ( String [ ] args ) { String gene1 = " AGGGCT " ; String gene2 = " AGGCA " ; int misMatchPenalty = 3 ; int gapPenalty = 2 ; getMinimumPenalty ( gene1 , gene2 , misMatchPenalty , gapPenalty ) ; } }

Index/key variables: i, j, m, n
Accumulator variables: i, j, xpos, ypos
Iterator variables: i, j, x1
Class/struct names: GFG
Java program:
class GFG { static int sumSubSequence ( int [ ] arr , int len , int m ) { int sum = 0 ; for ( int x : arr ) { sum += x ; } int [ ] [ ] dp = new int [ len + 1 ] [ sum + 1 ] ; for ( int i = 0 ; i <= len ; i ++ ) dp [ i ] [ 0 ] ++ ; for ( int i = 1 ; i <= len ; i ++ ) { dp [ i ] [ arr [ i - 1 ] ] ++ ; for ( int j = 1 ; j <= sum ; j ++ ) { if ( dp [ i - 1 ] [ j ] > 0 ) { dp [ i ] [ j ] ++ ; dp [ i ] [ j + arr [ i - 1 ] ] ++ ; } } } int count = 0 ; for ( int j = 1 ; j <= sum ; j ++ ) if ( dp [ len ] [ j ] > 0 ) if ( j % m == 0 ) count += dp [ len ] [ j ] ; return count ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 } ; int m = 3 ; int len = arr . length ; System . out . print ( sumSubSequence ( arr , len , m ) + "NEW_LINE"); } }

Index/key variables: i, j, len
Accumulator variables: count, i, j, sum
Iterator variables: i, j, x
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int lds ( int arr [ ] , int n ) { int lds [ ] = new int [ n ] ; int i , j , max = 0 ; for ( i = 0 ; i < n ; i ++ ) lds [ i ] = 1 ; for ( i = 1 ; i < n ; i ++ ) for ( j = 0 ; j < i ; j ++ ) if ( arr [ i ] < arr [ j ] && lds [ i ] < lds [ j ] + 1 ) lds [ i ] = lds [ j ] + 1 ; for ( i = 0 ; i < n ; i ++ ) if ( max < lds [ i ] ) max = lds [ i ] ; return max ; } public static void main ( String [ ] args ) { int arr [ ] = { 15 , 27 , 14 , 38 , 63 , 55 , 46 , 65 , 85 } ; int n = arr . length ; System . out . print ( " Length ▁ of ▁ LDS ▁ is ▁ " + lds ( arr , n ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int MAX = 100 ; static void binomialCoeff ( int C [ ] , int n ) { for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = Math . min ( i , n ) ; j > 0 ; j -- ) C [ j ] = C [ j ] + C [ j - 1 ] ; } } static int sumOfproduct ( int n ) { int sum = 0 ; int C [ ] = new int [ MAX ] ; binomialCoeff ( C , n ) ; for ( int i = 0 ; i <= n ; i ++ ) sum += C [ i ] * C [ i + 1 ] ; return sum ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . println ( sumOfproduct ( n ) ) ; } }

Index/key variables: MAX, i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int MAX = 100 ; static void binomialCoeff ( int n , int C [ ] ) { for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = Math . min ( i , n ) ; j > 0 ; j -- ) C [ j ] = C [ j ] + C [ j - 1 ] ; } } static int summation ( int n ) { int C [ ] = new int [ MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) C [ i ] = 0 ; binomialCoeff ( n , C ) ; int sum = 0 ; for ( int i = 0 ; i <= n ; i ++ ) sum += ( i * C [ i ] ) ; return sum ; } public static void main ( String args [ ] ) { int n = 2 ; System . out . println ( summation ( n ) ) ; } }

Index/key variables: MAX, i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int binomialCoeff ( int n , int k ) { int [ ] C = new int [ k + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = Math . min ( i , k ) ; j > 0 ; j -- ) C [ j ] = C [ j ] + C [ j - 1 ] ; } return C [ k ] ; } static int countArray ( int N , int K ) { return binomialCoeff ( K - 1 , N - 1 ) ; } public static void main ( String [ ] args ) { int N = 2 , K = 3 ; System . out . println ( countArray ( N , K ) ) ; } }

Index/key variables: j, k
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class data { int element ; int position ; } ; static data findMinElement ( int arr [ ] , int n ) { data result = new data ( ) ; int [ ] prefixSum = new int [ n ] ; int [ ] suffixSum = new int [ n ] ; prefixSum [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { prefixSum [ i ] = prefixSum [ i - 1 ] + arr [ i ] ; } suffixSum [ n - 1 ] = arr [ n - 1 ] ; for ( int i = n - 2 ; i >= 0 ; i -- ) { suffixSum [ i ] = suffixSum [ i + 1 ] + arr [ i ] ; } int min = suffixSum [ 0 ] ; int pos = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { if ( Math . abs ( suffixSum [ i + 1 ] - prefixSum [ i ] ) < min ) { min = Math . abs ( suffixSum [ i + 1 ] - prefixSum [ i ] ) ; if ( suffixSum [ i + 1 ] < prefixSum [ i ] ) pos = i + 1 ; else pos = i ; } } result . element = min ; result . position = pos ; return result ; } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 1 , 2 , 3 , 4 } ; int n = arr . length ; data values ; values = findMinElement ( arr , n ) ; System . out . println ( " Minimum ▁ element ▁ : ▁ " + values . element + " Position : " + values.position); } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, data
Java program:
import java . io . * ; class GFG { static int N = 100 ; public static int count ( int n , int c , int a [ ] , int b [ ] ) { int need [ ] = new int [ N ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i + n ] = a [ i ] ; b [ i + n ] = b [ i ] ; } int s = 0 ; int tank = 0 ; for ( int i = 0 ; i < 2 * n ; i ++ ) { tank += a [ i ] ; tank = Math . min ( tank , c ) ; tank -= b [ i ] ; if ( tank < 0 ) { tank = 0 ; s = i + 1 ; } } if ( s >= n ) return 0 ; int ans = 1 ; need [ s + n ] = 0 ; for ( int i = 1 ; i < n ; i ++ ) { int id = s + n - i ; need [ id ] = Math . max ( 0 , need [ id + 1 ] + b [ id ] - Math . min ( a [ id ] , c ) ) ; if ( need [ id ] == 0 ) ans ++ ; } return ans ; } public static void main ( String args [ ] ) { int n = 3 ; int c = 3 ; int [ ] a = new int [ ] { 3 , 1 , 2 , 0 , 0 , 0 } ; int [ ] b = new int [ ] { 2 , 2 , 2 , 0 , 0 , 0 } ; System . out . print ( count ( n , c , a , b ) + "NEW_LINE"); } }

Index/key variables: N, i, id
Accumulator variables: ans, i, tank
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static void printEqualSumSets ( int [ ] arr , int n ) { int i , currSum , sum = 0 ; for ( i = 0 ; i < arr . length ; i ++ ) sum += arr [ i ] ; if ( ( sum & 1 ) == 1 ) { System . out . print ( " - 1" ) ; return ; } int k = sum >> 1 ; boolean [ ] [ ] dp = new boolean [ n + 1 ] [ k + 1 ] ; for ( i = 1 ; i <= k ; i ++ ) dp [ 0 ] [ i ] = false ; for ( i = 0 ; i <= n ; i ++ ) dp [ i ] [ 0 ] = true ; for ( i = 1 ; i <= n ; i ++ ) { for ( currSum = 1 ; currSum <= k ; currSum ++ ) { dp [ i ] [ currSum ] = dp [ i - 1 ] [ currSum ] ; if ( arr [ i - 1 ] <= currSum ) dp [ i ] [ currSum ] = dp [ i ] [ currSum ] | dp [ i - 1 ] [ currSum - arr [ i - 1 ] ] ; } } List < Integer > set1 = new ArrayList < Integer > ( ) ; List < Integer > set2 = new ArrayList < Integer > ( ) ; if ( ! dp [ n ] [ k ] ) { System . out . print ( "-1NEW_LINE"); return ; } i = n ; currSum = k ; while ( i > 0 && currSum >= 0 ) { if ( dp [ i - 1 ] [ currSum ] ) { i -- ; set2 . add ( arr [ i ] ) ; } else if ( dp [ i - 1 ] [ currSum - arr [ i - 1 ] ] ) { i -- ; currSum -= arr [ i ] ; set1 . add ( arr [ i ] ) ; } } System . out . print ( " Set ▁ 1 ▁ elements : ▁ " ) ; for ( i = 0 ; i < set1 . size ( ) ; i ++ ) System . out . print ( set1 . get ( i ) + " ▁ " ) ; System . out . print ( " Set 2 elements : "); for ( i = 0 ; i < set2 . size ( ) ; i ++ ) System . out . print ( set2 . get ( i ) + " ▁ " ) ; } public static void main ( String args [ ] ) { int [ ] arr = new int [ ] { 5 , 5 , 1 , 11 } ; int n = arr . length ; printEqualSumSets ( arr , n ) ; } }

Index/key variables: currSum, i, k, n
Accumulator variables: currSum, i, sum
Iterator variables: currSum, i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static double largestSumOfAverages ( int [ ] A , int K ) { int n = A . length ; double [ ] pre_sum = new double [ n + 1 ] ; pre_sum [ 0 ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) pre_sum [ i + 1 ] = pre_sum [ i ] + A [ i ] ; double [ ] dp = new double [ n ] ; double sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) dp [ i ] = ( pre_sum [ n ] - pre_sum [ i ] ) / ( n - i ) ; for ( int k = 0 ; k < K - 1 ; k ++ ) for ( int i = 0 ; i < n ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) dp [ i ] = Math . max ( dp [ i ] , ( pre_sum [ j ] - pre_sum [ i ] ) / ( j - i ) + dp [ j ] ) ; return dp [ 0 ] ; } public static void main ( String [ ] args ) { int [ ] A = { 9 , 1 , 2 , 3 , 9 } ; System . out . println ( largestSumOfAverages ( A , K ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
import java . io . * ; public class GFG { static int N = 105 ; static int M = 1001 ; static int INF = - 1111111111 ; static int maxSum ( int [ ] [ ] arr ) { int [ ] [ ] dp = new int [ N ] [ M ] ; int [ ] current_arr = new int [ M ] ; int [ ] maxsum = new int [ M ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) dp [ i ] [ j ] = - 1 ; } current_arr [ 0 ] = 0 ; dp [ 0 ] [ 0 ] = 0 ; for ( int i = 1 ; i <= 5 ; i ++ ) { int len = arr [ i - 1 ] [ 0 ] ; for ( int j = 1 ; j <= len ; j ++ ) { current_arr [ j ] = arr [ i - 1 ] [ j ] ; current_arr [ j ] += current_arr [ j - 1 ] ; maxsum [ j ] = INF ; } for ( int j = 1 ; j <= len && j <= 6 ; j ++ ) for ( int k = 1 ; k <= len ; k ++ ) if ( j + k - 1 <= len ) maxsum [ j ] = Math . max ( maxsum [ j ] , current_arr [ j + k - 1 ] - current_arr [ k - 1 ] ) ; for ( int j = 0 ; j <= 6 ; j ++ ) dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ; for ( int j = 1 ; j <= 6 ; j ++ ) for ( int cur = 1 ; cur <= j && cur <= len ; cur ++ ) dp [ i ] [ j ] = Math . max ( dp [ i ] [ j ] , dp [ i - 1 ] [ j - cur ] + maxsum [ cur ] ) ; } int ans = 0 ; for ( int i = 0 ; i <= 6 ; i ++ ) ans = Math . max ( ans , dp [ 5 ] [ i ] ) ; return ans ; } public static void main ( String args [ ] ) { int [ ] [ ] arr = { { 3 , 2 , 3 , 5 } , { 2 , 7 , - 1 } , { 2 , 8 , 10 } , { 4 , 5 , 2 , 6 , 1 } , { 3 , 2 , 3 , - 2 } } ; System . out . println ( " Maximum ▁ sum ▁ can ▁ be ▁ " + " obtained ▁ is ▁ : ▁ " + maxSum ( arr ) ) ; } }

Index/key variables: M, N, cur, i, j
Accumulator variables: cur, i, j, k
Iterator variables: cur, i, j, k
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int findMaxVal ( int [ ] arr , int n , int num , int maxLimit ) { int ind ; int val ; int [ ] [ ] dp = new int [ n ] [ maxLimit + 1 ] ; for ( ind = 0 ; ind < n ; ind ++ ) { for ( val = 0 ; val <= maxLimit ; val ++ ) { if ( ind == 0 ) { if ( num - arr [ ind ] == val num + arr [ ind ] == val ) { dp [ ind ] [ val ] = 1 ; } else { dp [ ind ] [ val ] = 0 ; } } else { if ( val - arr [ ind ] >= 0 && val + arr [ ind ] <= maxLimit ) { if ( dp [ ind - 1 ] [ val - arr [ ind ] ] == 1 dp [ ind - 1 ] [ val + arr [ ind ] ] == 1 ) dp [ ind ] [ val ] = 1 ; } else if ( val - arr [ ind ] >= 0 ) { dp [ ind ] [ val ] = dp [ ind - 1 ] [ val - arr [ ind ] ] ; } else if ( val + arr [ ind ] <= maxLimit ) { dp [ ind ] [ val ] = dp [ ind - 1 ] [ val + arr [ ind ] ] ; } else { dp [ ind ] [ val ] = 0 ; } } } } for ( val = maxLimit ; val >= 0 ; val -- ) { if ( dp [ n - 1 ] [ val ] == 1 ) { return val ; } } return - 1 ; } public static void main ( String args [ ] ) { int num = 1 ; int [ ] arr = new int [ ] { 3 , 10 , 6 , 4 , 5 } ; int n = arr . length ; int maxLimit = 15 ; System . out . print ( findMaxVal ( arr , n , num , maxLimit ) ) ; } }

Index/key variables: ind, n, val
Accumulator variables: ind, val
Iterator variables: ind, val
Class/struct names: GFG
Java program:
class GFG { public static int gen ( int n ) { if ( n == 0 ) return 0 ; else if ( n == 1 ) return 1 ; else if ( n % 2 == 0 ) return 4 * gen ( n / 2 ) ; else if ( n % 2 == 1 ) return 4 * gen ( n / 2 ) + 1 ; return 0 ; } public static void moserDeBruijn ( int n ) { for ( int i = 0 ; i < n ; i ++ ) System . out . print ( gen ( i ) + " ▁ " ) ; System . out . println ( ) ; } public static void main ( String args [ ] ) { int n = 15 ; System . out . println ( " First ▁ " + n + " ▁ terms ▁ of ▁ " + " Moser - de ▁ Bruijn ▁ Sequence ▁ : ▁ " ) ; moserDeBruijn ( n ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int A [ ] [ ] = { { 2 } , { 3 , 9 } , { 1 , 6 , 7 } } ; static int minSumPath ( ) { int [ ] memo = new int [ A . length ] ; int n = A . length - 1 ; for ( int i = 0 ; i < A [ n ] . length ; i ++ ) memo [ i ] = A [ n ] [ i ] ; for ( int i = A . length - 2 ; i >= 0 ; i -- ) for ( int j = 0 ; j < A [ i ] . length ; j ++ ) memo [ j ] = A [ i ] [ j ] + ( int ) Math . min ( memo [ j ] , memo [ j + 1 ] ) ; return memo [ 0 ] ; } public static void main ( String args [ ] ) { System . out . print ( minSumPath ( ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
static boolean isPossible ( int index , int sum ) { if ( index == n ) { if ( ( sum % M ) == 0 ) return true ; return false ; } boolean placeAdd = isPossible ( index + 1 , sum + arr [ index ] ) ; boolean placeMinus = isPossible ( index + 1 , sum - arr [ index ] ) ; if ( placeAdd placeMinus ) return true ; return false ; }

Index/key variables: index
Java program:
import java . util . Arrays ; class GFG { static int MAX = 100 ; static int dp [ ] [ ] = new int [ MAX ] [ MAX ] ; static int countRemovals ( int a [ ] , int i , int j , int k ) { if ( i >= j ) return 0 ; else if ( ( a [ j ] - a [ i ] ) <= k ) return 0 ; else if ( dp [ i ] [ j ] != - 1 ) return dp [ i ] [ j ] ; else if ( ( a [ j ] - a [ i ] ) > k ) { dp [ i ] [ j ] = 1 + Math . min ( countRemovals ( a , i + 1 , j , k ) , countRemovals ( a , i , j - 1 , k ) ) ; } return dp [ i ] [ j ] ; } static int removals ( int a [ ] , int n , int k ) { Arrays . sort ( a ) ; for ( int [ ] rows : dp ) Arrays . fill ( rows , - 1 ) ; if ( n == 1 ) return 0 ; else return countRemovals ( a , 0 , n - 1 , k ) ; } public static void main ( String [ ] args ) { int a [ ] = { 1 , 3 , 4 , 9 , 10 , 11 , 12 , 17 , 20 } ; int n = a . length ; int k = 4 ; System . out . print ( removals ( a , n , k ) ) ; } }

Index/key variables: MAX, i, j
Iterator variables: rows
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int findInd ( int key , int i , int n , int k , int arr [ ] ) { int start , end , mid , ind = - 1 ; start = i + 1 ; end = n - 1 ; while ( start < end ) { mid = start + ( end - start ) / 2 ; if ( arr [ mid ] - key <= k ) { ind = mid ; start = mid + 1 ; } else { end = mid ; } } return ind ; } static int removals ( int arr [ ] , int n , int k ) { int i , j , ans = n - 1 ; Arrays . sort ( arr ) ; for ( i = 0 ; i < n ; i ++ ) { j = findInd ( arr [ i ] , i , n , k , arr ) ; if ( j != - 1 ) { ans = Math . min ( ans , n - ( j - i + 1 ) ) ; } } return ans ; } public static void main ( String args [ ] ) { int a [ ] = { 1 , 3 , 4 , 9 , 10 , 11 , 12 , 17 , 20 } ; int n = a . length ; int k = 4 ; System . out . println ( removals ( a , n , k ) ) ; } }

Index/key variables: i, mid
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int countPairs ( int a [ ] , int n ) { int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) if ( ( a [ i ] & a [ j ] ) == 0 ) count += 2 ; } return count ; } public static void main ( String arg [ ] ) { int a [ ] = { 3 , 4 , 2 } ; int n = a . length ; System . out . print ( countPairs ( a , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int N = 15 ; public static int countPairs ( int a [ ] , int n ) { HashMap < Integer , Integer > hash = new HashMap < > ( ) ; int dp [ ] [ ] = new int [ 1 << N ] [ N + 1 ] ; for ( int i = 0 ; i < n ; ++ i ) { if ( hash . containsKey ( a [ i ] ) ) { hash . replace ( a [ i ] , hash . get ( a [ i ] ) + 1 ) ; } else { hash . put ( a [ i ] , 1 ) ; } } for ( int mask = 0 ; mask < ( 1 << N ) ; ++ mask ) { if ( ( mask & 1 ) != 0 ) { if ( hash . containsKey ( mask ) ) { dp [ mask ] [ 0 ] = hash . get ( mask ) ; } if ( hash . containsKey ( mask ^ 1 ) ) { dp [ mask ] [ 0 ] += hash . get ( mask ^ 1 ) ; } } else { if ( hash . containsKey ( mask ) ) { dp [ mask ] [ 0 ] = hash . get ( mask ) ; } } for ( int i = 1 ; i <= N ; ++ i ) { if ( ( mask & ( 1 << i ) ) != 0 ) { dp [ mask ] [ i ] = dp [ mask ] [ i - 1 ] + dp [ mask ^ ( 1 << i ) ] [ i - 1 ] ; } else { dp [ mask ] [ i ] = dp [ mask ] [ i - 1 ] ; } } } int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ans += dp [ ( ( 1 << N ) - 1 ) ^ a [ i ] ] [ N ] ; } return ans ; } public static void main ( String [ ] args ) { int a [ ] = { 5 , 4 , 1 , 6 } ; int n = a . length ; System . out . print ( countPairs ( a , n ) ) ; } }

Index/key variables: N, i, mask
Accumulator variables: ans, i
Iterator variables: i, mask
Class/struct names: GFG
Java program:
import java . io . * ; import java . math . * ; class GFG { static long dp [ ] [ ] = new long [ 1000 ] [ 1000 ] ; static long sum ( int a [ ] , int i , int j ) { long ans = 0 ; for ( int m = i ; m <= j ; m ++ ) ans = ( ans + a [ m ] ) % 100 ; return ans ; } static long solve ( int a [ ] , int i , int j ) { if ( i == j ) return 0 ; if ( dp [ i ] [ j ] != - 1 ) return dp [ i ] [ j ] ; dp [ i ] [ j ] = 100000000 ; for ( int k = i ; k < j ; k ++ ) { dp [ i ] [ j ] = Math . min ( dp [ i ] [ j ] , ( solve ( a , i , k ) + solve ( a , k + 1 , j ) + ( sum ( a , i , k ) * sum ( a , k + 1 , j ) ) ) ) ; } return dp [ i ] [ j ] ; } static void initialize ( int n ) { for ( int i = 0 ; i <= n ; i ++ ) for ( int j = 0 ; j <= n ; j ++ ) dp [ i ] [ j ] = - 1 ; } public static void main ( String args [ ] ) { int a [ ] = { 40 , 60 , 20 } ; int n = a . length ; initialize ( n ) ; System . out . println ( solve ( a , 0 , n - 1 ) ) ; } }

Index/key variables: i, j, m
Accumulator variables: i, j, k, m
Iterator variables: i, j, k, m
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void reverseFibonacci ( int n ) { int a [ ] = new int [ n ] ; a [ 0 ] = 0 ; a [ 1 ] = 1 ; for ( int i = 2 ; i < n ; i ++ ) { a [ i ] = a [ i - 2 ] + a [ i - 1 ] ; } for ( int i = n - 1 ; i >= 0 ; i -- ) { System . out . print ( a [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int n = 5 ; reverseFibonacci ( n ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG