dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
class GFG { static int power ( int x , int y , int p ) { int res = 1 ; x = x % p ; if ( x == 0 ) return 0 ; while ( y > 0 ) { if ( ( y & 1 ) != 0 ) res = ( res * x ) % p ; y = y >> 1 ; x = ( x * x ) % p ; } return res ; } static int kvowelwords ( int N , int K ) { int i , j ; int MOD = 1000000007 ; int [ ] [ ] dp = new int [ N + 1 ] [ K + 1 ] ; int sum = 1 ; for ( i = 1 ; i <= N ; i ++ ) { dp [ i ] [ 0 ] = sum * 21 ; dp [ i ] [ 0 ] %= MOD ; sum = dp [ i ] [ 0 ] ; for ( j = 1 ; j <= K ; j ++ ) { if ( j > i ) dp [ i ] [ j ] = 0 ; else if ( j == i ) { dp [ i ] [ j ] = power ( 5 , i , MOD ) ; } else { dp [ i ] [ j ] = dp [ i - 1 ] [ j - 1 ] * 5 ; } dp [ i ] [ j ] %= MOD ; sum += dp [ i ] [ j ] ; sum %= MOD ; } } return sum ; } public static void main ( String [ ] args ) { int N = 3 ; int K = 3 ; System . out . println ( kvowelwords ( N , K ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . Vector ; public class GFG { public static class pair { private int first ; private int second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static void maxBoundary ( int N , Vector < pair > V ) { int dp [ ] [ ] = new int [ N ] [ 2 ] ; dp [ 0 ] [ 0 ] = V . get ( 0 ) . first ; dp [ 0 ] [ 1 ] = V . get ( 0 ) . second ; for ( int i = 1 ; i < N ; i ++ ) { dp [ i ] [ 0 ] = V . get ( i ) . first ; int height1 = Math . abs ( V . get ( i - 1 ) . second - V . get ( i ) . second ) ; int height2 = Math . abs ( V . get ( i - 1 ) . first - V . get ( i ) . second ) ; dp [ i ] [ 0 ] += Math . max ( height1 + dp [ i - 1 ] [ 0 ] , height2 + dp [ i - 1 ] [ 1 ] ) ; dp [ i ] [ 1 ] = V . get ( i ) . second ; int vertical1 = Math . abs ( V . get ( i ) . first - V . get ( i - 1 ) . second ) ; int vertical2 = Math . abs ( V . get ( i ) . first - V . get ( i - 1 ) . first ) ; dp [ i ] [ 1 ] += Math . max ( vertical1 + dp [ i - 1 ] [ 0 ] , vertical2 + dp [ i - 1 ] [ 1 ] ) ; } System . out . println ( Math . max ( dp [ N - 1 ] [ 0 ] , dp [ N - 1 ] [ 1 ] ) ) ; } public static void main ( String [ ] args ) { int N = 5 ; Vector < pair > V = new Vector < > ( ) ; V . add ( new pair ( 2 , 5 ) ) ; V . add ( new pair ( 3 , 8 ) ) ; V . add ( new pair ( 1 , 10 ) ) ; V . add ( new pair ( 7 , 14 ) ) ; V . add ( new pair ( 2 , 5 ) ) ; maxBoundary ( N , V ) ; } }

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, pair
Java program:
import java . util . * ; class GFG { static int maximumSum ( int [ ] A , int N , int K , int D ) { int [ ] [ ] [ ] dp = new int [ N + 1 ] [ K + 1 ] [ D + 1 ] ; for ( int i = 0 ; i < N + 1 ; i ++ ) { for ( int j = 0 ; j < K + 1 ; j ++ ) { for ( int k = 0 ; k < D + 1 ; k ++ ) { dp [ i ] [ j ] [ k ] = - 1 ; } } } for ( int i = 1 ; i <= N ; i ++ ) { int element = A [ i - 1 ] ; int mod = A [ i - 1 ] % D ; dp [ i ] = dp [ i - 1 ] ; for ( int j = 1 ; j <= K ; j ++ ) { dp [ i ] [ j ] [ mod ] = Math . max ( dp [ i ] [ j ] [ mod ] , element ) ; for ( int p = 0 ; p < D ; p ++ ) { if ( dp [ i - 1 ] [ j - 1 ] [ p ] != - 1 ) { dp [ i ] [ j ] [ ( p + mod ) % D ] = Math . max ( dp [ i ] [ j ] [ ( p + mod ) % D ] , dp [ i - 1 ] [ j - 1 ] [ p ] + element ) ; } } } } if ( dp [ N ] [ K ] [ 0 ] == - 1 ) return 0 ; return dp [ N ] [ K ] [ 0 ] ; } public static void main ( String [ ] args ) { int N = 5 , K = 3 , D = 7 ; int [ ] A = { 1 , 11 , 5 , 5 , 18 } ; System . out . print ( maximumSum ( A , N , K , D ) ) ; } }

Index/key variables: K, N, i, j, k, mod, p
Accumulator variables: i, j, k, p
Iterator variables: i, j, k, p
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int NumberOfways ( int N , int K ) { int [ ] dp = new int [ N + 1 ] ; dp [ 0 ] = 1 ; for ( int row = 1 ; row < K + 1 ; row ++ ) { for ( int col = 1 ; col < N + 1 ; col ++ ) { if ( col >= row ) dp [ col ] = dp [ col ] + dp [ col - row ] ; } } return ( dp [ N ] ) ; } public static void main ( String [ ] args ) { int N = 8 ; int K = 2 ; System . out . println ( NumberOfways ( N , K ) ) ; } }

Index/key variables: N, col
Accumulator variables: col, row
Iterator variables: col, row
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void findAPSequence ( int arr [ ] , int N , int Q [ ] [ ] , int M ) { int dp [ ] = new int [ N + 5 ] ; for ( int i = 0 ; i + 1 < N ; ) { int j = i + 1 ; while ( j + 1 < N && arr [ j + 1 ] - arr [ j ] == arr [ i + 1 ] - arr [ i ] ) j ++ ; for ( int k = i ; k < j ; k ++ ) { dp [ k ] = j - k ; } i = j ; } for ( int i = 0 ; i < M ; i ++ ) { if ( dp [ Q [ i ] [ 0 ] ] >= Q [ i ] [ 1 ] - Q [ i ] [ 0 ] ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 5 , 7 , 6 , 5 , 4 , 1 } ; int Q [ ] [ ] = { { 0 , 3 } , { 3 , 4 } , { 2 , 4 } } ; int N = arr . length ; int M = Q . length ; findAPSequence ( arr , N , Q , M ) ; } }

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: i, k
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int [ ] [ ] [ ] dp = new int [ 100 ] [ 100 ] [ 100 ] ; static int minSumDifference ( int [ ] arr , int n , int k1 , int k2 , int sum1 , int sum2 ) { if ( n < 0 ) { if ( k1 == 0 && k2 == 0 ) { return Math . abs ( sum1 - sum2 ) ; } else { return Integer . MAX_VALUE ; } } if ( dp [ n ] [ sum1 ] [ sum2 ] != - 1 ) { return dp [ n ] [ sum1 ] [ sum2 ] ; } int op1 = Integer . MAX_VALUE ; int op2 = Integer . MAX_VALUE ; int op3 = Integer . MAX_VALUE ; if ( k1 > 0 ) { op1 = minSumDifference ( arr , n - 1 , k1 - 1 , k2 , sum1 + arr [ n ] , sum2 ) ; } if ( k2 > 0 ) { op2 = minSumDifference ( arr , n - 1 , k1 , k2 - 1 , sum1 , sum2 + arr [ n ] ) ; } op3 = minSumDifference ( arr , n - 1 , k1 , k2 , sum1 , sum2 ) ; dp [ n ] [ sum1 ] [ sum2 ] = Math . min ( op1 , Math . min ( op2 , op3 ) ) ; return dp [ n ] [ sum1 ] [ sum2 ] ; } public static void main ( String [ ] args ) { int arr [ ] = { 12 , 3 , 5 , 6 , 7 , 17 } ; int K = 2 ; int N = arr . length ; for ( int [ ] [ ] row : dp ) { for ( int [ ] innerrow : row ) { Arrays . fill ( innerrow , - 1 ) ; } } System . out . println ( minSumDifference ( arr , N - 1 , K , K , 0 , 0 ) ) ; } }

Index/key variables: n, sum1, sum2
Iterator variables: innerrow, row
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static int find ( int A , int B , int C , int N ) { int [ ] arr = new int [ N ] ; arr [ 0 ] = A ; arr [ 1 ] = B ; arr [ 2 ] = C ; for ( int i = 3 ; i < N ; i ++ ) { arr [ i ] = arr [ i - 1 ] + arr [ i - 2 ] + arr [ i - 3 ] ; } return arr [ N - 1 ] ; } public static void main ( String [ ] args ) { int A = 1 , B = 3 , C = 2 , N = 4 ; System . out . print ( find ( A , B , C , N ) ) ; } }

Index/key variables: N, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; public class GFG { static class Pair { int x , y ; Pair ( int x , int y ) { this . x = x ; this . y = y ; } } private static int maxResult ( int [ ] arr , int k , int n ) { int dp [ ] = new int [ n ] ; dp [ 0 ] = arr [ 0 ] ; Deque < Pair > q = new LinkedList < Pair > ( ) ; q . add ( new Pair ( arr [ 0 ] , 0 ) ) ; for ( int i = 1 ; i < n ; i ++ ) { dp [ i ] = arr [ i ] + q . peekFirst ( ) . x ; while ( q . size ( ) > 0 && q . peekLast ( ) . x < dp [ i ] ) q . pollLast ( ) ; q . add ( new Pair ( dp [ i ] , i ) ) ; if ( i - k == q . peekFirst ( ) . y ) q . pollFirst ( ) ; } return dp [ n - 1 ] ; } public static void main ( String [ ] args ) { int arr [ ] = { 10 , - 5 , - 2 , 4 , 0 , 3 } ; int K = 3 ; int n = arr . length ; System . out . println ( maxResult ( arr , K , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, Pair
Java program:
class GFG { static void daysToCure ( int arr [ ] , int N , int P ) { int risk = 0 ; int normal_risk = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr [ i ] >= 60 arr [ i ] <= 10 ) { risk ++ ; } else { normal_risk ++ ; } } int days = ( risk / P ) + ( normal_risk / P ) ; if ( risk % P > 0 ) { days ++ ; } if ( normal_risk % P > 0 ) { days ++ ; } System . out . print ( days ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 9 , 80 , 27 , 72 , 79 } ; int N = arr . length ; int P = 2 ; daysToCure ( arr , N , P ) ; } }

Index/key variables: i
Accumulator variables: days, i, normal_risk, risk
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static final int M = 100 ; static int cntNum ( String X , int i , int prod , int K , int st , int tight , int [ ] [ ] [ ] [ ] dp ) { if ( i >= X . length ( ) prod > K ) { return prod == K ? 1 : 0 ; } if ( dp [ prod ] [ i ] [ tight ] [ st ] != - 1 ) { return dp [ prod ] [ i ] [ tight ] [ st ] ; } int res = 0 ; int end = tight > 0 ? X . charAt ( i ) - '0' : 9 ; for ( int j = 0 ; j <= end ; j ++ ) { if ( j == 0 && st == 0 ) { res += cntNum ( X , i + 1 , prod , K , 0 , ( tight & ( ( j == end ) ? 1 : 0 ) ) , dp ) ; } else { res += cntNum ( X , i + 1 , prod * j , K , 1 , ( tight & ( ( j == end ) ? 1 : 0 ) ) , dp ) ; } } static int UtilCntNumRange ( int L , int R , int K ) { String str = String . valueOf ( R ) ; int [ ] [ ] [ ] [ ] dp = new int [ M ] [ M ] [ 2 ] [ 2 ] ; for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { for ( int k = 0 ; k < 2 ; k ++ ) for ( int l = 0 ; l < 2 ; l ++ ) dp [ i ] [ j ] [ k ] [ l ] = - 1 ; } } int cntR = cntNum ( str , 0 , 1 , K , 0 , 1 , dp ) ; str = String . valueOf ( L - 1 ) ; for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { for ( int k = 0 ; k < 2 ; k ++ ) for ( int l = 0 ; l < 2 ; l ++ ) dp [ i ] [ j ] [ k ] [ l ] = - 1 ; } } int cntL = cntNum ( str , 0 , 1 , K , 0 , 1 , dp ) ; return ( cntR - cntL ) ; } public static void main ( String [ ] args ) { int L = 20 , R = 10000 , K = 14 ; System . out . print ( UtilCntNumRange ( L , R , K ) ) ; } }

Index/key variables: M, i, j, k, l, prod, st, tight
Accumulator variables: i, j, k, l, res
Iterator variables: i, j, k, l
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { public static int countVowelPermutation ( int n ) { int MOD = ( int ) ( 1e9 + 7 ) ; long [ ] [ ] dp = new long [ n + 1 ] [ 5 ] ; for ( int i = 0 ; i < 5 ; i ++ ) { dp [ 1 ] [ i ] = 1 ; } int [ ] [ ] relation = new int [ ] [ ] { { 1 } , { 0 , 2 } , { 0 , 1 , 3 , 4 } , { 2 , 4 } , { 0 } } ; for ( int i = 1 ; i < n ; i ++ ) { for ( int u = 0 ; u < 5 ; u ++ ) { dp [ i + 1 ] [ u ] = 0 ; for ( int v : relation [ u ] ) { dp [ i + 1 ] [ u ] += dp [ i ] [ v ] % MOD ; } } } long ans = 0 ; for ( int i = 0 ; i < 5 ; i ++ ) { ans = ( ans + dp [ n ] [ i ] ) % MOD ; } return ( int ) ans ; } public static void main ( String [ ] args ) { int N = 2 ; System . out . println ( countVowelPermutation ( N ) ) ; } }

Index/key variables: i, n, u, v
Accumulator variables: i, u
Iterator variables: i, u, v
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static int N = ( int ) 1e5 + 5 ; static ArrayList < ArrayList < Integer > > adj ; static int [ ] answer ; static void addEdgesToGraph ( int Edges [ ] [ ] , int N ) { for ( int i = 0 ; i < N - 1 ; i ++ ) { int u = Edges [ i ] [ 0 ] ; int v = Edges [ i ] [ 1 ] ; adj . get ( u ) . add ( v ) ; adj . get ( v ) . add ( u ) ; } } static void DFS ( int node , int parent , int Val [ ] ) { answer [ node ] = Val [ node ] ; for ( Integer child : adj . get ( node ) ) { if ( child == parent ) continue ; DFS ( child , node , Val ) ; answer [ node ] = ( answer [ node ] answer [ child ] ) ; } } static void preprocess ( int Val [ ] ) { DFS ( 1 , - 1 , Val ) ; } static void findSubtreeOR ( int Queries [ ] , int Q , int Val [ ] ) { preprocess ( Val ) ; for ( int i = 0 ; i < Q ; i ++ ) { System . out . println ( answer [ Queries [ i ] ] + " ▁ " ) ; } } static void findSubtreeORUtil ( int N , int Edges [ ] [ ] , int Val [ ] , int Queries [ ] , int Q ) { addEdgesToGraph ( Edges , N ) ; findSubtreeOR ( Queries , Q , Val ) ; } public static void main ( String [ ] args ) { adj = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) adj . add ( new ArrayList < > ( ) ) ; answer = new int [ N ] ; N = 5 ; int Edges [ ] [ ] = { { 1 , 2 } , { 1 , 3 } , { 3 , 4 } , { 3 , 5 } } ; int Val [ ] = { 0 , 2 , 3 , 4 , 8 , 16 } ; int Queries [ ] = { 2 , 3 , 1 } ; int Q = Queries . length ; findSubtreeORUtil ( N , Edges , Val , Queries , Q ) ; } }

Index/key variables: N, child, i, node
Accumulator variables: i
Iterator variables: child, i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int max ( int a , int b ) { return a > b ? a : b ; } static int maximumsum ( int arr [ ] [ ] , int K , int N , int M ) { int sum = 0 , maxSum ; int i , j , k ; int [ ] [ ] dp = new int [ K + 1 ] [ N + 1 ] ; for ( i = 0 ; i <= N ; i ++ ) dp [ 0 ] [ i ] = 0 ; for ( i = 0 ; i <= K ; i ++ ) dp [ i ] [ 0 ] = 0 ; for ( i = 1 ; i <= K ; i ++ ) { for ( j = 0 ; j < N ; j ++ ) { sum = 0 ; maxSum = dp [ i ] [ j ] ; for ( k = 1 ; k <= M && k <= i ; k ++ ) { sum += arr [ j ] [ k - 1 ] ; maxSum = Math . max ( maxSum , sum + dp [ i - k ] [ j ] ) ; } dp [ i ] [ j + 1 ] = maxSum ; } } return dp [ K ] [ N ] ; } public static void main ( String [ ] args ) { int arr [ ] [ ] = { { 10 , 10 , 100 , 30 } , { 80 , 50 , 10 , 50 } } ; int N = 2 , M = 4 ; int K = 5 ; System . out . print ( maximumsum ( arr , K , N , M ) ) ; } }

Index/key variables: K, N, i, j
Accumulator variables: i, j, k, sum
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static void FindSub ( HashSet < String > sub , HashSet < Character > ch , String str , String res , int i ) { if ( i == str . length ( ) ) { sub . add ( res ) ; return ; } if ( ! ch . contains ( str . charAt ( i ) ) ) { ch . add ( str . charAt ( i ) ) ; FindSub ( sub , ch , str , res + str . charAt ( i ) , i + 1 ) ; ch . remove ( str . charAt ( i ) ) ; } FindSub ( sub , ch , str , res , i + 1 ) ; } public static void printSubwithUniqueChar ( String str , int N ) { HashSet < String > sub = new HashSet < > ( ) ; HashSet < Character > ch = new HashSet < > ( ) ; FindSub ( sub , ch , str , " " , 0 ) ; for ( String subString : sub ) { System . out . print ( subString + " ▁ " ) ; } } public static void main ( String args [ ] ) { String str = " abac " ; int N = str . length ( ) ; printSubwithUniqueChar ( str , N ) ; } }

Iterator variables: subString
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static void waysToArrangeKLengthStrings ( int N , int K ) { int [ ] column_sum = new int [ N + 1 ] ; int i , j ; for ( i = 1 ; i < N + 1 ; i ++ ) { column_sum [ i ] = 0 ; } int dp [ ] [ ] = new int [ K + 1 ] [ N + 1 ] ; for ( i = 1 ; i < K + 1 ; i ++ ) { for ( j = 1 ; j < N + 1 ; j ++ ) { dp [ i ] [ j ] = 0 ; } } for ( i = 0 ; i <= N ; i ++ ) { dp [ 0 ] [ i ] = 1 ; column_sum [ i ] = 1 ; } for ( i = 1 ; i <= K ; i ++ ) { for ( j = 1 ; j <= N ; j ++ ) { dp [ i ] [ j ] += column_sum [ j - 1 ] ; column_sum [ j ] += dp [ i ] [ j ] ; } } System . out . print ( dp [ K ] [ N ] ) ; } public static void main ( String [ ] args ) { int N = 5 , K = 2 ; waysToArrangeKLengthStrings ( N , K ) ; } }

Index/key variables: K, N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int findNumberOfStrings ( int n ) { int DP [ ] [ ] = new int [ n + 1 ] [ 6 ] ; DP [ 1 ] [ 1 ] = 1 ; for ( int i = 1 ; i < n + 1 ; i ++ ) { for ( int j = 1 ; j < 6 ; j ++ ) { if ( i == 1 ) { DP [ i ] [ j ] = DP [ i ] [ j - 1 ] + 1 ; } else { DP [ i ] [ j ] = DP [ i ] [ j - 1 ] + DP [ i - 1 ] [ j ] ; } } } return DP [ n ] [ 5 ] ; } public static void main ( String [ ] args ) { int N = 2 ; System . out . print ( findNumberOfStrings ( N ) ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . ArrayList ; @ SuppressWarnings ( " unchecked " ) class GFG { static void dfs ( int v , int p , ArrayList < Integer > adj [ ] , int ans [ ] , int vals [ ] ) { boolean isLeaf = true ; ans [ v ] = Integer . MIN_VALUE ; for ( int u : adj [ v ] ) { if ( u == p ) continue ; isLeaf = false ; dfs ( u , v , adj , ans , vals ) ; ans [ v ] = Math . max ( ans [ u ] + vals [ v ] , Math . max ( ans [ u ] , vals [ u ] ) ) ; } if ( isLeaf ) { ans [ v ] = vals [ v ] ; } } static void printAnswer ( int n , int edges [ ] [ ] , int values [ ] ) { ArrayList < Integer > adj [ ] = new ArrayList [ n ] ; for ( int i = 0 ; i < n ; i ++ ) adj [ i ] = new ArrayList < > ( ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int u = edges [ i ] [ 0 ] - 1 ; int v = edges [ i ] [ 1 ] - 1 ; adj [ u ] . add ( v ) ; adj [ v ] . add ( u ) ; } int ans [ ] = new int [ n ] ; dfs ( 0 , - 1 , adj , ans , values ) ; for ( int x : ans ) { System . out . print ( x + " ▁ " ) ; } } public static void main ( String [ ] args ) { int N = 4 ; int edges [ ] [ ] = new int [ ] [ ] { { 1 , 2 } , { 1 , 3 } , { 3 , 4 } } ; int values [ ] = { 1 , - 1 , 0 , 1 } ; printAnswer ( N , edges , values ) ; } }

Index/key variables: i, n, u, v
Accumulator variables: i
Iterator variables: i, u, x
Boolean variables: isLeaf
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void noOfChars ( String s , char [ ] [ ] queries ) { int n = s . length ( ) ; int dp [ ] [ ] = new int [ n + 1 ] [ 26 ] ; for ( int i = 0 ; i < n ; i ++ ) { dp [ i + 1 ] [ s . charAt ( i ) - ' a ' ] ++ ; for ( int j = 0 ; j < 26 ; j ++ ) { dp [ i + 1 ] [ j ] += dp [ i ] [ j ] ; } } int q = queries . length ; for ( int i = 0 ; i < q ; i ++ ) { int l = ( int ) queries [ i ] [ 0 ] ; int r = ( int ) queries [ i ] [ 1 ] ; int c = queries [ i ] [ 2 ] - ' a ' ; System . out . print ( dp [ r ] - dp [ l - 1 ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { String S = " aabv " ; char queries [ ] [ ] = new char [ ] [ ] { { 1 , 2 , ' a ' } , { 2 , 3 , ' b ' } } ; noOfChars ( S , queries ) ; } }

Index/key variables: i, j, r
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int LowerBound ( int a [ ] , int k , int x ) { int l = - 1 ; int r = k ; while ( l + 1 < r ) { int m = ( l + r ) >>> 1 ; if ( a [ m ] >= x ) { r = m ; } else { l = m ; } } return r ; } static int findLCS ( int [ ] nums , int N ) { int k = 0 ; for ( int i = 0 ; i < N ; i ++ ) { int pos = LowerBound ( nums , k , nums [ i ] ) ; nums [ pos ] = nums [ i ] ; if ( k == pos ) { k = pos + 1 ; } } return k ; } static int minimumCost ( int [ ] A , int [ ] B , int M , int N , int C ) { int [ ] nums = new int [ 100000 ] ; int [ ] index = new int [ 100000 ] ; for ( int i = 0 ; i < 100000 ; i ++ ) index [ i ] = - 1 ; for ( int i = 0 ; i < N ; i ++ ) { index [ B [ i ] ] = i ; } int k = 0 ; for ( int i = 0 ; i < M ; i ++ ) { if ( index [ A [ i ] ] != - 1 ) { nums [ k ++ ] = index [ A [ i ] ] ; } } int lcs_length = findLCS ( nums , k ) ; int elements_to_be_added = N - lcs_length ; int min_cost = elements_to_be_added * C ; System . out . println ( min_cost ) ; return 0 ; } public static void main ( String [ ] args ) { int [ ] A = { 1 , 6 , 3 , 5 , 10 } ; int [ ] B = { 3 , 1 , 5 } ; int C = 2 ; int M = A . length ; int N = B . length ; minimumCost ( A , B , M , N , C ) ; } }

Index/key variables: i, m, pos
Accumulator variables: i, k
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int maxCount ( int arr [ ] , int m , int V ) { int table [ ] = new int [ V + 1 ] ; table [ 0 ] = 0 ; for ( int i = 1 ; i <= V ; i ++ ) table [ i ] = - 1 ; for ( int i = 1 ; i <= V ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { if ( arr [ j ] <= i ) { int sub_res = table [ i - arr [ j ] ] ; if ( sub_res != - 1 && sub_res + 1 > table [ i ] ) table [ i ] = sub_res + 1 ; } } } return table [ V ] ; } public static void main ( String [ ] args ) { int arr [ ] = { 25 , 10 , 5 } ; int m = arr . length ; int V = 30 ; System . out . println ( maxCount ( arr , m , V ) ) ; } }

Index/key variables: V, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static final int SZ = 100 ; static void pathSum ( int [ ] [ ] mat , int N , int M ) { int [ ] [ ] dp = new int [ N ] [ M ] ; dp [ 0 ] [ 0 ] = mat [ 0 ] [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { dp [ i ] [ 0 ] = mat [ i ] [ 0 ] + dp [ i - 1 ] [ 0 ] ; } for ( int j = 1 ; j < M ; j ++ ) { dp [ 0 ] [ j ] = mat [ 0 ] [ j ] + dp [ 0 ] [ j - 1 ] ; } for ( int i = 1 ; i < N ; i ++ ) { for ( int j = 1 ; j < M ; j ++ ) { dp [ i ] [ j ] = mat [ i ] [ j ] + Math . max ( dp [ i - 1 ] [ j ] , dp [ i ] [ j - 1 ] ) ; } } for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { System . out . print ( dp [ i ] [ j ] + " ▁ " ) ; } System . out . println ( ) ; } } public static void main ( String [ ] args ) { int mat [ ] [ ] = { { 3 , 2 , 1 } , { 6 , 5 , 4 } , { 7 , 8 , 9 } } ; int N = 3 ; int M = 3 ; pathSum ( mat , N , M ) ; } }

Index/key variables: M, N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int longestPalSubstr ( String str ) { int n = str . length ( ) ; boolean [ ] [ ] table = new boolean [ n ] [ n ] ; int maxLength = 1 ; for ( int i = 0 ; i < n ; ++ i ) table [ i ] [ i ] = true ; int start = 0 ; for ( int i = 0 ; i < n - 1 ; ++ i ) { if ( str . charAt ( i ) == str . charAt ( i + 1 ) ) { table [ i ] [ i + 1 ] = true ; start = i ; maxLength = 2 ; } } for ( int k = 3 ; k <= n ; ++ k ) { for ( int i = 0 ; i < n - k + 1 ; ++ i ) { int j = i + k - 1 ; if ( table [ i + 1 ] [ j - 1 ] && str . charAt ( i ) == str . charAt ( j ) ) { table [ i ] [ j ] = true ; if ( k > maxLength ) { start = i ; maxLength = k ; } } } } return maxLength ; } public static void main ( String [ ] args ) { String str = " forgeeksskeegfor " ; System . out . print ( longestPalSubstr ( str ) ) ; } }

Index/key variables: i, j, n
Iterator variables: i, k
Class/struct names: GFG
Java program:
import java . io . * ; public class GFG { public static int maxSumFlip ( int a [ ] , int n ) { int total_sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) total_sum += a [ i ] ; int max_sum = Integer . MIN_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { int sum = 0 ; int flip_sum = 0 ; for ( int j = i ; j < n ; j ++ ) { sum += a [ j ] ; max_sum = Math . max ( max_sum , total_sum - 2 * sum ) ; } } return Math . max ( max_sum , total_sum ) ; } public static void main ( String args [ ] ) { int arr [ ] = { - 2 , 3 , - 1 , - 4 , - 2 } ; int N = arr . length ; System . out . println ( maxSumFlip ( arr , N ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, sum, total_sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int INF = ( int ) 1e7 ; static int max_size = 100007 ; static int [ ] dp = new int [ max_size ] ; static int min_op ( int cur , int M ) { if ( cur > M ) return INF ; if ( cur == M ) return 0 ; if ( dp [ cur ] != - 1 ) return dp [ cur ] ; int op = INF ; for ( int i = 2 ; i * i <= cur ; i ++ ) { if ( cur % i == 0 ) { if ( i % 2 == 0 ) { op = Math . min ( op , 1 + min_op ( cur + i , M ) ) ; } if ( ( cur / i ) != i && ( cur / i ) % 2 == 0 ) { op = Math . min ( op , 1 + min_op ( cur + ( cur / i ) , M ) ) ; } } } return dp [ cur ] = op ; } static int min_operations ( int N , int M ) { for ( int i = N ; i <= M ; i ++ ) { dp [ i ] = - 1 ; } return min_op ( N , M ) ; } public static void main ( String [ ] args ) { int N = 6 , M = 24 ; int op = min_operations ( N , M ) ; if ( op >= INF ) System . out . print ( " - 1" ) ; else System . out . print ( op + "NEW_LINE"); } }

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