dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class GFG { static final int MAX = 1000 ; static boolean isPossible ( int n , int index , int sum , int M , int arr [ ] , int dp [ ] [ ] ) { if ( index == n ) { if ( ( sum % M ) == 0 ) return true ; return false ; } else if ( sum < 0 sum >= MAX ) return false ; if ( dp [ index ] [ sum ] != - 1 ) { if ( dp [ index ] [ sum ] == 0 ) return false ; return true ; } boolean placeAdd = isPossible ( n , index + 1 , sum + arr [ index ] , M , arr , dp ) ; boolean placeMinus = isPossible ( n , index + 1 , sum - arr [ index ] , M , arr , dp ) ; boolean res = ( placeAdd placeMinus ) ; dp [ index ] [ sum ] = ( res ) ? 1 : 0 ; return res ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 2 , 3 , 4 , 6 } ; int n = arr . length ; int M = 4 ; int dp [ ] [ ] = new int [ n + 1 ] [ MAX ] ; for ( int i = 0 ; i < n + 1 ; i ++ ) Arrays . fill ( dp [ i ] , - 1 ) ; boolean res ; res = isPossible ( n , 0 , 0 , M , arr , dp ) ; System . out . println ( ( res ? " True " : " False " ) ) ; } }

Index/key variables: MAX, i, index, sum
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static final int MAX_NODES = 100 ; static int in [ ] = new int [ MAX_NODES ] ; static int out [ ] = new int [ MAX_NODES ] ; static void dfs1 ( ArrayList < ArrayList < Integer > > v , int u , int parent ) { in [ u ] = 0 ; for ( int j = 0 ; j < v . get ( u ) . size ( ) ; j ++ ) { int child = v . get ( u ) . get ( j ) ; if ( child == parent ) continue ; dfs1 ( v , child , u ) ; in [ u ] = Math . max ( in [ u ] , 1 + in [ child ] ) ; } } static void dfs2 ( ArrayList < ArrayList < Integer > > v , int u , int parent ) { int mx1 = - 1 , mx2 = - 1 ; for ( int j = 0 ; j < v . get ( u ) . size ( ) ; j ++ ) { int child = v . get ( u ) . get ( j ) ; if ( child == parent ) continue ; if ( in [ child ] >= mx1 ) { mx2 = mx1 ; mx1 = in [ child ] ; } else if ( in [ child ] > mx2 ) mx2 = in [ child ] ; } for ( int j = 0 ; j < v . get ( u ) . size ( ) ; j ++ ) { int child = v . get ( u ) . get ( j ) ; if ( child == parent ) continue ; int longest = mx1 ; if ( mx1 == in [ child ] ) longest = mx2 ; out [ child ] = 1 + Math . max ( out [ u ] , 1 + longest ) ; dfs2 ( v , child , u ) ; } } static void addEdge ( ArrayList < ArrayList < Integer > > adj , int u , int v ) { adj . get ( u ) . add ( v ) ; adj . get ( v ) . add ( u ) ; } static void printHeights ( ArrayList < ArrayList < Integer > > v , int n ) { dfs1 ( v , 1 , 0 ) ; dfs2 ( v , 1 , 0 ) ; for ( int i = 1 ; i < n ; i ++ ) System . out . println ( " The ▁ maximum ▁ height ▁ when ▁ node ▁ " + i + " ▁ is ▁ considered ▁ as ▁ root ▁ is ▁ " + Math . max ( in [ i ] , out [ i ] ) ) ; } public static void main ( String [ ] args ) { int V = 12 ; ArrayList < ArrayList < Integer > > adj = new ArrayList < ArrayList < Integer > > ( V + 1 ) ; for ( int i = 0 ; i < V ; i ++ ) adj . add ( new ArrayList < Integer > ( ) ) ; addEdge ( adj , 1 , 2 ) ; addEdge ( adj , 1 , 3 ) ; addEdge ( adj , 1 , 4 ) ; addEdge ( adj , 2 , 5 ) ; addEdge ( adj , 2 , 6 ) ; addEdge ( adj , 3 , 7 ) ; addEdge ( adj , 7 , 10 ) ; addEdge ( adj , 7 , 11 ) ; addEdge ( adj , 4 , 8 ) ; addEdge ( adj , 4 , 9 ) ; printHeights ( adj , V ) ; } }

Index/key variables: MAX_NODES, child, i, u
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static int findGolomb ( int n ) { if ( n == 1 ) return 1 ; return 1 + findGolomb ( n - findGolomb ( findGolomb ( n - 1 ) ) ) ; } public static void printGolomb ( int n ) { for ( int i = 1 ; i <= n ; i ++ ) System . out . print ( findGolomb ( i ) + " ▁ " ) ; } public static void main ( String [ ] args ) { int n = 9 ; printGolomb ( n ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int max ( int a , int b ) { return ( a > b ) ? a : b ; } static void printknapSack ( int W , int wt [ ] , int val [ ] , int n ) { int i , w ; int K [ ] [ ] = new int [ n + 1 ] [ W + 1 ] ; for ( i = 0 ; i <= n ; i ++ ) { for ( w = 0 ; w <= W ; w ++ ) { if ( i == 0 w == 0 ) K [ i ] [ w ] = 0 ; else if ( wt [ i - 1 ] <= w ) K [ i ] [ w ] = Math . max ( val [ i - 1 ] + K [ i - 1 ] [ w - wt [ i - 1 ] ] , K [ i - 1 ] [ w ] ) ; else K [ i ] [ w ] = K [ i - 1 ] [ w ] ; } } int res = K [ n ] [ W ] ; System . out . println ( res ) ; w = W ; for ( i = n ; i > 0 && res > 0 ; i -- ) { if ( res == K [ i - 1 ] [ w ] ) continue ; else { System . out . print ( wt [ i - 1 ] + " ▁ " ) ; res = res - val [ i - 1 ] ; w = w - wt [ i - 1 ] ; } } } public static void main ( String arg [ ] ) { int val [ ] = { 60 , 100 , 120 } ; int wt [ ] = { 10 , 20 , 30 } ; int W = 50 ; int n = val . length ; printknapSack ( W , wt , val , n ) ; } }

Index/key variables: W, i, n, w
Accumulator variables: i, w
Iterator variables: i, w
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int removals ( int arr [ ] , int n , int k ) { Arrays . sort ( arr ) ; int dp [ ] = new int [ n ] ; Arrays . fill ( dp , - 1 ) ; int ans = n - 1 ; dp [ 0 ] = 0 ; for ( int i = 1 ; i < n ; i ++ ) { dp [ i ] = i ; int j = dp [ i - 1 ] ; while ( j != i && arr [ i ] - arr [ j ] > k ) { j ++ ; } dp [ i ] = Integer . min ( dp [ i ] , j ) ; ans = Integer . min ( ans , ( n - ( i - j + 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 . print ( removals ( a , n , k ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int maximumSegments ( int n , int a , int b , int c ) { int dp [ ] = new int [ n + 10 ] ; Arrays . fill ( dp , - 1 ) ; dp [ 0 ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( dp [ i ] != - 1 ) { dp [ i + a ] = Math . max ( dp [ i ] + 1 , dp [ i + a ] ) ; dp [ i + b ] = Math . max ( dp [ i ] + 1 , dp [ i + b ] ) ; dp [ i + c ] = Math . max ( dp [ i ] + 1 , dp [ i + c ] ) ; } } return dp [ n ] ; } public static void main ( String arg [ ] ) { int n = 7 , a = 5 , b = 2 , c = 5 ; System . out . print ( maximumSegments ( n , a , b , c ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; import java . math . * ; class GFG { public static int getMaximumSum ( int arr [ ] ) { int n = arr . length ; int max = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { max = Math . max ( max , arr [ i ] ) ; } int [ ] freq = new int [ max + 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { freq [ arr [ i ] ] ++ ; } int ans = 0 , i = max ; while ( i > 0 ) { if ( freq [ i ] > 0 ) { ans += i ; freq [ i - 1 ] -- ; freq [ i ] -- ; } else { i -- ; } } return ans ; } public static void main ( String [ ] args ) { int [ ] a = { 1 , 2 , 3 } ; System . out . println ( getMaximumSum ( a ) ) ; } }

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { public static void sequence ( int n ) { int f [ ] = new int [ n + 1 ] ; f [ 0 ] = 0 ; f [ 1 ] = 1 ; f [ 2 ] = 1 ; System . out . print ( f [ 1 ] + " ▁ " + f [ 2 ] + " ▁ " ) ; for ( int i = 3 ; i <= n ; i ++ ) { f [ i ] = f [ f [ i - 1 ] ] + f [ i - f [ i - 1 ] ] ; System . out . print ( f [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int n = 13 ; sequence ( n ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int longestSubsequenceCommonSegment ( int k , String s1 , String s2 ) { int n = s1 . length ( ) ; int m = s2 . length ( ) ; int lcs [ ] [ ] = new int [ n + 1 ] [ m + 1 ] ; int cnt [ ] [ ] = new int [ n + 1 ] [ m + 1 ] ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= m ; j ++ ) { lcs [ i ] [ j ] = Math . max ( lcs [ i - 1 ] [ j ] , lcs [ i ] [ j - 1 ] ) ; if ( s1 . charAt ( i - 1 ) == s2 . charAt ( j - 1 ) ) cnt [ i ] [ j ] = cnt [ i - 1 ] [ j - 1 ] + 1 ; if ( cnt [ i ] [ j ] >= k ) { for ( int a = k ; a <= cnt [ i ] [ j ] ; a ++ ) lcs [ i ] [ j ] = Math . max ( lcs [ i ] [ j ] , lcs [ i - a ] [ j - a ] + a ) ; } } } return lcs [ n ] [ m ] ; } public static void main ( String [ ] args ) { int k = 4 ; String s1 = " aggasdfa " ; String s2 = " aggajasdfa " ; System . out . println ( longestSubsequenceCommonSegment ( k , s1 , s2 ) ) ; } }

Index/key variables: i, j, m, n
Accumulator variables: a, i, j
Iterator variables: a, i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class pair { int Item1 , Item2 ; pair ( int f , int s ) { Item1 = f ; Item2 = s ; } } class GFG { static int row = 5 ; static int col = 5 ; static boolean isPath ( int [ ] [ ] arr ) { int [ ] [ ] dir = { { 0 , 1 } , { 0 , - 1 } , { 1 , 0 } , { - 1 , 0 } } ; Queue < pair > q = new LinkedList < > ( ) ; q . add ( new pair ( 0 , 0 ) ) ; while ( q . size ( ) > 0 ) { pair p = ( q . peek ( ) ) ; q . remove ( ) ; arr [ p . Item1 ] [ p . Item2 ] = - 1 ; if ( p == new pair ( row - 1 , col - 1 ) ) return true ; for ( int i = 0 ; i < 4 ; i ++ ) { int a = p . Item1 + dir [ i ] [ 0 ] ; int b = p . Item2 + dir [ i ] [ 1 ] ; if ( a >= 0 && b >= 0 && a < row && b < col && arr [ a ] [ b ] != - 1 ) { q . add ( new pair ( a , b ) ) ; } } } return false ; } public static void main ( String [ ] args ) { int [ ] [ ] arr = { { 0 , 0 , 0 , - 1 , 0 } , { - 1 , 0 , 0 , - 1 , - 1 } , { 0 , 0 , 0 , - 1 , 0 } , { - 1 , 0 , - 1 , 0 , - 1 } , { 0 , 0 , - 1 , 0 , 0 } } ; if ( isPath ( arr ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: a, b, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, pair
Java program:
import java . util . * ; class GFG { static final int SIZE = 10 ; static int start , finish ; static void longSubarrWthSumDivByK ( int arr [ ] , int n , int k ) { HashMap < Integer , Integer > um = new HashMap < > ( ) ; int [ ] mod_arr = new int [ n ] ; int curr_sum = 0 , max = 0 ; for ( int i = 0 ; i < n ; i ++ ) { curr_sum += arr [ i ] ; mod_arr [ i ] = ( ( curr_sum % k ) + k ) % k ; } for ( int i = 0 ; i < n ; i ++ ) { if ( mod_arr [ i ] == 0 ) { max = i + 1 ; start = 0 ; finish = i ; } else if ( ! um . containsKey ( mod_arr [ i ] ) ) um . put ( mod_arr [ i ] , i ) ; else if ( max < ( i - um . get ( mod_arr [ i ] ) ) ) { max = i - um . get ( mod_arr [ i ] ) ; start = um . get ( mod_arr [ i ] ) + 1 ; finish = i ; } } } static void findLargestSubmatrix ( int mat [ ] [ ] , int n , int k ) { int finalLeft = 0 , finalRight = 0 , finalTop = 0 , finalBottom = 0 ; int left , right , i , maxArea = 0 ; int [ ] temp = new int [ n ] ; for ( left = 0 ; left < n ; left ++ ) { Arrays . fill ( temp , 0 ) ; for ( right = left ; right < n ; right ++ ) { for ( i = 0 ; i < n ; ++ i ) temp [ i ] += mat [ i ] [ right ] ; longSubarrWthSumDivByK ( temp , n , k ) ; if ( maxArea < ( ( right - left + 1 ) * ( finish - start + 1 ) ) ) { finalLeft = left ; finalRight = right ; finalTop = start ; finalBottom = finish ; maxArea = ( right - left + 1 ) * ( finish - start + 1 ) ; } } } System . out . print ( " ( Top , ▁ Left ) : ▁ ( " + finalTop + " , ▁ " + finalLeft + ")NEW_LINE"); System . out . print ( " ( Bottom , ▁ Right ) : ▁ ( " + finalBottom + " , ▁ " + finalRight + ")NEW_LINE"); System . out . print ( " Area : ▁ " + maxArea ) ; } public static void main ( String [ ] args ) { int [ ] [ ] mat = { { 1 , 2 , - 1 , - 4 } , { - 8 , - 3 , 4 , 2 } , { 3 , 8 , 10 , 1 } , { - 4 , - 1 , 1 , 7 } } ; int n = 4 , k = 5 ; findLargestSubmatrix ( mat , n , k ) ; } }

Index/key variables: i, n, right
Accumulator variables: curr_sum, i, left, right
Iterator variables: i, left, right
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int zigzag ( int n , int k ) { int dp [ ] [ ] = new int [ n + 1 ] [ k + 1 ] ; dp [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; i ++ ) dp [ i ] [ 0 ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= Math . min ( i , k ) ; j ++ ) dp [ i ] [ j ] = dp [ i ] [ j - 1 ] + dp [ i - 1 ] [ i - j ] ; } return dp [ n ] [ k ] ; } public static void main ( String [ ] args ) { int n = 4 , k = 3 ; System . out . println ( zigzag ( n , k ) ) ; } }

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

Index/key variables: i, j, k, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class Counting { static int MAXN = 109 ; public static int countarray ( int n , int k , int x ) { int [ ] dp = new int [ 109 ] ; dp [ 0 ] = 0 ; dp [ 1 ] = 1 ; for ( int i = 2 ; i < n ; i ++ ) dp [ i ] = ( k - 2 ) * dp [ i - 1 ] + ( k - 1 ) * dp [ i - 2 ] ; return ( x == 1 ? ( k - 1 ) * dp [ n - 2 ] : dp [ n - 1 ] ) ; } public static void main ( String [ ] args ) { int n = 4 , k = 3 , x = 2 ; System . out . println ( countarray ( n , k , x ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: Counting
Java program:
class GFG { static final int MAX = 100 ; static final int MAX_CHAR = 26 ; static void precompute ( String s , int n , int l [ ] [ ] , int r [ ] [ ] ) { l [ s . charAt ( 0 ) - ' a ' ] [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < MAX_CHAR ; j ++ ) l [ j ] [ i ] += l [ j ] [ i - 1 ] ; l [ s . charAt ( i ) - ' a ' ] [ i ] ++ ; } r [ s . charAt ( n - 1 ) - ' a ' ] [ n - 1 ] = 1 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { for ( int j = 0 ; j < MAX_CHAR ; j ++ ) r [ j ] [ i ] += r [ j ] [ i + 1 ] ; r [ s . charAt ( i ) - ' a ' ] [ i ] ++ ; } } static int countPalindromes ( int k , int n , int l [ ] [ ] , int r [ ] [ ] ) { int ans = 0 ; if ( k == 1 ) { for ( int i = 0 ; i < MAX_CHAR ; i ++ ) ans += l [ i ] [ n - 1 ] ; return ans ; } if ( k == 2 ) { for ( int i = 0 ; i < MAX_CHAR ; i ++ ) ans += ( ( l [ i ] [ n - 1 ] * ( l [ i ] [ n - 1 ] - 1 ) ) / 2 ) ; return ans ; } for ( int i = 1 ; i < n - 1 ; i ++ ) for ( int j = 0 ; j < MAX_CHAR ; j ++ ) ans += l [ j ] [ i - 1 ] * r [ j ] [ i + 1 ] ; return ans ; } public static void main ( String [ ] args ) { String s = " aabab " ; int k = 2 ; int n = s . length ( ) ; int l [ ] [ ] = new int [ MAX_CHAR ] [ MAX ] ; int r [ ] [ ] = new int [ MAX_CHAR ] [ MAX ] ; precompute ( s , n , l , r ) ; System . out . println ( countPalindromes ( k , n , l , r ) ) ; } }

Index/key variables: MAX, MAX_CHAR, i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
using System ; class GFG { static int N = 30 ; static int solve ( char X [ ] , char Y [ ] , int l , int r , int k , int dp [ ] [ ] [ ] ) { if ( k == 0 ) { return 0 ; } if ( l < 0 r < 0 ) { return ( int ) 1e9 ; } if ( dp [ l ] [ r ] [ k ] != - 1 ) { return dp [ l ] [ r ] [ k ] ; } int cost = ( X [ l ] - ' a ' ) ^ ( Y [ r ] - ' a ' ) ; return dp [ l ] [ r ] [ k ] = Math . min ( Math . min ( cost + solve ( X , Y , l - 1 , r - 1 , k - 1 , dp ) , solve ( X , Y , l - 1 , r , k , dp ) ) , solve ( X , Y , l , r - 1 , k , dp ) ) ; } public static void main ( String [ ] args ) { char X [ ] = " abble " . toCharArray ( ) ; char Y [ ] = " pie " . toCharArray ( ) ; int n = X . length ; int m = Y . length ; int k = 2 ; int [ ] [ ] [ ] dp = new int [ N ] [ N ] [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { for ( int l = 0 ; l < N ; l ++ ) { dp [ i ] [ j ] [ l ] = - 1 ; } } } int ans = solve ( X , Y , n - 1 , m - 1 , k , dp ) ; System . out . println ( ans == 1e9 ? - 1 : ans ) ; } }

Index/key variables: N, i, j, k, l, r
Accumulator variables: i, j, l
Iterator variables: i, j, l
Class/struct names: GFG
Java program:
import java . io . * ; class MaxSumPath { static int maxSum ( int [ ] [ ] mat , int n ) { if ( n == 1 ) return mat [ 0 ] [ 0 ] ; int dp [ ] [ ] = new int [ n ] [ n ] ; int maxSum = Integer . MIN_VALUE , max ; for ( int j = 0 ; j < n ; j ++ ) dp [ n - 1 ] [ j ] = mat [ n - 1 ] [ j ] ; for ( int i = n - 2 ; i >= 0 ; i -- ) { for ( int j = 0 ; j < n ; j ++ ) { max = Integer . MIN_VALUE ; if ( ( ( j - 1 ) >= 0 ) && ( max < dp [ i + 1 ] [ j - 1 ] ) ) max = dp [ i + 1 ] [ j - 1 ] ; if ( ( ( j + 1 ) < n ) && ( max < dp [ i + 1 ] [ j + 1 ] ) ) max = dp [ i + 1 ] [ j + 1 ] ; dp [ i ] [ j ] = mat [ i ] [ j ] + max ; } } for ( int j = 0 ; j < n ; j ++ ) if ( maxSum < dp [ 0 ] [ j ] ) maxSum = dp [ 0 ] [ j ] ; return maxSum ; } public static void main ( String [ ] args ) { int mat [ ] [ ] = { { 5 , 6 , 1 , 7 } , { - 2 , 10 , 8 , - 1 } , { 3 , - 7 , - 9 , 11 } , { 12 , - 4 , 2 , 6 } } ; int n = 4 ; System . out . println ( " Maximum ▁ Sum ▁ = ▁ " + maxSum ( mat , n ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: MaxSumPath
Java program:
import java . util . * ; class GFG { static String longestRepeatedSubSeq ( String str ) { int n = str . length ( ) ; int [ ] [ ] dp = new int [ n + 1 ] [ n + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) for ( int j = 0 ; j <= n ; j ++ ) dp [ i ] [ j ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) for ( int j = 1 ; j <= n ; j ++ ) if ( str . charAt ( i - 1 ) == str . charAt ( j - 1 ) && i != j ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ; else dp [ i ] [ j ] = Math . max ( dp [ i ] [ j - 1 ] , dp [ i - 1 ] [ j ] ) ; String res = " " ; int i = n , j = n ; while ( i > 0 && j > 0 ) { if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j - 1 ] + 1 ) { res = res + str . charAt ( i - 1 ) ; i -- ; j -- ; } else if ( dp [ i ] [ j ] == dp [ i - 1 ] [ j ] ) i -- ; else j -- ; } String reverse = " " ; for ( int k = res . length ( ) - 1 ; k >= 0 ; k -- ) { reverse = reverse + res . charAt ( k ) ; } return reverse ; } public static void main ( String args [ ] ) { String str = " AABEBCDD " ; System . out . println ( longestRepeatedSubSeq ( str ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void dfs ( int node , int parent , Vector < Integer > tree [ ] , int colour [ ] , int answer [ ] ) { answer [ node ] = colour [ node ] ; for ( Integer u : tree [ node ] ) { if ( u == parent ) continue ; dfs ( u , node , tree , colour , answer ) ; answer [ node ] += Math . max ( answer [ u ] , 0 ) ; } } static int maxDiff ( Vector < Integer > tree [ ] , int colour [ ] , int N ) { int [ ] answer = new int [ N + 1 ] ; dfs ( 1 , 0 , tree , colour , answer ) ; int high = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { high = Math . max ( high , answer [ i ] ) ; answer [ i ] = 0 ; } for ( int i = 1 ; i <= N ; i ++ ) { if ( colour [ i ] == - 1 ) colour [ i ] = 1 ; else colour [ i ] = - 1 ; } dfs ( 1 , 0 , tree , colour , answer ) ; for ( int i = 1 ; i < N ; i ++ ) high = Math . max ( high , answer [ i ] ) ; return high ; } public static void main ( String [ ] args ) { int N = 5 ; Vector < Integer > tree [ ] = new Vector [ N + 1 ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) tree [ i ] = new Vector < Integer > ( ) ; tree [ 1 ] . add ( 2 ) ; tree [ 2 ] . add ( 1 ) ; tree [ 1 ] . add ( 3 ) ; tree [ 3 ] . add ( 1 ) ; tree [ 2 ] . add ( 4 ) ; tree [ 4 ] . add ( 2 ) ; tree [ 3 ] . add ( 5 ) ; tree [ 5 ] . add ( 3 ) ; int colour [ ] = { 0 , 1 , 1 , - 1 , - 1 , 1 } ; System . out . println ( maxDiff ( tree , colour , N ) ) ; } }

Index/key variables: i, node, u
Accumulator variables: i
Iterator variables: i, u
Class/struct names: GFG
Java program:
public class GFG { static final int MAX = 50 ; static int solve ( int dp [ ] [ ] , int a [ ] , int low , int high , int turn ) { if ( low == high ) { return a [ low ] * turn ; } if ( dp [ low ] [ high ] != 0 ) { return dp [ low ] [ high ] ; } dp [ low ] [ high ] = Math . max ( a [ low ] * turn + solve ( dp , a , low + 1 , high , turn + 1 ) , a [ high ] * turn + solve ( dp , a , low , high - 1 , turn + 1 ) ) ; return dp [ low ] [ high ] ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 3 , 1 , 5 , 2 } ; int n = arr . length ; int dp [ ] [ ] = new int [ MAX ] [ MAX ] ; System . out . println ( solve ( dp , arr , 0 , n - 1 , 1 ) ) ; } }

Index/key variables: MAX, high, low
Class/struct names: GFG
Java program:
class GFG { static int maxSumBitonicSubArr ( int arr [ ] , int n ) { int [ ] msis = new int [ n ] ; int [ ] msds = new int [ n ] ; int max_sum = Integer . MIN_VALUE ; msis [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) if ( arr [ i ] > arr [ i - 1 ] ) msis [ i ] = msis [ i - 1 ] + arr [ i ] ; else msis [ i ] = arr [ i ] ; msds [ n - 1 ] = arr [ n - 1 ] ; for ( int i = n - 2 ; i >= 0 ; i -- ) if ( arr [ i ] > arr [ i + 1 ] ) msds [ i ] = msds [ i + 1 ] + arr [ i ] ; else msds [ i ] = arr [ i ] ; for ( int i = 0 ; i < n ; i ++ ) if ( max_sum < ( msis [ i ] + msds [ i ] - arr [ i ] ) ) max_sum = msis [ i ] + msds [ i ] - arr [ i ] ; return max_sum ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 3 , 9 , 2 , 7 , 6 , 4 } ; int n = arr . length ; System . out . println ( " Maximum ▁ Sum ▁ = ▁ " + maxSumBitonicSubArr ( arr , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
public class GFG_1 { String a , b ; static void printSuperSeq ( String a , String b ) { int m = a . length ( ) , n = b . length ( ) ; int [ ] [ ] dp = new int [ m + 1 ] [ n + 1 ] ; for ( int i = 0 ; i <= m ; i ++ ) { for ( int j = 0 ; j <= n ; j ++ ) { if ( i == 0 ) dp [ i ] [ j ] = j ; else if ( j == 0 ) dp [ i ] [ j ] = i ; else if ( a . charAt ( i - 1 ) == b . charAt ( j - 1 ) ) dp [ i ] [ j ] = 1 + dp [ i - 1 ] [ j - 1 ] ; else dp [ i ] [ j ] = 1 + Math . min ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ; } } String res = " " ; int i = m , j = n ; while ( i > 0 && j > 0 ) { if ( a . charAt ( i - 1 ) == b . charAt ( j - 1 ) ) { res = a . charAt ( i - 1 ) + res ; i -- ; j -- ; } else if ( dp [ i - 1 ] [ j ] < dp [ i ] [ j - 1 ] ) { res = a . charAt ( i - 1 ) + res ; i -- ; } else { res = b . charAt ( j - 1 ) + res ; j -- ; } } while ( i > 0 ) { res = a . charAt ( i - 1 ) + res ; i -- ; } while ( j > 0 ) { res = b . charAt ( j - 1 ) + res ; j -- ; } System . out . println ( res ) ; } public static void main ( String args [ ] ) { String a = " algorithm " ; String b = " rhythm " ; printSuperSeq ( a , b ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG_1
Java program:
import java . util . * ; class GFG { static int maxSubsequenceSubString ( String X , String Y , int n , int m ) { if ( n == 0 m == 0 ) return 0 ; if ( X . charAt ( n - 1 ) == Y . charAt ( m - 1 ) ) { return 1 + maxSubsequenceSubString ( X , Y , n - 1 , m - 1 ) ; } else { return maxSubsequenceSubString ( X , Y , n - 1 , m ) ; } } public static void main ( String [ ] args ) { String X = " abcd " ; String Y = " bacdbdcd " ; int n = X . length ( ) , m = Y . length ( ) ; int maximum_length = 0 ; for ( int i = 0 ; i <= m ; i ++ ) { int temp_ans = maxSubsequenceSubString ( X , Y , n , i ) ; if ( temp_ans > maximum_length ) maximum_length = temp_ans ; } System . out . print ( " Length ▁ for ▁ maximum ▁ possible ▁ Subsequence ▁ of ▁ String ▁ X ▁ which ▁ is ▁ SubString ▁ of ▁ Y - > " + maximum_length ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG