dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
public class GFG { static int minTimeForWritingChars ( int N , int insert , int remove , int copy ) { if ( N == 0 ) return 0 ; if ( N == 1 ) return insert ; int dp [ ] = new int [ N + 1 ] ; dp [ 1 ] = insert ; for ( int i = 2 ; i <= N ; i ++ ) { if ( i % 2 == 0 ) dp [ i ] = Math . min ( dp [ i - 1 ] + insert , dp [ i / 2 ] + copy ) ; else dp [ i ] = Math . min ( dp [ i - 1 ] + insert , dp [ ( i + 1 ) / 2 ] + copy + remove ) ; } return dp [ N ] ; } public static void main ( String [ ] args ) { int N = 9 ; int insert = 1 , remove = 2 , copy = 1 ; System . out . println ( minTimeForWritingChars ( N , insert , remove , copy ) ) ; } }

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int countWays ( int n , int m ) { int count [ ] = new int [ n + 1 ] ; count [ 0 ] = 0 ; int i ; for ( i = 1 ; i <= n ; i ++ ) { if ( i > m ) count [ i ] = count [ i - 1 ] + count [ i - m ] ; else if ( i < m i == 1 ) count [ i ] = 1 ; else count [ i ] = 2 ; } return count [ n ] ; } public static void main ( String [ ] args ) { int n = 7 ; int m = 4 ; System . out . println ( " Number ▁ of ▁ ways ▁ = ▁ " + countWays ( n , m ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
public class GFG { static int LAS ( int [ ] arr , int n ) { int inc = 1 ; int dec = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ i ] > arr [ i - 1 ] ) { inc = dec + 1 ; } else if ( arr [ i ] < arr [ i - 1 ] ) { dec = inc + 1 ; } } return Math . max ( inc , dec ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 10 , 22 , 9 , 33 , 49 , 50 , 31 , 60 } ; int n = arr . length ; System . out . println ( LAS ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { public static int min ( int x , int y ) { return ( x < y ) ? x : y ; } public static int utility_fun_for_del ( String str , int i , int j ) { if ( i >= j ) return 0 ; if ( str . charAt ( i ) == str . charAt ( j ) ) { return utility_fun_for_del ( str , i + 1 , j - 1 ) ; } return 1 + Math . min ( utility_fun_for_del ( str , i + 1 , j ) , utility_fun_for_del ( str , i , j - 1 ) ) ; } public static int min_ele_del ( String str ) { return utility_fun_for_del ( str , 0 , str . length ( ) - 1 ) ; } public static void main ( String [ ] args ) { String str = " abefbac " ; System . out . println ( " Minimum ▁ element ▁ of ▁ deletions ▁ = ▁ " + min_ele_del ( str ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; public class GFG { static int dp [ ] [ ] = new int [ 2000 ] [ 2000 ] ; public static int transformation ( String s1 , String s2 , int i , int j ) { if ( i >= s1 . length ( ) || j >= s2 . length ( ) ) { return 0 ; } if ( s1 . charAt ( i ) == s2 . charAt ( j ) ) { dp [ i ] [ j ] = 1 + transformation ( s1 , s2 , i + 1 , j + 1 ) ; } if ( dp [ i ] [ j ] != - 1 ) { return dp [ i ] [ j ] ; } else { dp [ i ] [ j ] = Math . max ( transformation ( s1 , s2 , i , j + i ) , transformation ( s1 , s2 , i + 1 , j ) ) ; } return dp [ s1 . length ( ) - 1 ] [ s2 . length ( ) - 1 ] ; } public static void main ( String [ ] args ) { String s1 = " geeksforgeeks " ; String s2 = " geeks " ; int i = 0 ; int j = 0 ; for ( int [ ] row : dp ) { Arrays . fill ( row , - 1 ) ; } System . out . println ( " MINIMUM ▁ NUMBER ▁ OF ▁ DELETIONS : ▁ " + ( s1 . length ( ) - transformation ( s1 , s2 , 0 , 0 ) ) ) ; System . out . println ( " MINIMUM ▁ NUMBER ▁ OF ▁ INSERTIONS : ▁ " + ( s2 . length ( ) - transformation ( s1 , s2 , 0 , 0 ) ) ) ; System . out . println ( " LCS ▁ LENGTH : ▁ " + transformation ( s1 , s2 , 0 , 0 ) ) ; } }

Index/key variables: i, j
Iterator variables: row
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int MAX = 100 ; static int largestZigZagSumRec ( int mat [ ] [ ] , int i , int j , int n ) { if ( i == n - 1 ) return mat [ i ] [ j ] ; int zzs = 0 ; for ( int k = 0 ; k < n ; k ++ ) if ( k != j ) zzs = Math . max ( zzs , largestZigZagSumRec ( mat , i + 1 , k , n ) ) ; return zzs + mat [ i ] [ j ] ; } static int largestZigZag ( int mat [ ] [ ] , int n ) { int res = 0 ; for ( int j = 0 ; j < n ; j ++ ) res = Math . max ( res , largestZigZagSumRec ( mat , 0 , j , n ) ) ; return res ; } public static void main ( String [ ] args ) { int n = 3 ; int mat [ ] [ ] = { { 4 , 2 , 1 } , { 3 , 9 , 6 } , { 11 , 3 , 15 } } ; System . out . println ( " Largest ▁ zigzag ▁ sum : ▁ " + largestZigZag ( mat , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: j, k
Iterator variables: j, k
Class/struct names: GFG
Java program:
import java . util . ArrayList ; public class SubSet_sum_problem { static boolean [ ] [ ] dp ; static void display ( ArrayList < Integer > v ) { System . out . println ( v ) ; } static void printSubsetsRec ( int arr [ ] , int i , int sum , ArrayList < Integer > p ) { if ( i == 0 && sum != 0 && dp [ 0 ] [ sum ] ) { p . add ( arr [ i ] ) ; display ( p ) ; p . clear ( ) ; return ; } if ( i == 0 && sum == 0 ) { display ( p ) ; p . clear ( ) ; return ; } if ( dp [ i - 1 ] [ sum ] ) { ArrayList < Integer > b = new ArrayList < > ( ) ; b . addAll ( p ) ; printSubsetsRec ( arr , i - 1 , sum , b ) ; } if ( sum >= arr [ i ] && dp [ i - 1 ] [ sum - arr [ i ] ] ) { p . add ( arr [ i ] ) ; printSubsetsRec ( arr , i - 1 , sum - arr [ i ] , p ) ; } } static void printAllSubsets ( int arr [ ] , int n , int sum ) { if ( n == 0 sum < 0 ) return ; dp = new boolean [ n ] [ sum + 1 ] ; for ( int i = 0 ; i < n ; ++ i ) { dp [ i ] [ 0 ] = true ; } if ( arr [ 0 ] <= sum ) dp [ 0 ] [ arr [ 0 ] ] = true ; for ( int i = 1 ; i < n ; ++ i ) for ( int j = 0 ; j < sum + 1 ; ++ j ) dp [ i ] [ j ] = ( arr [ i ] <= j ) ? ( dp [ i - 1 ] [ j ] dp [ i - 1 ] [ j - arr [ i ] ] ) : dp [ i - 1 ] [ j ] ; if ( dp [ n - 1 ] [ sum ] == false ) { System . out . println ( " There ▁ are ▁ no ▁ subsets ▁ with " + " ▁ sum ▁ " + sum ) ; return ; } ArrayList < Integer > p = new ArrayList < > ( ) ; printSubsetsRec ( arr , n - 1 , sum , p ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int n = arr . length ; int sum = 10 ; printAllSubsets ( arr , n , sum ) ; } }

Index/key variables: i, j, n, sum
Iterator variables: i, j
Class/struct names: SubSet_sum_problem
Java program:
import java . util . * ; class GFG { static int M = 26 ; static int waysToIncreaseLCSBy1 ( String str1 , String str2 ) { int m = str1 . length ( ) , n = str2 . length ( ) ; Vector < Integer > [ ] position = new Vector [ M ] ; for ( int i = 0 ; i < M ; i ++ ) position [ i ] = new Vector < > ( ) ; for ( int i = 1 ; i <= n ; i ++ ) position [ str2 . charAt ( i - 1 ) - ' a ' ] . add ( i ) ; int [ ] [ ] lcsl = new int [ m + 2 ] [ n + 2 ] ; int [ ] [ ] lcsr = new int [ m + 2 ] [ n + 2 ] ; for ( int i = 0 ; i <= m + 1 ; i ++ ) for ( int j = 0 ; j <= n + 1 ; j ++ ) lcsl [ i ] [ j ] = lcsr [ i ] [ j ] = 0 ; for ( int i = 1 ; i <= m ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { if ( str1 . charAt ( i - 1 ) == str2 . charAt ( j - 1 ) ) lcsl [ i ] [ j ] = 1 + lcsl [ i - 1 ] [ j - 1 ] ; else lcsl [ i ] [ j ] = Math . max ( lcsl [ i - 1 ] [ j ] , lcsl [ i ] [ j - 1 ] ) ; } } for ( int i = m ; i >= 1 ; i -- ) { for ( int j = n ; j >= 1 ; j -- ) { if ( str1 . charAt ( i - 1 ) == str2 . charAt ( j - 1 ) ) lcsr [ i ] [ j ] = 1 + lcsr [ i + 1 ] [ j + 1 ] ; else lcsr [ i ] [ j ] = Math . max ( lcsr [ i + 1 ] [ j ] , lcsr [ i ] [ j + 1 ] ) ; } } int ways = 0 ; for ( int i = 0 ; i <= m ; i ++ ) { for ( char d = 0 ; d < 26 ; d ++ ) { for ( int j = 0 ; j < position [ d ] . size ( ) ; j ++ ) { int p = position [ d ] . elementAt ( j ) ; if ( lcsl [ i ] [ p - 1 ] + lcsr [ i + 1 ] [ p + 1 ] == lcsl [ m ] [ n ] ) ways ++ ; } } } return ways ; } public static void main ( String [ ] args ) { String str1 = " abcabc " ; String str2 = " abcd " ; System . out . println ( waysToIncreaseLCSBy1 ( str1 , str2 ) ) ; } }

Index/key variables: M, d, i, j, m, n
Accumulator variables: d, i, j, ways
Iterator variables: d, i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int countStr ( int n , int bCount , int cCount ) { if ( bCount < 0 cCount < 0 ) return 0 ; if ( n == 0 ) return 1 ; if ( bCount == 0 && cCount == 0 ) return 1 ; int res = countStr ( n - 1 , bCount , cCount ) ; res += countStr ( n - 1 , bCount - 1 , cCount ) ; res += countStr ( n - 1 , bCount , cCount - 1 ) ; return res ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . println ( countStr ( n , 1 , 2 ) ) ; } }

Accumulator variables: res
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int N = 4 ; static int MaximumPath ( int Mat [ ] [ ] ) { int result = 0 ; int dp [ ] [ ] = new int [ N ] [ N + 2 ] ; for ( int [ ] rows : dp ) Arrays . fill ( rows , 0 ) ; for ( int i = 0 ; i < N ; i ++ ) dp [ 0 ] [ i + 1 ] = Mat [ 0 ] [ i ] ; for ( int i = 1 ; i < N ; i ++ ) for ( int j = 1 ; j <= N ; j ++ ) dp [ i ] [ j ] = Math . max ( dp [ i - 1 ] [ j - 1 ] , Math . max ( dp [ i - 1 ] [ j ] , dp [ i - 1 ] [ j + 1 ] ) ) + Mat [ i ] [ j - 1 ] ; for ( int i = 0 ; i <= N ; i ++ ) result = Math . max ( result , dp [ N - 1 ] [ i ] ) ; return result ; } public static void main ( String arg [ ] ) { int Mat [ ] [ ] = { { 4 , 2 , 3 , 4 } , { 2 , 9 , 1 , 10 } , { 15 , 1 , 3 , 0 } , { 16 , 92 , 41 , 44 } } ; System . out . println ( MaximumPath ( Mat ) ) ; } }

Index/key variables: N, i, j
Accumulator variables: i, j
Iterator variables: i, j, rows
Class/struct names: GFG
Java program:
import java . math . * ; class GFG { static int MAX = 100001 ; static double dp [ ] = new double [ MAX ] ; static double probability ( int k , int n ) { double ans = 0.0 ; for ( int i = k ; i <= n ; ++ i ) { double res = dp [ n ] - dp [ i ] - dp [ n - i ] - n ; ans += Math . pow ( 2.0 , res ) ; } return ans ; } static void precompute ( ) { for ( int i = 2 ; i < MAX ; ++ i ) dp [ i ] = ( Math . log ( i ) / Math . log ( 2 ) ) + dp [ i - 1 ] ; } public static void main ( String args [ ] ) { precompute ( ) ; System . out . println ( probability ( 2 , 3 ) ) ; System . out . println ( probability ( 3 , 6 ) ) ; System . out . println ( probability ( 500 , 1000 ) ) ; } }

Index/key variables: MAX, i, n
Accumulator variables: ans
Iterator variables: i
Class/struct names: GFG
Java program:
public class Main { static boolean canVote ( int [ ] a , int n , int x ) { int [ ] [ ] dp = new int [ n + 1 ] [ x + 1 ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) { for ( int j = 0 ; j < x + 1 ; j ++ ) { dp [ i ] [ j ] = 0 ; } } int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += a [ i ] ; for ( int i = 1 ; i < n ; i ++ ) for ( int j = 1 ; j <= x ; j ++ ) if ( a [ i ] <= j ) dp [ i ] [ j ] = Math . max ( dp [ i - 1 ] [ j ] , a [ i ] + dp [ i - 1 ] [ j - a [ i ] ] ) ; else dp [ i ] [ j ] = dp [ i - 1 ] [ j ] ; return ( sum - dp [ n ] [ x ] >= x ) ; } public static void main ( String [ ] args ) { int n = 3 , x = 4 ; int [ ] a = { 2 , 4 , 2 } ; if ( canVote ( a , n , x ) ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } }

Index/key variables: i, j, n, x
Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: Main
Java program:
import java . util . * ; class GFG { static void printMaxSum ( int arr [ ] , int n ) { int dp [ ] = new int [ n ] ; Arrays . fill ( dp , 0 ) ; for ( int i = 0 ; i < n ; i ++ ) { dp [ i ] = arr [ i ] ; int maxi = 0 ; for ( int j = 1 ; j <= Math . sqrt ( i + 1 ) ; j ++ ) { if ( ( ( i + 1 ) % j == 0 ) && ( i + 1 ) != j ) { if ( dp [ j - 1 ] > maxi ) maxi = dp [ j - 1 ] ; if ( dp [ ( i + 1 ) / j - 1 ] > maxi && j != 1 ) maxi = dp [ ( i + 1 ) / j - 1 ] ; } } dp [ i ] += maxi ; } for ( int i = 0 ; i < n ; i ++ ) System . out . print ( dp [ i ] + " ▁ " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 1 , 4 , 6 , 5 } ; int n = arr . length ; printMaxSum ( arr , n ) ; } }

Index/key variables: i, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { static int minSum ( int ar [ ] , int n ) { if ( n <= 4 ) return Arrays . stream ( ar ) . min ( ) . getAsInt ( ) ; int [ ] sum = new int [ n ] ; sum [ 0 ] = ar [ 0 ] ; sum [ 1 ] = ar [ 1 ] ; sum [ 2 ] = ar [ 2 ] ; sum [ 3 ] = ar [ 3 ] ; for ( int i = 4 ; i < n ; i ++ ) sum [ i ] = ar [ i ] + Arrays . stream ( Arrays . copyOfRange ( sum , i - 4 , i ) ) . min ( ) . getAsInt ( ) ; return Arrays . stream ( Arrays . copyOfRange ( sum , n - 4 , n ) ) . min ( ) . getAsInt ( ) ; } public static void main ( String [ ] args ) { int ar [ ] = { 2 , 4 , 1 , 5 , 2 , 3 , 6 , 1 , 2 , 4 } ; int n = ar . length ; System . out . println ( " Minimum ▁ sum ▁ = ▁ " + minSum ( ar , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
public class GFG { static int maxAlternateSum ( int arr [ ] , int n ) { if ( n == 1 ) return arr [ 0 ] ; int min = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( min > arr [ i ] ) min = arr [ i ] ; } if ( min == arr [ 0 ] ) { return arr [ 0 ] ; } int dec [ ] = new int [ n ] ; int inc [ ] = new int [ n ] ; dec [ 0 ] = inc [ 0 ] = arr [ 0 ] ; int flag = 0 ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( arr [ j ] > arr [ i ] ) { dec [ i ] = Math . max ( dec [ i ] , inc [ j ] + arr [ i ] ) ; flag = 1 ; } else if ( arr [ j ] < arr [ i ] && flag == 1 ) inc [ i ] = Math . max ( inc [ i ] , dec [ j ] + arr [ i ] ) ; } } int result = Integer . MIN_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { if ( result < inc [ i ] ) result = inc [ i ] ; if ( result < dec [ i ] ) result = dec [ i ] ; } return result ; } public static void main ( String [ ] args ) { int arr [ ] = { 8 , 2 , 3 , 5 , 7 , 9 , 10 } ; System . out . println ( " Maximum ▁ sum ▁ = ▁ " + maxAlternateSum ( arr , arr . length ) ) ; } }

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 pad ( int n ) { padv [ 0 ] = padv [ 1 ] = padv [ 2 ] = 1 ; for ( int i = 3 ; i <= n ; i ++ ) { padv [ i ] = padv [ i - 2 ] + padv [ i - 3 ] ; } return padv [ n - 1 ] ; } public static void main ( String args [ ] ) { int n = 12 ; System . out . println ( pad ( n ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int ROW , COL , count ; static boolean isSafe ( int [ ] [ ] M , int row , int col , boolean [ ] [ ] visited ) { return ( ( row >= 0 ) && ( row < ROW ) && ( col >= 0 ) && ( col < COL ) && ( M [ row ] [ col ] == 1 && ! visited [ row ] [ col ] ) ) ; } static void DFS ( int [ ] [ ] M , int row , int col , boolean [ ] [ ] visited ) { int [ ] rowNbr = { - 1 , - 1 , - 1 , 0 , 0 , 1 , 1 , 1 } ; int [ ] colNbr = { - 1 , 0 , 1 , - 1 , 1 , - 1 , 0 , 1 } ; visited [ row ] [ col ] = true ; for ( int k = 0 ; k < 8 ; k ++ ) { if ( isSafe ( M , row + rowNbr [ k ] , col + colNbr [ k ] , visited ) ) { count ++ ; DFS ( M , row + rowNbr [ k ] , col + colNbr [ k ] , visited ) ; } } } static int largestRegion ( int [ ] [ ] M ) { boolean [ ] [ ] visited = new boolean [ ROW ] [ COL ] ; int result = 0 ; for ( int i = 0 ; i < ROW ; i ++ ) { for ( int j = 0 ; j < COL ; j ++ ) { if ( M [ i ] [ j ] == 1 && ! visited [ i ] [ j ] ) { count = 1 ; DFS ( M , i , j , visited ) ; result = Math . max ( result , count ) ; } } } return result ; } public static void main ( String args [ ] ) { int M [ ] [ ] = { { 0 , 0 , 1 , 1 , 0 } , { 1 , 0 , 1 , 1 , 0 } , { 0 , 1 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 , 1 } } ; ROW = 4 ; COL = 5 ; System . out . println ( largestRegion ( M ) ) ; } }

Index/key variables: COL, ROW, col, i, j, k, row
Accumulator variables: count, i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
class GFG { static int lucas ( int n ) { int a = 2 , b = 1 , c , i ; if ( n == 0 ) return a ; for ( i = 2 ; i <= n ; i ++ ) { c = a + b ; a = b ; b = c ; } return b ; } public static void main ( String args [ ] ) { int n = 9 ; System . out . println ( lucas ( n ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { final int MAX = 1000000 ; static int breakSum ( int n ) { int dp [ ] = new int [ n + 1 ] ; dp [ 0 ] = 0 ; dp [ 1 ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) dp [ i ] = Math . max ( dp [ i / 2 ] + dp [ i / 3 ] + dp [ i / 4 ] , i ) ; return dp [ n ] ; } public static void main ( String [ ] args ) { int n = 24 ; System . out . println ( breakSum ( n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static String longestRepeatedSubstring ( String str ) { int n = str . length ( ) ; int LCSRe [ ] [ ] = new int [ n + 1 ] [ n + 1 ] ; int i , index = 0 ; for ( i = 1 ; i <= n ; i ++ ) { for ( int j = i + 1 ; j <= n ; j ++ ) { if ( str . charAt ( i - 1 ) == str . charAt ( j - 1 ) && LCSRe [ i - 1 ] [ j - 1 ] < ( j - i ) ) { LCSRe [ i ] [ j ] = LCSRe [ i - 1 ] [ j - 1 ] + 1 ; if ( LCSRe [ i ] [ j ] > res_length ) { res_length = LCSRe [ i ] [ j ] ; index = Math . max ( i , index ) ; } } else { LCSRe [ i ] [ j ] = 0 ; } } } if ( res_length > 0 ) { for ( i = index - res_length + 1 ; i <= index ; i ++ ) { res += str . charAt ( i - 1 ) ; } } return res ; } public static void main ( String [ ] args ) { String str = " geeksforgeeks " ; System . out . println ( longestRepeatedSubstring ( str ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, res
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class Main { public static int minCost ( int cost [ ] , int n ) { int dp [ ] = new int [ n + 1 ] ; dp [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { int min_cost = Integer . MAX_VALUE ; for ( int j = 0 ; j < i ; j ++ ) if ( j < cost . length && cost [ j ] != - 1 ) { min_cost = Math . min ( min_cost , cost [ j ] + dp [ i - j - 1 ] ) ; } dp [ i ] = min_cost ; } return dp [ n ] ; } public static void main ( String [ ] args ) { int cost [ ] = { 10 , - 1 , - 1 , - 1 , - 1 } ; int W = cost . length ; System . out . print ( minCost ( cost , W ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: Main
Java program:
import java . util . * ; class GFG { static int findSum ( Vector < Integer > arr ) { int sum = 0 ; for ( int i : arr ) sum += i ; return sum ; } static void printMaxSumIs ( int [ ] arr , int n ) { @ SuppressWarnings ( " unchecked " ) Vector < Integer > [ ] L = new Vector [ n ] ; for ( int i = 0 ; i < n ; i ++ ) L [ i ] = new Vector < > ( ) ; L [ 0 ] . add ( arr [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( ( arr [ i ] > arr [ j ] ) && ( findSum ( L [ i ] ) < findSum ( L [ j ] ) ) ) { for ( int k : L [ j ] ) if ( ! L [ i ] . contains ( k ) ) L [ i ] . add ( k ) ; } } L [ i ] . add ( arr [ i ] ) ; } Vector < Integer > res = new Vector < > ( L [ 0 ] ) ; for ( Vector < Integer > x : L ) if ( findSum ( x ) > findSum ( res ) ) res = x ; for ( int i : res ) System . out . print ( i + " ▁ " ) ; System . out . println ( ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 3 , 2 , 6 , 4 , 5 , 1 } ; int n = arr . length ; printMaxSumIs ( arr , n ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j, sum
Iterator variables: i, j, k, x
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void printLIS ( Vector < Integer > arr ) { for ( int x : arr ) System . out . print ( x + " ▁ " ) ; System . out . println ( ) ; } static void constructPrintLIS ( int arr [ ] , int n ) { Vector < Integer > L [ ] = new Vector [ n ] ; for ( int i = 0 ; i < L . length ; i ++ ) L [ i ] = new Vector < Integer > ( ) ; L [ 0 ] . add ( arr [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( ( arr [ i ] > arr [ j ] ) && ( L [ i ] . size ( ) < L [ j ] . size ( ) + 1 ) ) L [ i ] = L [ j ] ; } L [ i ] . add ( arr [ i ] ) ; } Vector < Integer > max = L [ 0 ] ; for ( Vector < Integer > x : L ) if ( x . size ( ) > max . size ( ) ) max = x ; printLIS ( max ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 2 , 4 , 5 , 1 } ; int n = arr . length ; constructPrintLIS ( arr , n ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j, x
Class/struct names: GFG
Java program:
class GFG { static int lcs ( String X , String Y , int m , int n ) { int L [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ; for ( int i = 0 ; i <= m ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { if ( i == 0 j == 0 ) { L [ i ] [ j ] = 0 ; } else if ( X . charAt ( i - 1 ) == Y . charAt ( j - 1 ) ) { L [ i ] [ j ] = L [ i - 1 ] [ j - 1 ] + 1 ; } else { L [ i ] [ j ] = Math . max ( L [ i - 1 ] [ j ] , L [ i ] [ j - 1 ] ) ; } } } return L [ m ] [ n ] ; } static boolean isKPal ( String str , int k ) { int n = str . length ( ) ; StringBuilder revStr = new StringBuilder ( str ) ; revStr = revStr . reverse ( ) ; int lps = lcs ( str , revStr . toString ( ) , n , n ) ; return ( n - lps <= k ) ; } public static void main ( String [ ] args ) { String str = " abcdeca " ; int k = 2 ; if ( isKPal ( str , k ) ) { System . out . println ( " Yes " ) ; } else System . out . println ( " No " ) ; } }

Index/key variables: i, j, m, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int isKPalRec ( String str1 , String str2 , int m , int n ) { if ( m == 0 ) { return n ; } if ( n == 0 ) { return m ; } if ( str1 . charAt ( m - 1 ) == str2 . charAt ( n - 1 ) ) { return isKPalRec ( str1 , str2 , m - 1 , n - 1 ) ; } } static boolean isKPal ( String str , int k ) { String revStr = str ; revStr = reverse ( revStr ) ; int len = str . length ( ) ; return ( isKPalRec ( str , revStr , len , len ) <= k * 2 ) ; } static String reverse ( String input ) { char [ ] temparray = input . toCharArray ( ) ; int left , right = 0 ; right = temparray . length - 1 ; for ( left = 0 ; left < right ; left ++ , right -- ) { char temp = temparray [ left ] ; temparray [ left ] = temparray [ right ] ; temparray [ right ] = temp ; } return String . valueOf ( temparray ) ; } public static void main ( String [ ] args ) { String str = " acdcb " ; int k = 2 ; if ( isKPal ( str , k ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }

Index/key variables: left, right
Accumulator variables: left, right
Iterator variables: left
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int minTime ( int arr [ ] , int n ) { if ( n <= 0 ) return 0 ; int incl = arr [ 0 ] ; int excl = 0 ; for ( int i = 1 ; i < n ; i ++ ) { int incl_new = arr [ i ] + Math . min ( excl , incl ) ; int excl_new = incl ; incl = incl_new ; excl = excl_new ; } return Math . min ( incl , excl ) ; } public static void main ( String [ ] args ) { int arr1 [ ] = { 10 , 5 , 2 , 7 , 10 } ; int n1 = arr1 . length ; System . out . println ( minTime ( arr1 , n1 ) ) ; int arr2 [ ] = { 10 , 5 , 7 , 10 } ; int n2 = arr2 . length ; System . out . println ( minTime ( arr2 , n2 ) ) ; int arr3 [ ] = { 10 , 5 , 2 , 4 , 8 , 6 , 7 , 10 } ; int n3 = arr3 . length ; System . out . println ( minTime ( arr3 , n3 ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { public static int lcs ( String X , String Y ) { int m = X . length ( ) , n = Y . length ( ) ; int L [ ] [ ] = new int [ m + 1 ] [ n + 1 ] ; for ( int i = 0 ; i <= m ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { if ( i == 0 j == 0 ) L [ i ] [ j ] = 0 ; else if ( X [ i - 1 ] == Y [ j - 1 ] ) L [ i ] [ j ] = L [ i - 1 ] [ j - 1 ] + 1 ; else L [ i ] [ j ] = max ( L [ i - 1 ] [ j ] , L [ i ] [ j - 1 ] ) ; } } return L [ m ] [ n ] ; } }

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