dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
class Geeks { static int k_nonzero_numbers ( String s , int n , int k ) { int dp [ ] [ ] [ ] = new int [ n + 1 ] [ 2 ] [ k + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) for ( int j = 0 ; j < 2 ; j ++ ) for ( int x = 0 ; x <= k ; x ++ ) dp [ i ] [ j ] [ x ] = 0 ; dp [ 0 ] [ 0 ] [ 0 ] = 1 ; for ( int i = 0 ; i < n ; ++ i ) { int sm = 0 ; while ( sm < 2 ) { for ( int j = 0 ; j < k + 1 ; ++ j ) { int x = 0 ; while ( x <= ( sm != 0 ? 9 : s . charAt ( i ) - '0' ) ) { if ( j + ( x > 0 ? 1 : 0 ) < k + 1 ) { dp [ i + 1 ] [ ( sm != 0 x < ( s . charAt ( i ) - '0' ) ) ? 1 : 0 ] [ j + ( x > 0 ? 1 : 0 ) ] += dp [ i ] [ sm ] [ j ] ; } ++ x ; } } ++ sm ; } } return dp [ n ] [ 0 ] [ k ] + dp [ n ] [ 1 ] [ k ] ; } public static void main ( String [ ] args ) { String s = "25" ; int k = 2 ; int n = s . length ( ) ; System . out . println ( k_nonzero_numbers ( s , n , k ) ) ; } }

Index/key variables: i, j, k, n, sm, x
Accumulator variables: i, j, x
Iterator variables: i, j, x
Class/struct names: Geeks
Java program:
import java . util . * ; class GFG { static int maximumOccurrence ( String s ) { int n = s . length ( ) ; HashMap < String , Integer > freq = new HashMap < String , Integer > ( ) ; int i , j ; for ( i = 0 ; i < n ; i ++ ) { String temp = " " ; temp += s . charAt ( i ) ; if ( freq . containsKey ( temp ) ) { freq . put ( temp , freq . get ( temp ) + 1 ) ; } else { freq . put ( temp , 1 ) ; } } for ( i = 0 ; i < n ; i ++ ) { for ( j = i + 1 ; j < n ; j ++ ) { String temp = " " ; temp += s . charAt ( i ) ; temp += s . charAt ( j ) ; if ( freq . containsKey ( temp ) ) freq . put ( temp , freq . get ( temp ) + 1 ) ; else freq . put ( temp , 1 ) ; } } int answer = Integer . MIN_VALUE ; for ( int it : freq . values ( ) ) answer = Math . max ( answer , it ) ; return answer ; } public static void main ( String [ ] args ) { String s = " xxxyy " ; System . out . print ( maximumOccurrence ( s ) ) ; } }

Accumulator variables: i, j, temp
Iterator variables: i, it, j
Class/struct names: GFG
Java program:
class GFG { static int distinctChars ( String s ) { int freq [ ] = new int [ 26 ] ; int count = 0 ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) freq [ s . charAt ( i ) - ' a ' ] ++ ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( freq [ i ] > 0 ) count ++ ; } return count ; } static int waysToSplit ( String s ) { int n = s . length ( ) ; int answer = 0 ; for ( int i = 1 ; i < n ; i ++ ) { String left = s . substring ( 0 , i ) ; String right = s . substring ( i , n ) ; if ( distinctChars ( left ) == distinctChars ( right ) ) answer ++ ; } return answer ; } public static void main ( String [ ] args ) { String s = " ababa " ; System . out . print ( waysToSplit ( s ) ) ; } }

Index/key variables: i
Accumulator variables: answer, count, i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int waysToSplit ( String s ) { int n = s . length ( ) ; int answer = 0 ; int prefix [ ] = new int [ n ] ; int suffix [ ] = new int [ n ] ; int seen [ ] = new int [ 26 ] ; for ( int i = 0 ; i < n ; i ++ ) { int prev = ( i - 1 >= 0 ? prefix [ i - 1 ] : 0 ) ; if ( seen [ s . charAt ( i ) - ' a ' ] == 0 ) { prefix [ i ] += ( prev + 1 ) ; } else prefix [ i ] = prev ; seen [ s . charAt ( i ) - ' a ' ] = 1 ; } for ( int i = 0 ; i < 26 ; i ++ ) seen [ i ] = 0 ; suffix [ n - 1 ] = 0 ; for ( int i = n - 1 ; i >= 1 ; i -- ) { int prev = suffix [ i ] ; if ( seen [ s . charAt ( i ) - ' a ' ] == 0 ) { suffix [ i - 1 ] += ( prev + 1 ) ; } else suffix [ i - 1 ] = prev ; seen [ s . charAt ( i ) - ' a ' ] = 1 ; } for ( int i = 0 ; i < n ; i ++ ) { if ( prefix [ i ] == suffix [ i ] ) answer ++ ; } return answer ; } public static void main ( String [ ] args ) { String s = " ababa " ; System . out . println ( waysToSplit ( s ) ) ; } }

Index/key variables: i, n
Accumulator variables: answer, i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static long Count_Paths ( int x , int y ) { if ( x == 0 && y == 0 ) return 0 ; if ( x == 0 y == 0 ) return 1 ; int [ ] dp = new int [ Math . max ( x , y ) + 1 ] ; int p = Math . max ( x , y ) , q = Math . min ( x , y ) ; for ( int i = 0 ; i <= p ; i ++ ) dp [ i ] = 1 ; for ( int i = 1 ; i <= q ; i ++ ) for ( int j = 1 ; j <= p ; j ++ ) dp [ j ] += dp [ j - 1 ] ; return dp [ p ] ; } public static void main ( String [ ] args ) { int x = 3 , y = 3 ; System . out . print ( " Number ▁ of ▁ Paths ▁ " + Count_Paths ( x , y ) ) ; } }

Index/key variables: i, j, p
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static final int MAX_SIZE = 100005 ; static int [ ] fib = new int [ MAX_SIZE + 1 ] ; static void fibonacci ( ) { int i ; fib [ 0 ] = 0 ; fib [ 1 ] = 1 ; for ( i = 2 ; i <= MAX_SIZE ; i ++ ) { fib [ i ] = fib [ i - 1 ] + fib [ i - 2 ] ; } } static void printLevel ( int level ) { int left_index = ( int ) Math . pow ( 2 , level - 1 ) ; int right_index = ( int ) ( Math . pow ( 2 , level ) - 1 ) ; for ( int i = left_index ; i <= right_index ; i ++ ) { System . out . print ( fib [ i - 1 ] + " ▁ " ) ; } System . out . println ( ) ; } public static void main ( String [ ] args ) { fibonacci ( ) ; int K = 4 ; printLevel ( K ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int calculate ( int pos , int prev , int left , int k ) { if ( pos == k ) { if ( left == 0 ) return 1 ; else return 0 ; } if ( left == 0 ) return 0 ; int answer = 0 ; for ( int i = prev ; i <= left ; i ++ ) { answer += calculate ( pos + 1 , i , left - i , k ) ; } return answer ; } static int countWaystoDivide ( int n , int k ) { return calculate ( 0 , 1 , n , k ) ; } public static void main ( String [ ] args ) { int N = 8 ; int K = 4 ; System . out . print ( countWaystoDivide ( N , K ) ) ; } }

Accumulator variables: answer, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int [ ] [ ] [ ] dp = new int [ 500 ] [ 500 ] [ 500 ] ; static int calculate ( int pos , int prev , int left , int k ) { if ( pos == k ) { if ( left == 0 ) return 1 ; else return 0 ; } if ( left == 0 ) return 0 ; if ( dp [ pos ] [ prev ] [ left ] != - 1 ) return dp [ pos ] [ prev ] [ left ] ; int answer = 0 ; for ( int i = prev ; i <= left ; i ++ ) { answer += calculate ( pos + 1 , i , left - i , k ) ; } return dp [ pos ] [ prev ] [ left ] = answer ; } static int countWaystoDivide ( int n , int k ) { for ( int i = 0 ; i < 500 ; i ++ ) { for ( int j = 0 ; j < 500 ; j ++ ) { for ( int l = 0 ; l < 500 ; l ++ ) dp [ i ] [ j ] [ l ] = - 1 ; } } return calculate ( 0 , 1 , n , k ) ; } public static void main ( String [ ] args ) { int N = 8 ; int K = 4 ; System . out . print ( countWaystoDivide ( N , K ) ) ; } }

Index/key variables: i, j, l, left, pos, prev
Accumulator variables: answer, i, j, l
Iterator variables: i, j, l
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int maxScore ( int l , int r , int prefix_sum [ ] , int num ) { if ( l > r ) return 0 ; int current_sum = prefix_sum [ r ] - ( l - 1 >= 0 ? prefix_sum [ l - 1 ] : 0 ) ; if ( num % 2 == 0 ) current_sum *= - 1 ; return current_sum + Math . max ( maxScore ( l + 1 , r , prefix_sum , num + 1 ) , maxScore ( l , r - 1 , prefix_sum , num + 1 ) ) ; } static int findMaxScore ( int a [ ] , int n ) { int prefix_sum [ ] = new int [ n ] ; prefix_sum [ 0 ] = a [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { prefix_sum [ i ] = prefix_sum [ i - 1 ] + a [ i ] ; } return maxScore ( 0 , n - 1 , prefix_sum , 1 ) ; } public static void main ( String [ ] args ) { int n = 6 ; int A [ ] = { 1 , 2 , 3 , 4 , 2 , 6 } ; System . out . print ( findMaxScore ( A , n ) ) ; } }

Index/key variables: i, n, r
Accumulator variables: current_sum, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static HashMap < Integer , Integer > Map = new HashMap < Integer , Integer > ( ) ; static void findPrimeFactors ( int N ) { int i ; Map . clear ( ) ; while ( N % 2 == 0 ) { if ( Map . containsKey ( 2 ) ) Map . put ( 2 , Map . get ( 2 ) + 1 ) ; else Map . put ( 2 , 1 ) ; N /= 2 ; } for ( i = 3 ; i <= Math . sqrt ( N ) ; i += 2 ) { while ( N % i == 0 ) { if ( Map . containsKey ( i ) ) Map . put ( i , Map . get ( i ) + 1 ) ; else Map . put ( i , 1 ) ; N /= i ; } } if ( N > 2 ) { if ( Map . containsKey ( N ) ) Map . put ( N , Map . get ( N ) + 1 ) ; else Map . put ( N , 1 ) ; } } static int PowInFactN ( int N , int P ) { int ans = 0 ; int temp = P ; while ( temp <= N ) { ans += N / temp ; temp = temp * P ; } return ans ; } static int findPowers ( int N , int P ) { findPrimeFactors ( P ) ; Vector < Integer > Powers = new Vector < Integer > ( ) ; for ( Map . Entry < Integer , Integer > it : Map . entrySet ( ) ) { int primeFac = it . getKey ( ) ; int facPow = it . getValue ( ) ; int p = PowInFactN ( N , primeFac ) ; p /= facPow ; Powers . add ( p ) ; } return Collections . min ( Powers ) ; } public static void main ( String [ ] args ) { int N = 24 , P = 4 ; System . out . print ( findPowers ( N , P ) ) ; } }

Accumulator variables: N, ans, i, p
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int FindMaxLength ( int A [ ] , int B [ ] , int n , int m ) { int [ ] [ ] dp = new int [ n + 1 ] [ m + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) for ( int j = 0 ; j <= m ; j ++ ) dp [ i ] [ j ] = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { for ( int j = m - 1 ; j >= 0 ; j -- ) { if ( A [ i ] == B [ j ] ) dp [ j ] [ i ] = dp [ j + 1 ] [ i + 1 ] + 1 ; } } int maxm = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { maxm = Math . max ( maxm , dp [ i ] [ j ] ) ; } } return maxm ; } public static void main ( String [ ] args ) { int A [ ] = { 1 , 2 , 8 , 2 , 1 } ; int B [ ] = { 8 , 2 , 1 , 4 , 7 } ; int n = A . length ; int m = B . length ; System . out . print ( FindMaxLength ( A , B , n , m ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int maxLength ( int [ ] a , int n ) { int maximum = 1 ; int left [ ] = new int [ n ] ; int right [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { left [ i ] = 1 ; right [ i ] = 1 ; } for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( a [ i ] > a [ i + 1 ] ) { right [ i ] = right [ i + 1 ] + 1 ; } maximum = Math . max ( maximum , right [ i ] ) ; } for ( int i = 1 ; i < n ; i ++ ) { if ( a [ i ] < a [ i - 1 ] ) { left [ i ] = left [ i - 1 ] + 1 ; } } if ( n > 2 ) { for ( int i = 1 ; i < n - 1 ; i ++ ) { if ( a [ i - 1 ] > a [ i + 1 ] ) { maximum = Math . max ( maximum , left [ i - 1 ] + right [ i + 1 ] ) ; } } } return maximum ; } public static void main ( String [ ] args ) { int arr [ ] = { 8 , 7 , 3 , 5 , 2 , 9 } ; int n = arr . length ; System . out . println ( maxLength ( arr , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int LAS [ ] [ ] = new int [ 1000 ] [ 2 ] ; static int solve ( int arr [ ] , int n , int i , int pos ) { if ( i == n ) return 0 ; if ( LAS [ i ] [ pos ] == 1 ) return LAS [ i ] [ pos ] ; int inc = 0 , exc = 0 ; if ( arr [ i ] > 0 && pos == 1 ) { pos = 0 ; inc = 1 + solve ( arr , n , i + 1 , pos ) ; } else if ( arr [ i ] < 0 && pos == 0 ) { pos = 1 ; inc = 1 + solve ( arr , n , i + 1 , pos ) ; } exc = solve ( arr , n , i + 1 , pos ) ; LAS [ i ] [ pos ] = Math . max ( inc , exc ) ; return LAS [ i ] [ pos ] ; } public static void main ( String [ ] args ) { int arr [ ] = { - 1 , 2 , 3 , 4 , 5 , - 6 , 8 , - 99 } ; int n = arr . length ; System . out . println ( Math . max ( solve ( arr , n , 0 , 0 ) , solve ( arr , n , 0 , 1 ) ) ) ; } }

Index/key variables: i, pos
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int cntSubSeq ( int arr [ ] , int n ) { int pos_count = 0 ; int neg_count = 0 ; int result ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 ) pos_count ++ ; if ( arr [ i ] < 0 ) neg_count ++ ; } result = ( int ) Math . pow ( 2 , pos_count ) ; if ( neg_count > 0 ) result *= Math . pow ( 2 , neg_count - 1 ) ; else result = 0 ; return result ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , - 4 , - 1 , 6 } ; int n = arr . length ; System . out . print ( cntSubSeq ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, neg_count, pos_count, result
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { final static int INT_MAX = Integer . MAX_VALUE ; static int minSteps ( String str , int n , int k ) { if ( str . charAt ( n - 1 ) == '0' ) return - 1 ; if ( n == 1 ) return 0 ; if ( n < 4 ) return 1 ; int dp [ ] = new int [ n ] ; dp [ n - 1 ] = 0 ; dp [ n - 2 ] = 1 ; dp [ n - 3 ] = 1 ; for ( int i = n - 4 ; i >= 0 ; i -- ) { if ( str . charAt ( i ) == '0' ) continue ; int steps = INT_MAX ; if ( i + k < n && str . charAt ( i + k ) == '1' ) steps = Math . min ( steps , dp [ i + k ] ) ; if ( str . charAt ( i + 1 ) == '1' ) steps = Math . min ( steps , dp [ i + 1 ] ) ; if ( str . charAt ( i + 2 ) == '1' ) steps = Math . min ( steps , dp [ i + 2 ] ) ; dp [ i ] = ( steps == INT_MAX ) ? steps : 1 + steps ; } if ( dp [ 0 ] == INT_MAX ) return - 1 ; return dp [ 0 ] ; } public static void main ( String [ ] args ) { String str = "101000011" ; int n = str . length ( ) ; int k = 5 ; System . out . println ( minSteps ( str , n , k ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static Map < String , Integer > dp = new HashMap < > ( ) ; static Integer solve ( char [ ] s , char c ) { if ( s . length == 1 ) return 0 ; if ( s . length == 2 ) { if ( s [ 0 ] == s [ 1 ] && s [ 0 ] == c ) return 1 ; else return 0 ; } if ( dp . containsKey ( String . valueOf ( s ) + " ▁ " + c ) ) return dp . get ( String . valueOf ( s ) + " ▁ " + c ) ; Integer ans = 0 ; if ( s [ 0 ] == s [ s . length - 1 ] && s [ 0 ] == c ) { for ( char c1 = ' a ' ; c1 <= ' z ' ; c1 ++ ) if ( c1 != c ) ans = Math . max ( ans , 1 + solve ( Arrays . copyOfRange ( s , 1 , s . length - 1 ) , c1 ) ) ; } else { for ( Integer i = 0 ; i < s . length ; i ++ ) { if ( s [ i ] == c ) { for ( Integer j = s . length - 1 ; j > i ; j -- ) if ( s [ j ] == c ) { if ( j == i ) break ; ans = solve ( Arrays . copyOfRange ( s , i , j + 1 ) , c ) ; break ; } break ; } } } dp . put ( String . valueOf ( s ) + " ▁ " + c , ans ) ; return dp . get ( String . valueOf ( s ) + " ▁ " + c ) ; } public static void main ( String [ ] args ) { String s = " abscrcdba " ; Integer ma = 0 ; for ( char c1 = ' a ' ; c1 <= ' z ' ; c1 ++ ) ma = Math . max ( ma , solve ( s . toCharArray ( ) , c1 ) * 2 ) ; System . out . print ( ma + "NEW_LINE"); } }

Index/key variables: i, j
Accumulator variables: c1, i, j
Iterator variables: c1, i, j
Class/struct names: GFG
Java program:
class GFG { static int eggDrop ( int n , int k ) { int dp [ ] [ ] = new int [ k + 1 ] [ n + 1 ] ; int x = 0 ; while ( dp [ x ] [ n ] < k ) { x ++ ; for ( int i = 1 ; i <= n ; i ++ ) dp [ x ] [ i ] = dp [ x - 1 ] [ i - 1 ] + dp [ x - 1 ] [ i ] + 1 ; } return x ; } public static void main ( String args [ ] ) { int n = 2 , k = 36 ; System . out . println ( eggDrop ( n , k ) ) ; } }

Index/key variables: i, n, x
Accumulator variables: i, x
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int maxIncSubarr ( int a [ ] , int n ) { int pre [ ] = new int [ n ] ; int pos [ ] = new int [ n ] ; pre [ 0 ] = 1 ; pos [ n - 1 ] = 1 ; int l = 0 ; for ( int i = 1 ; i < n ; i ++ ) { if ( a [ i ] > a [ i - 1 ] ) pre [ i ] = pre [ i - 1 ] + 1 ; else pre [ i ] = 1 ; } l = 1 ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( a [ i ] < a [ i + 1 ] ) pos [ i ] = pos [ i + 1 ] + 1 ; else pos [ i ] = 1 ; } int ans = 0 ; l = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( a [ i ] > a [ i - 1 ] ) l ++ ; else l = 1 ; ans = Math . max ( ans , l ) ; } for ( int i = 1 ; i <= n - 2 ; i ++ ) { if ( a [ i - 1 ] < a [ i + 1 ] ) ans = Math . max ( pre [ i - 1 ] + pos [ i + 1 ] , ans ) ; } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 } ; int n = arr . length ; System . out . println ( maxIncSubarr ( arr , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i, l
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { final static int n = 3 ; final static int m = 3 ; static int countSquareMatrices ( int a [ ] [ ] , int N , int M ) { int count = 0 ; for ( int i = 1 ; i < N ; i ++ ) { for ( int j = 1 ; j < M ; j ++ ) { if ( a [ i ] [ j ] == 0 ) continue ; a [ i ] [ j ] = Math . min ( Math . min ( a [ i - 1 ] [ j ] , a [ i ] [ j - 1 ] ) , a [ i - 1 ] [ j - 1 ] ) + 1 ; } } for ( int i = 0 ; i < N ; i ++ ) for ( int j = 0 ; j < M ; j ++ ) count += a [ i ] [ j ] ; return count ; } public static void main ( String [ ] args ) { int arr [ ] [ ] = { { 1 , 0 , 1 } , { 1 , 1 , 0 } , { 1 , 1 , 0 } } ; System . out . println ( countSquareMatrices ( arr , n , m ) ) ; } }

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 final int N = 10000 ; static int [ ] seg = new int [ 3 * N ] ; static int update ( int in , int l , int r , int up_in , int val ) { if ( r < up_in l > up_in ) return seg [ in ] ; if ( l == up_in && r == up_in ) return seg [ in ] = val ; int m = ( l + r ) / 2 ; return seg [ in ] = update ( 2 * in + 1 , l , m , up_in , val ) + update ( 2 * in + 2 , m + 1 , r , up_in , val ) ; } static int query ( int in , int l , int r , int l1 , int r1 ) { if ( l > r ) return 0 ; if ( r < l1 l > r1 ) return 0 ; if ( l1 <= l && r <= r1 ) return seg [ in ] ; int m = ( l + r ) / 2 ; return query ( 2 * in + 1 , l , m , l1 , r1 ) + query ( 2 * in + 2 , m + 1 , r , l1 , r1 ) ; } static int findCnt ( int [ ] arr , int n ) { int [ ] brr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) brr [ i ] = arr [ i ] ; Arrays . sort ( brr ) ; HashMap < Integer , Integer > r = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) r . put ( brr [ i ] , i + 1 ) ; int dp [ ] = new int [ n ] ; int ans = 0 ; for ( int i = n - 1 ; i >= 0 ; i -- ) { int rank = r . get ( arr [ i ] ) ; dp [ i ] = 1 + query ( 0 , 0 , n - 1 , rank , n - 1 ) ; ans += dp [ i ] ; update ( 0 , 0 , n - 1 , rank - 1 , dp [ i ] + query ( 0 , 0 , n - 1 , rank - 1 , rank - 1 ) ) ; } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 10 , 9 } ; int n = arr . length ; System . out . print ( findCnt ( arr , n ) ) ; } }

Index/key variables: i, in, n
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int minCost ( int n , int x , int y , int z ) { int dp [ ] = new int [ n + 1 ] ; dp [ 0 ] = dp [ 1 ] = 0 ; for ( int i = 2 ; i <= n ; i ++ ) { if ( i % 2 == 1 ) { dp [ i ] = Math . min ( dp [ ( i + 1 ) / 2 ] + x + z , dp [ i - 1 ] + y ) ; } else { dp [ i ] = Math . min ( dp [ i / 2 ] + x , dp [ i - 1 ] + y ) ; } } return dp [ n ] ; } public static void main ( String [ ] args ) { int n = 5 , x = 2 , y = 1 , z = 3 ; System . out . print ( minCost ( n , x , y , z ) + "NEW_LINE"); } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { final static int N = 1000005 ; static int maximum_set ( int a [ ] , int n ) { int dp [ ] = new int [ N ] ; for ( int i = 0 ; i < n ; i ++ ) dp [ a [ i ] ] = 1 ; int ans = 1 ; for ( int i = N - 1 ; i >= 1 ; i -- ) { if ( dp [ i ] != 0 ) { for ( int j = 2 * i ; j < N ; j += i ) { dp [ i ] = Math . max ( dp [ i ] , 1 + dp [ j ] ) ; ans = Math . max ( ans , dp [ i ] ) ; } } } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 4 , 6 , 8 , 10 , 18 , 21 , 24 } ; int n = arr . length ; System . out . println ( maximum_set ( arr , n ) ) ; } }

Index/key variables: N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static final int N = 100 ; static int dp [ ] [ ] = new int [ N ] [ 3 ] ; static int v [ ] [ ] = new int [ N ] [ 3 ] ; static int findCnt ( String s , int i , int r ) { if ( i == s . length ( ) ) { if ( r == 0 ) return 1 ; else return 0 ; } if ( v [ i ] [ r ] == 1 ) return dp [ i ] [ r ] ; v [ i ] [ r ] = 1 ; dp [ i ] [ r ] = findCnt ( s , i + 1 , ( r * 2 + ( s . charAt ( i ) - '0' ) ) % 3 ) + findCnt ( s , i + 1 , r ) ; return dp [ i ] [ r ] ; } public static void main ( String [ ] args ) { String s = "11" ; System . out . print ( findCnt ( s , 0 , 0 ) - 1 ) ; } }

Index/key variables: N, i, r
Class/struct names: GFG
Java program:
class GFG { static int minCount ( int arr [ ] , int n , int k ) { int ans = 0 ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; sum -= k ; int l = 0 ; int r = 0 ; int tot = 0 ; while ( l < n ) { if ( tot <= sum ) { ans = Math . max ( ans , r - l ) ; if ( r == n ) break ; tot += arr [ r ++ ] ; } else { tot -= arr [ l ++ ] ; } } return ( n - ans ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 11 , 5 , 5 } ; int n = arr . length ; int k = 11 ; System . out . println ( minCount ( arr , n , k ) ) ; } }

Index/key variables: i
Accumulator variables: i, l, r, sum, tot
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static final int N = 401 ; static int [ ] [ ] dp = new int [ N ] [ N ] ; static boolean [ ] [ ] v = new boolean [ N ] [ N ] ; static int minMergeCost ( int i , int j , int [ ] arr ) { if ( i == j ) return 0 ; if ( v [ i ] [ j ] ) return dp [ i ] [ j ] ; v [ i ] [ j ] = true ; int x = dp [ i ] [ j ] ; x = Integer . MAX_VALUE ; int tot = 0 ; for ( int k = i ; k <= j ; k ++ ) tot += arr [ k ] ; for ( int k = i + 1 ; k <= j ; k ++ ) { x = Math . min ( x , tot + minMergeCost ( i , k - 1 , arr ) + minMergeCost ( k , j , arr ) ) ; } return x ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 7 } ; int n = arr . length ; System . out . print ( minMergeCost ( 0 , n - 1 , arr ) ) ; } }

Index/key variables: N, i, j, k
Accumulator variables: k, tot
Iterator variables: k
Class/struct names: GFG
Java program:
class GFG { static int maxSize = 50 ; static double dp [ ] = new double [ maxSize ] ; static int v [ ] = new int [ maxSize ] ; static double expectedSteps ( int x ) { if ( x == 0 ) return 0 ; if ( x <= 5 ) return 6 ; if ( v [ x ] == 1 ) return dp [ x ] ; v [ x ] = 1 ; dp [ x ] = 1 + ( expectedSteps ( x - 1 ) + expectedSteps ( x - 2 ) + expectedSteps ( x - 3 ) + expectedSteps ( x - 4 ) + expectedSteps ( x - 5 ) + expectedSteps ( x - 6 ) ) / 6 ; return dp [ x ] ; } public static void main ( String [ ] args ) { int n = 10 ; System . out . println ( expectedSteps ( n - 1 ) ) ; } }

Index/key variables: maxSize, x
Class/struct names: GFG
Java program:
class GFG { static int countSubSeq ( String str , int len ) { int ans = 0 ; int mul = 1 ; for ( int i = 0 ; i < len ; i ++ ) { if ( str . charAt ( i ) == '0' ) ans += mul ; mul *= 2 ; } return ans ; } public static void main ( String [ ] args ) { String str = "10010" ; int len = str . length ( ) ; System . out . print ( countSubSeq ( str , len ) ) ; } }

Accumulator variables: ans, i, mul
Iterator variables: i
Class/struct names: GFG