dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class GFG { static int [ ] [ ] dp = new int [ 500 ] [ 500 ] ; static int CountSets ( int x , int pos ) { if ( x <= 0 ) { if ( pos == 0 ) return 1 ; else return 0 ; } if ( pos == 0 ) return 1 ; if ( dp [ x ] [ pos ] != - 1 ) return dp [ x ] [ pos ] ; int answer = CountSets ( x - 1 , pos ) + CountSets ( x - 2 , pos - 1 ) ; return dp [ x ] [ pos ] = answer ; } static int CountOrderedSets ( int n ) { int [ ] factorial = new int [ 10000 ] ; factorial [ 0 ] = 1 ; for ( int i = 1 ; i < 10000 ; i ++ ) factorial [ i ] = factorial [ i - 1 ] * i ; int answer = 0 ; for ( int i = 0 ; i < 500 ; i ++ ) { for ( int j = 0 ; j < 500 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } for ( int i = 1 ; i <= n ; i ++ ) { int sets = CountSets ( n , i ) * factorial [ i ] ; answer = answer + sets ; } return answer ; } public static void main ( String [ ] args ) { int N = 3 ; System . out . print ( CountOrderedSets ( N ) ) ; } }

Index/key variables: i, j, pos, x
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int numberOfArithmeticSequences ( int L [ ] , int N ) { if ( N <= 2 ) return 0 ; int count = 0 ; int res = 0 ; for ( int i = 2 ; i < N ; ++ i ) { if ( L [ i ] - L [ i - 1 ] == L [ i - 1 ] - L [ i - 2 ] ) { ++ count ; } else { count = 0 ; } res += count ; } return res ; } public static void main ( String [ ] args ) { int L [ ] = { 1 , 3 , 5 , 6 , 7 , 8 } ; int N = L . length ; System . out . print ( numberOfArithmeticSequences ( L , N ) ) ; } }

Index/key variables: i
Accumulator variables: res
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . Arrays ; import java . util . ArrayList ; import java . lang . * ; import java . util . Collections ; class GFG { static int CountOfTriplets ( int a [ ] , int n ) { int answer = 0 ; int x = 0 ; int count [ ] = new int [ 100005 ] ; int ways [ ] = new int [ 100005 ] ; for ( int i = 0 ; i < n ; i ++ ) { x ^= a [ i ] ; answer += count [ x ] * i - ways [ x ] ; count [ x ] ++ ; ways [ x ] += ( i + 1 ) ; } return answer ; } public static void main ( String [ ] args ) { int Arr [ ] = { 3 , 6 , 12 , 8 , 6 , 2 , 1 , 5 } ; int N = Arr . length ; System . out . print ( CountOfTriplets ( Arr , N ) ) ; } }

Index/key variables: i, x
Accumulator variables: answer, i, x
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int [ ] [ ] dp = new int [ 5000 ] [ ( 1 << 10 ) + 5 ] ; static int getmask ( int val ) { int mask = 0 ; if ( val == 0 ) return 1 ; while ( val > 0 ) { int d = val % 10 ; mask |= ( 1 << d ) ; val /= 10 ; } return mask ; } static int countWays ( int pos , int mask , int a [ ] , int n ) { if ( pos == n ) return ( mask > 0 ? 1 : 0 ) ; if ( dp [ pos ] [ mask ] != - 1 ) return dp [ pos ] [ mask ] ; int count = 0 ; count = count + countWays ( pos + 1 , mask , a , n ) ; if ( ( getmask ( a [ pos ] ) & mask ) == 0 ) { int new_mask = ( mask | ( getmask ( a [ pos ] ) ) ) ; count = count + countWays ( pos + 1 , new_mask , a , n ) ; } return dp [ pos ] [ mask ] = count ; } static int numberOfSubarrays ( int a [ ] , int n ) { for ( int i = 0 ; i < 5000 ; i ++ ) { for ( int j = 0 ; j < ( 1 << 10 ) + 5 ; j ++ ) { dp [ i ] [ j ] = - 1 ; } } return countWays ( 0 , 0 , a , n ) ; } public static void main ( String [ ] args ) { int N = 4 ; int A [ ] = { 1 , 12 , 23 , 34 } ; System . out . print ( numberOfSubarrays ( A , N ) ) ; } }

Index/key variables: i, j, mask, pos
Accumulator variables: i, j, mask, val
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static Vector < Integer > fib = new Vector < Integer > ( ) ; static class node { node left ; int data ; node right ; } ; static node newNode ( int data ) { node temp = new node ( ) ; temp . data = data ; temp . left = null ; temp . right = null ; return temp ; } static int height ( node root ) { if ( root == null ) return 0 ; return ( Math . max ( height ( root . left ) , height ( root . right ) ) + 1 ) ; } static void FibonacciSeries ( int n ) { fib . add ( 0 ) ; fib . add ( 1 ) ; for ( int i = 2 ; i < n ; i ++ ) fib . add ( fib . get ( i - 1 ) + fib . get ( i - 2 ) ) ; } static int CountPathUtil ( node root , int i , int count ) { if ( root == null || ! ( fib . get ( i ) == root . data ) ) { return count ; } if ( root . left != null && root . right != null ) { count ++ ; } count = CountPathUtil ( root . left , i + 1 , count ) ; return CountPathUtil ( root . right , i + 1 , count ) ; } static void CountPath ( node root ) { int ht = height ( root ) ; FibonacciSeries ( ht ) ; System . out . print ( CountPathUtil ( root , 0 , 0 ) ) ; } public static void main ( String [ ] args ) { node root = newNode ( 0 ) ; root . left = newNode ( 1 ) ; root . right = newNode ( 1 ) ; root . left . left = newNode ( 1 ) ; root . left . right = newNode ( 4 ) ; root . right . right = newNode ( 1 ) ; root . right . right . left = newNode ( 2 ) ; CountPath ( root ) ; } }

Accumulator variables: count, i
Iterator variables: i
Class/struct names: GFG, node
Java program:
import java . util . * ; class GFG { static int M = 18 ; static int a , b ; static int [ ] [ ] [ ] [ ] dp = new int [ M ] [ 90 ] [ 90 ] [ 2 ] ; static HashSet < Integer > fib = new HashSet < Integer > ( ) ; static void fibonacci ( ) { int prev = 0 , curr = 1 ; fib . add ( prev ) ; fib . add ( curr ) ; while ( curr <= 100 ) { int temp = curr + prev ; fib . add ( temp ) ; prev = curr ; curr = temp ; } } static int count ( int pos , int even , int odd , int tight , Vector < Integer > num ) { if ( pos == num . size ( ) ) { if ( num . size ( ) % 2 == 1 ) { odd = odd + even ; even = odd - even ; odd = odd - even ; } int d = even - odd ; if ( fib . contains ( d ) ) return 1 ; return 0 ; } if ( dp [ pos ] [ even ] [ odd ] [ tight ] != - 1 ) return dp [ pos ] [ even ] [ odd ] [ tight ] ; int ans = 0 ; int limit = ( tight == 1 ? 9 : num . get ( pos ) ) ; for ( int d = 0 ; d <= limit ; d ++ ) { int currF = tight , currEven = even ; int currOdd = odd ; if ( d < num . get ( pos ) ) currF = 1 ; if ( pos % 2 == 1 ) currOdd += d ; else currEven += d ; ans += count ( pos + 1 , currEven , currOdd , currF , num ) ; } return dp [ pos ] [ even ] [ odd ] [ tight ] = ans ; } static int solve ( int x ) { Vector < Integer > num = new Vector < Integer > ( ) ; while ( x > 0 ) { num . add ( x % 10 ) ; x /= 10 ; } Collections . reverse ( num ) ; for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < 90 ; j ++ ) { for ( int l = 0 ; l < 90 ; l ++ ) { for ( int k = 0 ; k < 2 ; k ++ ) { dp [ i ] [ j ] [ l ] [ k ] = - 1 ; } } } } return count ( 0 , 0 , 0 , 0 , num ) ; } public static void main ( String [ ] args ) { fibonacci ( ) ; int L = 1 , R = 50 ; System . out . print ( solve ( R ) - solve ( L - 1 ) + "NEW_LINE"); L = 50 ; R = 100 ; System . out . print ( solve ( R ) - solve ( L - 1 ) + "NEW_LINE"); } }

Index/key variables: M, even, i, j, k, l, odd, pos, tight
Accumulator variables: ans, currEven, currOdd, d, i, j, k, l, x
Iterator variables: d, i, j, k, l
Class/struct names: GFG
Java program:
class GFG { static int maximumOccurrence ( String s ) { int n = s . length ( ) ; int freq [ ] = new int [ 26 ] ; int dp [ ] [ ] = new int [ 26 ] [ 26 ] ; for ( int i = 0 ; i < n ; i ++ ) { int c = ( s . charAt ( i ) - ' a ' ) ; for ( int j = 0 ; j < 26 ; j ++ ) dp [ j ] += freq [ j ] ; freq ++ ; } int answer = Integer . MIN_VALUE ; for ( int i = 0 ; i < 26 ; i ++ ) answer = Math . max ( answer , freq [ i ] ) ; for ( int i = 0 ; i < 26 ; i ++ ) { for ( int j = 0 ; j < 26 ; j ++ ) { answer = Math . max ( answer , dp [ i ] [ j ] ) ; } } return answer ; } public static void main ( String [ ] args ) { String s = " xxxyy " ; System . out . print ( maximumOccurrence ( s ) ) ; } }

Index/key variables: i, j
Accumulator variables: freq, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; import java . util . Arrays ; class GFG { static int mod = 1000000007 ; static int dp [ ] [ ] [ ] = new int [ 1005 ] [ 105 ] [ 2 ] ; static int powers [ ] = new int [ 1005 ] ; static int powersModk [ ] = new int [ 1005 ] ; static int calculate ( int pos , int rem , int z , int k , int n ) { if ( rem == 0 && z != 0 ) { if ( pos != n ) return ( powers [ n - pos - 1 ] * 9 ) % mod ; else return 1 ; } if ( pos == n ) return 0 ; if ( dp [ pos ] [ rem ] [ z ] != - 1 ) return dp [ pos ] [ rem ] [ z ] ; int count = 0 ; for ( int i = 0 ; i < 10 ; i ++ ) { if ( i == 0 ) count = ( count + ( calculate ( pos + 1 , ( rem + ( i * powersModk [ pos ] ) % k ) % k , z , k , n ) ) ) % mod ; else count = ( count + ( calculate ( pos + 1 , ( rem + ( i * powersModk [ pos ] ) % k ) % k , 1 , k , n ) ) ) % mod ; } return dp [ pos ] [ rem ] [ z ] = count ; } static int countNumbers ( int n , int k ) { int st = 1 ; int i ; for ( i = 0 ; i <= n ; i ++ ) { powers [ i ] = st ; st *= 10 ; st %= mod ; } st = 1 ; for ( i = 0 ; i <= n ; i ++ ) { powersModk [ i ] = st ; st *= 10 ; st %= mod ; } for ( int [ ] [ ] row : dp ) { for ( int [ ] innerRow : row ) { Arrays . fill ( innerRow , - 1 ) ; } } ; return calculate ( 0 , 0 , 0 , k , n ) ; } public static void main ( String [ ] args ) { int N = 2 ; int K = 2 ; System . out . print ( countNumbers ( N , K ) ) ; } }

Index/key variables: i, pos, rem, z
Accumulator variables: i, st
Iterator variables: i, innerRow, row
Class/struct names: GFG
Java program:
import java . util . ArrayList ; import java . util . Arrays ; class GFG { static class Pair < K , V > { K first ; V second ; public Pair ( K first , V second ) { this . first = first ; this . second = second ; } } static int inf = 100000000 ; static int smPath ( int s , int d , ArrayList < Pair < Pair < Integer , Integer > , Integer > > ed , int n , int k ) { int [ ] dis = new int [ n + 1 ] ; Arrays . fill ( dis , inf ) ; dis [ s ] = 0 ; for ( int i = 0 ; i < k ; i ++ ) { int [ ] dis1 = new int [ n + 1 ] ; Arrays . fill ( dis1 , inf ) ; for ( Pair < Pair < Integer , Integer > , Integer > it : ed ) dis1 [ it . first . second ] = Math . min ( dis1 [ it . first . second ] , dis [ it . first . first ] + it . second ) ; for ( int j = 0 ; j <= n ; j ++ ) dis [ j ] = dis1 [ j ] ; } if ( dis [ d ] == inf ) return - 1 ; else return dis [ d ] ; } public static void main ( String [ ] args ) { int n = 4 ; ArrayList < Pair < Pair < Integer , Integer > , Integer > > ed = new ArrayList < > ( Arrays . asList ( new Pair < Pair < Integer , Integer > , Integer > ( new Pair < Integer , Integer > ( 0 , 1 ) , 10 ) , new Pair < Pair < Integer , Integer > , Integer > ( new Pair < Integer , Integer > ( 0 , 2 ) , 3 ) , new Pair < Pair < Integer , Integer > , Integer > ( new Pair < Integer , Integer > ( 0 , 3 ) , 2 ) , new Pair < Pair < Integer , Integer > , Integer > ( new Pair < Integer , Integer > ( 1 , 3 ) , 7 ) , new Pair < Pair < Integer , Integer > , Integer > ( new Pair < Integer , Integer > ( 2 , 3 ) , 7 ) ) ) ; int s = 0 , d = 3 ; int k = 2 ; System . out . println ( smPath ( s , d , ed , n , k ) ) ; } }

Index/key variables: d, j, s
Accumulator variables: i, j
Iterator variables: i, it, j
Class/struct names: GFG, Pair
Java program:
import java . util . ArrayList ; import java . util . Arrays ; import java . util . PriorityQueue ; class Pair < K , V > { K first ; V second ; public Pair ( K first , V second ) { this . first = first ; this . second = second ; } } class GFG { static final float inf = Float . POSITIVE_INFINITY ; static float bellman ( int s , int d , ArrayList < Pair < Pair < Integer , Integer > , Float > > ed , int n ) { if ( s == d ) return 0 ; float [ ] dis = new float [ n + 1 ] ; Arrays . fill ( dis , inf ) ; dis [ s ] = 1 ; for ( int i = 0 ; i < n - 1 ; i ++ ) for ( Pair < Pair < Integer , Integer > , Float > it : ed ) dis [ it . first . second ] = Math . min ( dis [ it . first . second ] , dis [ it . first . first ] * it . second ) ; for ( Pair < Pair < Integer , Integer > , Float > it : ed ) { if ( dis [ it . first . second ] > dis [ it . first . first ] * it . second ) return - 2 ; } if ( dis [ d ] == inf ) return - 1 ; else return dis [ d ] ; } public static void main ( String [ ] args ) { int n = 3 ; ArrayList < Pair < Pair < Integer , Integer > , Float > > ed = new ArrayList < > ( Arrays . asList ( new Pair < Pair < Integer , Integer > , Float > ( new Pair < Integer , Integer > ( 1 , 2 ) , 0.5f ) , new Pair < Pair < Integer , Integer > , Float > ( new Pair < Integer , Integer > ( 1 , 3 ) , 1.9f ) , new Pair < Pair < Integer , Integer > , Float > ( new Pair < Integer , Integer > ( 2 , 3 ) , 3f ) ) ) ; int s = 1 , d = 3 ; float get = bellman ( s , d , ed , n ) ; if ( get == - 2 ) System . out . println ( " Cycle ▁ Detected " ) ; else System . out . println ( get ) ; } }

Index/key variables: d, s
Accumulator variables: i
Iterator variables: i, it
Class/struct names: GFG, Pair
Java program:
import java . util . * ; class GFG { public static int maxLengthSquare ( int row , int column , int [ ] [ ] arr , int k ) { int sum [ ] [ ] = new int [ row + 1 ] [ column + 1 ] ; int cur_max = 1 ; int max = 0 ; for ( int i = 1 ; i <= row ; i ++ ) { for ( int j = 1 ; j <= column ; j ++ ) { sum [ i ] [ j ] = sum [ i - 1 ] [ j ] + sum [ i ] [ j - 1 ] + arr [ i - 1 ] [ j - 1 ] - sum [ i - 1 ] [ j - 1 ] ; if ( i >= cur_max && j >= cur_max && sum [ i ] [ j ] - sum [ i - cur_max ] [ j ] - sum [ i ] [ j - cur_max ] + sum [ i - cur_max ] [ j - cur_max ] <= k ) { max = cur_max ++ ; } } } return max ; } public static void main ( String args [ ] ) { int row = 4 , column = 4 ; int matrix [ ] [ ] = { { 1 , 1 , 1 , 1 } , { 1 , 0 , 0 , 0 } , { 1 , 0 , 0 , 0 } , { 1 , 0 , 0 , 0 } } ; int k = 6 ; int ans = maxLengthSquare ( row , column , matrix , k ) ; System . out . println ( ans ) ; } }

Index/key variables: i, j
Accumulator variables: cur_max, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int N = 101 ; static int mod = ( int ) 1e9 + 7 ; static int exactsum [ ] [ ] [ ] = new int [ N ] [ N ] [ N ] ; static int exactnum [ ] [ ] [ ] = new int [ N ] [ N ] [ N ] ; static int getSum ( int x , int y , int z ) { int ans = 0 ; exactnum [ 0 ] [ 0 ] [ 0 ] = 1 ; for ( int i = 0 ; i <= x ; ++ i ) { for ( int j = 0 ; j <= y ; ++ j ) { for ( int k = 0 ; k <= z ; ++ k ) { if ( i > 0 ) { exactsum [ i ] [ j ] [ k ] += ( exactsum [ i - 1 ] [ j ] [ k ] * 10 + 4 * exactnum [ i - 1 ] [ j ] [ k ] ) % mod ; exactnum [ i ] [ j ] [ k ] += exactnum [ i - 1 ] [ j ] [ k ] % mod ; } if ( j > 0 ) { exactsum [ i ] [ j ] [ k ] += ( exactsum [ i ] [ j - 1 ] [ k ] * 10 + 5 * exactnum [ i ] [ j - 1 ] [ k ] ) % mod ; exactnum [ i ] [ j ] [ k ] += exactnum [ i ] [ j - 1 ] [ k ] % mod ; } if ( k > 0 ) { exactsum [ i ] [ j ] [ k ] += ( exactsum [ i ] [ j ] [ k - 1 ] * 10 + 6 * exactnum [ i ] [ j ] [ k - 1 ] ) % mod ; exactnum [ i ] [ j ] [ k ] += exactnum [ i ] [ j ] [ k - 1 ] % mod ; } ans += exactsum [ i ] [ j ] [ k ] % mod ; ans %= mod ; } } } return ans ; } public static void main ( String [ ] args ) { int x = 1 , y = 1 , z = 1 ; System . out . println ( getSum ( x , y , z ) % mod ) ; } }

Index/key variables: N, i, j, k
Accumulator variables: ans
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
class GFG { static void findMax ( int [ ] a , int n ) { int dp [ ] [ ] = new int [ n ] [ 2 ] ; int i , j ; for ( i = 0 ; i < n ; i ++ ) for ( j = 0 ; j < 2 ; j ++ ) dp [ i ] [ j ] = 0 ; dp [ 0 ] [ 0 ] = a [ 0 ] + a [ 1 ] ; dp [ 0 ] [ 1 ] = a [ 0 ] * a [ 1 ] ; for ( i = 1 ; i <= n - 2 ; i ++ ) { dp [ i ] [ 0 ] = Math . max ( dp [ i - 1 ] [ 0 ] , dp [ i - 1 ] [ 1 ] ) + a [ i + 1 ] ; dp [ i ] [ 1 ] = dp [ i - 1 ] [ 0 ] - a [ i ] + a [ i ] * a [ i + 1 ] ; } System . out . println ( Math . max ( dp [ n - 2 ] [ 0 ] , dp [ n - 2 ] [ 1 ] ) ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , - 1 , - 5 , - 3 , 2 , 9 , - 4 } ; findMax ( arr , 7 ) ; } }

Index/key variables: i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int sum ( int arr [ ] , int l , int r ) { int s = 0 ; for ( int i = l ; i <= r ; i ++ ) { s += arr [ i ] ; } return s ; } static int dp [ ] [ ] [ ] = new int [ 101 ] [ 101 ] [ 101 ] ; static int solve ( int arr [ ] , int l , int r , int k ) { if ( r - l + 1 <= k ) return sum ( arr , l , r ) ; if ( dp [ l ] [ r ] [ k ] != 0 ) return dp [ l ] [ r ] [ k ] ; int sum_ = sum ( arr , l , r ) ; int len_r = ( r - l + 1 ) - k ; int len = ( r - l + 1 ) ; int ans = 0 ; for ( int i = 0 ; i < len - len_r + 1 ; i ++ ) { int sum_sub = sum ( arr , i + l , i + l + len_r - 1 ) ; ans = Math . max ( ans , ( sum_ - sum_sub ) + ( sum_sub - solve ( arr , i + l , i + l + len_r - 1 , k ) ) ) ; } dp [ l ] [ r ] [ k ] = ans ; return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 10 , 15 , 20 , 9 , 2 , 5 } , k = 2 ; int n = arr . length ; System . out . println ( solve ( arr , 0 , n - 1 , k ) ) ; } }

Index/key variables: i, k, l, r
Accumulator variables: i, s
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { final static int MAXI = 50 ; static int dp [ ] [ ] [ ] = new int [ MAXI ] [ MAXI ] [ MAXI * MAXI ] ; static int n , m ; final static int INT_MAX = Integer . MAX_VALUE ; static int minDifference ( int x , int y , int k , int b [ ] [ ] , int c [ ] [ ] ) { if ( x >= n y >= m ) return INT_MAX ; if ( x == n - 1 && y == m - 1 ) { int diff = b [ x ] [ y ] - c [ x ] [ y ] ; return Math . min ( Math . abs ( k - diff ) , Math . abs ( k + diff ) ) ; } int ans = dp [ x ] [ y ] [ k ] ; if ( ans != - 1 ) return ans ; ans = INT_MAX ; int diff = b [ x ] [ y ] - c [ x ] [ y ] ; ans = Math . min ( ans , minDifference ( x + 1 , y , Math . abs ( k + diff ) , b , c ) ) ; ans = Math . min ( ans , minDifference ( x , y + 1 , Math . abs ( k + diff ) , b , c ) ) ; ans = Math . min ( ans , minDifference ( x + 1 , y , Math . abs ( k - diff ) , b , c ) ) ; ans = Math . min ( ans , minDifference ( x , y + 1 , Math . abs ( k - diff ) , b , c ) ) ; return ans ; } public static void main ( String [ ] args ) { n = 2 ; m = 2 ; int b [ ] [ ] = { { 1 , 4 } , { 2 , 4 } } ; int c [ ] [ ] = { { 3 , 2 } , { 3 , 1 } } ; for ( int i = 0 ; i < MAXI ; i ++ ) { for ( int j = 0 ; j < MAXI ; j ++ ) { for ( int k = 0 ; k < MAXI * MAXI ; k ++ ) { dp [ i ] [ j ] [ k ] = - 1 ; } } } System . out . println ( minDifference ( 0 , 0 , 0 , b , c ) ) ; } }

Index/key variables: MAXI, i, j, k, x, y
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
class GFG { static int longest_subseq ( int n , int k , String s ) { int [ ] dp = new int [ n ] ; int [ ] max_length = new int [ 26 ] ; for ( int i = 0 ; i < n ; i ++ ) { int curr = s . charAt ( i ) - ' a ' ; int lower = Math . max ( 0 , curr - k ) ; int upper = Math . min ( 25 , curr + k ) ; for ( int j = lower ; j < upper + 1 ; j ++ ) { dp [ i ] = Math . max ( dp [ i ] , max_length [ j ] + 1 ) ; } max_length [ curr ] = Math . max ( dp [ i ] , max_length [ curr ] ) ; } int ans = 0 ; for ( int i : dp ) ans = Math . max ( i , ans ) ; return ans ; } public static void main ( String [ ] args ) { String s = " geeksforgeeks " ; int n = s . length ( ) ; int k = 3 ; System . out . print ( longest_subseq ( n , k , s ) ) ; } }

Index/key variables: curr, i, j, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static boolean areAllNegative ( int [ ] arr ) { int n = arr . length ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > 0 ) return false ; } return true ; } static int [ ] getRightToLeftKadane ( int [ ] arr ) { int max_so_far = 0 , max_ending_here = 0 ; int size = arr . length ; int [ ] new_arr = new int [ size ] ; for ( int i = 0 ; i < size ; i ++ ) new_arr [ i ] = arr [ i ] ; for ( int i = size - 1 ; i >= 0 ; i -- ) { max_ending_here = max_ending_here + new_arr [ i ] ; if ( max_ending_here < 0 ) max_ending_here = 0 ; else if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ; new_arr [ i ] = max_so_far ; } return new_arr ; } static int [ ] getPrefixSum ( int [ ] arr ) { int n = arr . length ; int [ ] new_arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) new_arr [ i ] = arr [ i ] ; for ( int i = 1 ; i < n ; i ++ ) new_arr [ i ] = new_arr [ i - 1 ] + new_arr [ i ] ; return new_arr ; } static int maxSumSubArr ( int [ ] a ) { int max_so_far = 0 , max_ending_here = 0 ; int n = a . length ; for ( int i = 0 ; i < n ; i ++ ) { max_ending_here = max_ending_here + a [ i ] ; if ( max_ending_here < 0 ) max_ending_here = 0 ; else if ( max_so_far < max_ending_here ) max_so_far = max_ending_here ; } return max_so_far ; } static int maxSumSubWithOp ( int [ ] arr ) { int [ ] kadane_r_to_l = getRightToLeftKadane ( arr ) ; int size = arr . length ; int [ ] prefixSum = getPrefixSum ( arr ) ; for ( int i = 1 ; i < size ; i ++ ) { prefixSum [ i ] = Math . max ( prefixSum [ i - 1 ] , prefixSum [ i ] ) ; } int max_subarray_sum = 0 ; for ( int i = 0 ; i < size - 1 ; i ++ ) { max_subarray_sum = Math . max ( max_subarray_sum , prefixSum [ i ] + kadane_r_to_l [ i + 1 ] ) ; } return max_subarray_sum ; } static int maxSum ( int [ ] arr , int size ) { if ( areAllNegative ( arr ) ) { int mx = - 1000000000 ; for ( int i = 0 ; i < size ; i ++ ) { if ( arr [ i ] > mx ) mx = arr [ i ] ; } return mx ; } int resSum = maxSumSubArr ( arr ) ; resSum = Math . max ( resSum , maxSumSubWithOp ( arr ) ) ; int [ ] reverse_arr = new int [ size ] ; for ( int i = 0 ; i < size ; i ++ ) reverse_arr [ size - 1 - i ] = arr [ i ] ; resSum = Math . max ( resSum , maxSumSubWithOp ( reverse_arr ) ) ; return resSum ; } public static void main ( String args [ ] ) { int [ ] arr = { - 9 , 21 , 24 , 24 , - 51 , - 6 , 17 , - 42 , - 39 , 33 } ; int size = arr . length ; System . out . println ( maxSum ( arr , size ) ) ; } }

Index/key variables: i, n, size
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int max_sum ( int a [ ] , int n ) { int [ ] [ ] dp = new int [ n + 1 ] [ 2 ] ; dp [ 0 ] [ 0 ] = 0 ; dp [ 0 ] [ 1 ] = - 999999 ; for ( int i = 0 ; i <= n - 1 ; i ++ ) { dp [ i + 1 ] [ 0 ] = Math . max ( dp [ i ] [ 0 ] + a [ i ] , dp [ i ] [ 1 ] - a [ i ] ) ; dp [ i + 1 ] [ 1 ] = Math . max ( dp [ i ] [ 0 ] - a [ i ] , dp [ i ] [ 1 ] + a [ i ] ) ; } return dp [ n ] [ 0 ] ; } public static void main ( String [ ] args ) { int a [ ] = { - 10 , 5 , - 4 } ; int n = a . length ; System . out . println ( max_sum ( a , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static final int MOD = 1000000007 ; static int number_of_ways ( int arr [ ] , int n , int k ) { if ( k == 1 ) return 1 ; int dp [ ] = new int [ k + 1 ] ; int i ; for ( i = 0 ; i < k + 1 ; i ++ ) dp [ i ] = - 1 ; for ( i = 0 ; i < n ; i ++ ) dp [ arr [ i ] ] = 0 ; dp [ 0 ] = 1 ; dp [ 1 ] = ( dp [ 1 ] == - 1 ) ? 1 : dp [ 1 ] ; for ( i = 2 ; i <= k ; ++ i ) { if ( dp [ i ] == 0 ) continue ; dp [ i ] = dp [ i - 1 ] + dp [ i - 2 ] ; dp [ i ] %= MOD ; } return dp [ k ] ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 } ; int n = arr . length ; int k = 6 ; System . out . println ( number_of_ways ( arr , n , k ) ) ; } }

Index/key variables: i, k
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int findCount ( int n ) { return ( int ) ( Math . log ( n ) / Math . log ( 2 ) ) + 1 ; } public static void main ( String [ ] args ) { int N = 10 ; System . out . println ( findCount ( N ) ) ; } }

Class/struct names: GFG
Java program:
class GFG { static void findSetBits ( int n ) { for ( int i = 0 ; i <= n ; i ++ ) System . out . print ( Integer . bitCount ( i ) + " ▁ " ) ; } public static void main ( String [ ] args ) { int n = 5 ; findSetBits ( n ) ; } }

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