dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
class FindSmallestInteger { int findSmallest ( int arr [ ] , int n ) { int res = 1 ; for ( int i = 0 ; i < n && arr [ i ] <= res ; i ++ ) res = res + arr [ i ] ; return res ; } public static void main ( String [ ] args ) { FindSmallestInteger small = new FindSmallestInteger ( ) ; int arr1 [ ] = { 1 , 3 , 4 , 5 } ; int n1 = arr1 . length ; System . out . println ( small . findSmallest ( arr1 , n1 ) ) ; int arr2 [ ] = { 1 , 2 , 6 , 10 , 11 , 15 } ; int n2 = arr2 . length ; System . out . println ( small . findSmallest ( arr2 , n2 ) ) ; int arr3 [ ] = { 1 , 1 , 1 , 1 } ; int n3 = arr3 . length ; System . out . println ( small . findSmallest ( arr3 , n3 ) ) ; int arr4 [ ] = { 1 , 1 , 3 , 4 } ; int n4 = arr4 . length ; System . out . println ( small . findSmallest ( arr4 , n4 ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: FindSmallestInteger
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static HashSet < Integer > s ; static void countXOR ( int arr [ ] , int comb [ ] , int start , int end , int index , int r ) { if ( index == r ) { int new_xor = 0 ; for ( int j = 0 ; j < r ; j ++ ) { new_xor ^= comb [ j ] ; } s . add ( new_xor ) ; return ; } for ( int i = start ; i <= end && end - i + 1 >= r - index ; i ++ ) { comb [ index ] = arr [ i ] ; countXOR ( arr , comb , i + 1 , end , index + 1 , r ) ; } } static void maxSizeSet ( int arr [ ] , int N ) { for ( int r = 1 ; r <= N ; r ++ ) { int comb [ ] = new int [ r + 1 ] ; countXOR ( arr , comb , 0 , N - 1 , 0 , r ) ; } System . out . println ( s . size ( ) ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 , 5 } ; int N = arr . length ; s = new HashSet < > ( ) ; maxSizeSet ( arr , N ) ; } }

Index/key variables: i, index, j
Accumulator variables: i, j, new_xor, r
Iterator variables: i, j, r
Class/struct names: GFG
Java program:
class GFG { static int maxSubArraySum ( int a [ ] , int size ) { int max_so_far = Integer . MIN_VALUE , max_ending_here = 0 , start = 0 , end = 0 , s = 0 ; for ( int i = 0 ; i < size ; i ++ ) { max_ending_here += a [ i ] ; if ( max_so_far < max_ending_here ) { max_so_far = max_ending_here ; start = s ; end = i ; } if ( max_ending_here < 0 ) { max_ending_here = 0 ; s = i + 1 ; } } return ( end - start + 1 ) ; } public static void main ( String [ ] args ) { int a [ ] = { - 2 , - 3 , 4 , - 1 , - 2 , 1 , 5 , - 3 } ; int n = a . length ; System . out . println ( maxSubArraySum ( a , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, max_ending_here
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { private static int LongSubarrSeq ( int [ ] arr1 , int [ ] arr2 ) { int M = arr1 . length ; int N = arr2 . length ; int maxL = 0 ; int [ ] [ ] DP = new int [ M + 1 ] [ N + 1 ] ; for ( int i = 1 ; i <= M ; i ++ ) { for ( int j = 1 ; j <= N ; j ++ ) { if ( arr1 [ i - 1 ] == arr2 [ j - 1 ] ) { DP [ i ] [ j ] = 1 + DP [ i - 1 ] [ j - 1 ] ; } else { DP [ i ] [ j ] = DP [ i ] [ j - 1 ] ; } } } for ( int i = 1 ; i <= M ; i ++ ) { for ( int j = 1 ; j <= N ; j ++ ) { maxL = Math . max ( maxL , DP [ i ] [ j ] ) ; } } return maxL ; } public static void main ( String [ ] args ) { int [ ] arr1 = { 4 , 2 , 3 , 1 , 5 , 6 } ; int [ ] arr2 = { 3 , 1 , 4 , 6 , 5 , 2 } ; System . out . println ( LongSubarrSeq ( arr1 , arr2 ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int findMinDiff ( int [ ] arr , int n ) { int diff = Integer . MAX_VALUE ; for ( int i = 0 ; i < n - 1 ; i ++ ) for ( int j = i + 1 ; j < n ; j ++ ) if ( Math . abs ( ( arr [ i ] - arr [ j ] ) ) < diff ) diff = Math . abs ( ( arr [ i ] - arr [ j ] ) ) ; return diff ; } public static void main ( String [ ] args ) { int arr [ ] = new int [ ] { 1 , 5 , 3 , 19 , 18 , 25 } ; System . out . println ( " Minimum ▁ difference ▁ is ▁ " + findMinDiff ( arr , arr . length ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int findLongestSubstring ( int posA , int posB , String A , String B , int canSkip , int n , int dp [ ] [ ] [ ] ) { if ( posA >= n posB >= n ) { return 0 ; } if ( dp [ posA ] [ posB ] [ canSkip ] != - 1 ) { return dp [ posA ] [ posB ] [ canSkip ] ; } int op1 = 0 ; int op2 = 0 ; int op3 = 0 ; if ( A . charAt ( posA ) == B . charAt ( posB ) ) { op1 = 1 + findLongestSubstring ( posA + 1 , posB + 1 , A , B , 0 , n , dp ) ; } if ( canSkip == 1 ) { op2 = findLongestSubstring ( posA + 1 , posB , A , B , canSkip , n , dp ) ; } op3 = findLongestSubstring ( posA , posB + 1 , A , B , canSkip , n , dp ) ; return dp [ posA ] [ posB ] [ canSkip ] = Math . max ( op1 , Math . max ( op2 , op3 ) ) ; } static void minOperations ( String A , String B , int N ) { int [ ] [ ] [ ] dp = new int [ N ] [ N ] [ 2 ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { for ( int k = 0 ; k < 2 ; k ++ ) { dp [ i ] [ j ] [ k ] = - 1 ; } } } System . out . println ( N - findLongestSubstring ( 0 , 0 , A , B , 1 , N , dp ) ) ; } public static void main ( String [ ] args ) { String A = " abab " ; String B = " baba " ; int N = A . length ( ) ; minOperations ( A , B , N ) ; } }

Index/key variables: N, canSkip, i, j, k, posA, posB
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int MOD = 1000000007 ; static int dp [ ] [ ] [ ] = new int [ 5005 ] [ 12 ] [ 12 ] ; static int findCountUtil ( int N , int maxDigit [ ] , int position , int previous , int count ) { if ( position == N ) { return 1 ; } int ans = dp [ position ] [ previous ] [ count ] ; if ( ans != - 1 ) { return ans ; } ans = 0 ; for ( int i = 0 ; i <= 9 ; ++ i ) { if ( count == 0 && previous != i ) { ans = ( ans + ( findCountUtil ( N , maxDigit , position + 1 , i , maxDigit [ i ] - 1 ) ) % MOD ) % MOD ; } else if ( count != 0 ) { ans = ( ans + ( findCountUtil ( N , maxDigit , position + 1 , i , ( previous == i && position != 0 ) ? count - 1 : maxDigit [ i ] - 1 ) ) % MOD ) % MOD ; } } return ans ; } static void findCount ( int N , int maxDigit [ ] ) { int position = 0 ; int previous = 0 ; int count = 1 ; int ans = findCountUtil ( N , maxDigit , position , previous , count ) ; System . out . println ( ans ) ; } public static void main ( String [ ] args ) { int N = 2 ; int [ ] maxDigit = { 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 } ; for ( int [ ] [ ] row : dp ) { for ( int [ ] rowColumn : row ) { Arrays . fill ( rowColumn , - 1 ) ; } } findCount ( N , maxDigit ) ; } }

Index/key variables: count, i, position, previous
Iterator variables: i, row, rowColumn
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { static int findMinDiff ( int [ ] arr , int n ) { Arrays . sort ( arr ) ; int diff = Integer . MAX_VALUE ; for ( int i = 0 ; i < n - 1 ; i ++ ) if ( arr [ i + 1 ] - arr [ i ] < diff ) diff = arr [ i + 1 ] - arr [ i ] ; return diff ; } public static void main ( String [ ] args ) { int arr [ ] = new int [ ] { 1 , 5 , 3 , 19 , 18 , 25 } ; System . out . println ( " Minimum ▁ difference ▁ is ▁ " + findMinDiff ( arr , arr . length ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . lang . * ; class GFG { public static void main ( String [ ] args ) { int a = 2 , b = 10 ; int size = Math . abs ( b - a ) + 1 ; int array [ ] = new int [ size ] ; for ( int i = a ; i <= b ; i ++ ) if ( i % 2 == 0 i % 5 == 0 ) array [ i - a ] = 1 ; System . out . println ( " MULTIPLES ▁ of ▁ 2" + " ▁ and ▁ 5 : " ) ; for ( int i = a ; i <= b ; i ++ ) if ( array [ i - a ] == 1 ) System . out . printf ( i + " ▁ " ) ; } }

Index/key variables: size
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int max ( int l , int r ) { return ( l > r ? l : r ) ; } static class Node { int data ; Node left , right ; } ; static class INT { int v ; INT ( int a ) { v = a ; } } static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = node . right = null ; return node ; } static void print ( Node root ) { if ( root != null ) { print ( root . left ) ; System . out . print ( root . data + " ▁ " ) ; print ( root . right ) ; } } static Node pruneUtil ( Node root , int k , INT sum ) { if ( root == null ) return null ; INT lsum = new INT ( sum . v + ( root . data ) ) ; INT rsum = new INT ( lsum . v ) ; root . left = pruneUtil ( root . left , k , lsum ) ; root . right = pruneUtil ( root . right , k , rsum ) ; sum . v = max ( lsum . v , rsum . v ) ; if ( sum . v < k ) { root = null ; } return root ; } static Node prune ( Node root , int k ) { INT sum = new INT ( 0 ) ; return pruneUtil ( root , k , sum ) ; } public static void main ( String args [ ] ) { int k = 45 ; Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 5 ) ; root . right . left = newNode ( 6 ) ; root . right . right = newNode ( 7 ) ; root . left . left . left = newNode ( 8 ) ; root . left . left . right = newNode ( 9 ) ; root . left . right . left = newNode ( 12 ) ; root . right . right . left = newNode ( 10 ) ; root . right . right . left . right = newNode ( 11 ) ; root . left . left . right . left = newNode ( 13 ) ; root . left . left . right . right = newNode ( 14 ) ; root . left . left . right . right . left = newNode ( 15 ) ; System . out . println ( "Tree before truncationNEW_LINE");  print ( root ) ; root = prune ( root , k ) ; System . out . println ( " Tree after truncation ");  print ( root ) ; } }

Class/struct names: GFG, INT, Node
Java program:
class Node { int key ; Node left , right ; public Node ( int item ) { key = item ; left = right = null ; } } class BinaryTree { Node root ; BinaryTree ( ) { root = null ; } void printPostorder ( Node node ) { if ( node == null ) return ; printPostorder ( node . left ) ; printPostorder ( node . right ) ; System . out . print ( node . key + " ▁ " ) ; } void printInorder ( Node node ) { if ( node == null ) return ; printInorder ( node . left ) ; System . out . print ( node . key + " ▁ " ) ; printInorder ( node . right ) ; } void printPreorder ( Node node ) { if ( node == null ) return ; System . out . print ( node . key + " ▁ " ) ; printPreorder ( node . left ) ; printPreorder ( node . right ) ; } void printPostorder ( ) { printPostorder ( root ) ; } void printInorder ( ) { printInorder ( root ) ; } void printPreorder ( ) { printPreorder ( root ) ; } public static void main ( String [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; System . out . println ( " Preorder ▁ traversal ▁ of ▁ binary ▁ tree ▁ is ▁ " ) ; tree . printPreorder ( ) ; System . out . println ( " Inorder traversal of binary tree is "); tree . printInorder ( ) ; System . out . println ( " Postorder traversal of binary tree is "); tree . printPostorder ( ) ; } }

Class/struct names: BinaryTree, Node
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void swapEvenOdd ( int arr [ ] , int N ) { Stack < int [ ] > stack = new Stack < > ( ) ; stack . push ( new int [ ] { 0 , arr [ 0 ] } ) ; for ( int i = 1 ; i < N ; i ++ ) { if ( ! stack . isEmpty ( ) ) { if ( arr [ i ] % 2 != stack . peek ( ) [ 1 ] % 2 ) { int pop [ ] = stack . pop ( ) ; int index = pop [ 0 ] , val = pop [ 1 ] ; arr [ index ] = arr [ i ] ; arr [ i ] = val ; } else stack . push ( new int [ ] { i , arr [ i ] } ) ; } else stack . push ( new int [ ] { i , arr [ i ] } ) ; } for ( int i = 0 ; i < N ; i ++ ) System . out . print ( arr [ i ] + " ▁ " ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 3 , 2 , 4 } ; int N = arr . length ; swapEvenOdd ( arr , N ) ; } }

Index/key variables: i, index
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static final int M = 100 ; static int mxSubSum ( int i , int [ ] arr , int j , int dp [ ] [ ] ) { if ( i == 0 ) { return dp [ i ] [ j ] = Math . max ( 0 , arr [ i ] ) ; } if ( dp [ i ] [ j ] != - 1 ) { return dp [ i ] [ j ] ; } int X = Math . max ( 0 , arr [ i ] + mxSubSum ( i - 1 , arr , j , dp ) ) ; if ( j == 0 ) { return dp [ i ] [ j ] = X ; } int Y = mxSubSum ( i - 1 , arr , j - 1 , dp ) ; return dp [ i ] [ j ] = Math . max ( X , Y ) ; } static int MaximumSubarraySum ( int n , int [ ] arr , int k ) { int [ ] [ ] dp = new int [ M ] [ M ] ; for ( int i = 0 ; i < M ; i ++ ) for ( int j = 0 ; j < M ; j ++ ) dp [ i ] [ j ] = - 1 ; mxSubSum ( n - 1 , arr , k , dp ) ; int res = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j <= k ; j ++ ) { res = Math . max ( res , dp [ i ] [ j ] ) ; } } if ( Arrays . stream ( arr ) . max ( ) . getAsInt ( ) < 0 ) { res = Arrays . stream ( arr ) . max ( ) . getAsInt ( ) ; } return res ; } public static void main ( String [ ] args ) { int arr [ ] = { - 2 , 1 , 3 , - 2 , 4 , - 7 , 20 } ; int K = 1 ; int N = arr . length ; System . out . print ( MaximumSubarraySum ( N , arr , K ) + "NEW_LINE"); } }

Index/key variables: M, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { private static boolean [ ] prime ; private static void sieve ( int n ) { prime = new boolean [ n + 1 ] ; Arrays . fill ( prime , true ) ; for ( int p = 2 ; p * p <= n ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i <= n ; i += p ) prime [ i ] = false ; } } } private static int MinWays ( int [ ] [ ] a , int n , int m ) { int [ ] dp = new int [ 1 << m ] ; Arrays . fill ( dp , n + 1 ) ; for ( int i = 0 ; i < a . length ; i ++ ) { int bitmask = BitMask ( a [ i ] ) ; for ( int j = ( 1 << m ) - 1 ; j >= 0 ; j -- ) { if ( dp [ j ] != n + 1 ) { dp [ j bitmask ] = Math . min ( dp [ j bitmask ] , dp [ j ] + 1 ) ; } } dp [ bitmask ] = 1 ; } return ( dp [ ( 1 << m ) - 1 ] - 1 ) == ( n + 1 ) ? - 1 : ( dp [ ( 1 << m ) - 1 ] - 1 ) ; } private static int BitMask ( int [ ] a ) { int bitmask = 0 ; for ( int i = 0 ; i < a . length ; i ++ ) { if ( prime [ a [ i ] ] ) { bitmask |= ( 1 << i ) ; } } return bitmask ; } public static void main ( String [ ] args ) { int [ ] [ ] mat = { { 4 , 6 , 5 , 8 } , { 2 , 9 , 12 , 14 } , { 32 , 7 , 18 , 16 } , { 12 , 4 , 35 , 17 } } ; int m = mat [ 0 ] . length ; int n = mat . length ; int max = 10000 ; sieve ( max ) ; System . out . println ( MinWays ( mat , n , m ) ) ; } }

Index/key variables: bitmask, i, j, p
Accumulator variables: bitmask, i, j, p
Iterator variables: i, j, p
Class/struct names: GFG
Java program:
import java . util . * ; import java . io . * ; class GFG { static int INF = 10000 ; static void minCost ( int arr [ ] , int n ) { Arrays . sort ( arr ) ; int m = 2 * n ; int cost [ ] [ ] = new int [ n + 1 ] [ m + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) { for ( int j = 0 ; j <= m ; j ++ ) { cost [ i ] [ j ] = INF ; } } cost [ 0 ] [ 0 ] = 0 ; int prev = 0 ; for ( int i = 1 ; i <= n ; i ++ ) { prev = cost [ i - 1 ] [ 0 ] ; for ( int j = 1 ; j <= m ; j ++ ) { cost [ i ] [ j ] = Math . min ( cost [ i ] [ j ] , prev + Math . abs ( j - arr [ i - 1 ] ) ) ; prev = Math . min ( prev , cost [ i - 1 ] [ j ] ) ; } } int minCost = INF ; for ( int j = 1 ; j <= m ; j ++ ) { minCost = Math . min ( minCost , cost [ n ] [ j ] ) ; } System . out . print ( minCost ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 2 , 4 , 4 , 5 , 2 } ; int N = arr . length ; minCost ( arr , 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 . * ; class GFG { static boolean checkbit ( int array [ ] , int index ) { int val = array [ index >> 5 ] & ( 1 << ( index & 31 ) ) ; if ( val == 0 ) return false ; return true ; } static void setbit ( int array [ ] , int index ) { array [ index >> 5 ] |= ( 1 << ( index & 31 ) ) ; } public static void main ( String args [ ] ) { int a = 2 , b = 10 ; int size = Math . abs ( b - a ) ; size = ( int ) Math . ceil ( ( double ) size / 32 ) ; int [ ] array = new int [ size ] ; for ( int i = a ; i <= b ; i ++ ) if ( i % 2 == 0 i % 5 == 0 ) setbit ( array , i - a ) ; System . out . println ( " MULTIPLES ▁ of ▁ 2 ▁ and ▁ 5 : " ) ; for ( int i = a ; i <= b ; i ++ ) if ( checkbit ( array , i - a ) ) System . out . print ( i + " ▁ " ) ; } }

Index/key variables: size
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class Test { static int arr1 [ ] = new int [ ] { 0 , 1 , 0 , 1 , 1 , 1 , 1 } ; static int arr2 [ ] = new int [ ] { 1 , 1 , 1 , 1 , 1 , 0 , 1 } ; static int longestCommonSum ( int n ) { int maxLen = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int sum1 = 0 , sum2 = 0 ; for ( int j = i ; j < n ; j ++ ) { sum1 += arr1 [ j ] ; sum2 += arr2 [ j ] ; if ( sum1 == sum2 ) { int len = j - i + 1 ; if ( len > maxLen ) maxLen = len ; } } } return maxLen ; } public static void main ( String [ ] args ) { System . out . print ( " Length ▁ of ▁ the ▁ longest ▁ common ▁ span ▁ with ▁ same ▁ sum ▁ is ▁ " ) ; System . out . println ( longestCommonSum ( arr1 . length ) ) ; } }

Index/key variables: j
Accumulator variables: i, j, sum1, sum2
Iterator variables: i, j
Class/struct names: Test
Java program:
import java . util . * ; class GFG { static int findNumberOfLIS ( int [ ] nums ) { if ( nums . length == 0 ) return 0 ; int n = nums . length ; int [ ] dp_l = new int [ n ] ; Arrays . fill ( dp_l , 1 ) ; int [ ] dp_c = new int [ n ] ; Arrays . fill ( dp_c , 1 ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( nums [ i ] <= nums [ j ] ) continue ; if ( dp_l [ j ] + 1 > dp_l [ i ] ) { dp_l [ i ] = dp_l [ j ] + 1 ; dp_c [ i ] = dp_c [ j ] ; } else if ( dp_l [ j ] + 1 == dp_l [ i ] ) dp_c [ i ] += dp_c [ j ] ; } } int max_length = 0 ; for ( int i : dp_l ) max_length = Math . max ( i , max_length ) ; int count = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( dp_l [ i ] == max_length ) count += dp_c [ i ] ; } return count ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 5 , 4 , 7 } ; System . out . print ( findNumberOfLIS ( arr ) + "NEW_LINE"); } }

Index/key variables: i, j, n
Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static int [ ] [ ] [ ] dp ; static int [ ] KMPArray ; static int m ; private static int findSubsequence ( int [ ] a , int [ ] sequence , int i , int prev , int k ) { if ( k == m ) return Integer . MIN_VALUE ; if ( i == a . length ) return 0 ; if ( prev != - 1 && dp [ i ] [ prev ] [ k ] != - 1 ) { return dp [ i ] [ prev ] [ k ] ; } int include = 0 ; if ( prev == - 1 a [ i ] >= a [ prev ] ) { int k2 = k ; while ( k2 > 0 && a [ i ] != sequence [ k2 ] ) k2 = KMPArray [ k2 - 1 ] ; if ( a [ i ] == sequence [ k2 ] ) k2 ++ ; include = 1 + findSubsequence ( a , sequence , i + 1 , i , k2 ) ; } int ans = Math . max ( include , findSubsequence ( a , sequence , i + 1 , prev , k ) ) ; if ( prev != - 1 ) { dp [ i ] [ prev ] [ k ] = ans ; } return ans ; } private static void fillKMPArray ( int [ ] pattern ) { int j = 0 ; int i = 1 ; KMPArray [ 0 ] = 0 ; while ( i < m ) { if ( pattern [ i ] == pattern [ j ] ) { j ++ ; KMPArray [ i ] = j ; i ++ ; } else { if ( j != 0 ) j = KMPArray [ j - 1 ] ; else { KMPArray [ i ] = j ; i ++ ; } } } } static void printAnswer ( int a [ ] , int sequence [ ] ) { m = sequence . length ; KMPArray = new int [ m ] ; fillKMPArray ( sequence ) ; dp = new int [ a . length ] [ a . length ] [ a . length ] ; for ( int i = 0 ; i < a . length ; i ++ ) for ( int j = 0 ; j < a . length ; j ++ ) Arrays . fill ( dp [ i ] [ j ] , - 1 ) ; int ans = findSubsequence ( a , sequence , 0 , - 1 , 0 ) ; System . out . println ( ( ans < 0 ) ? 0 : ans ) ; } public static void main ( String [ ] args ) throws Exception { int [ ] arr = { 5 , 3 , 9 , 3 , 4 , 7 } ; int [ ] arr1 = { 3 , 4 } ; printAnswer ( arr , arr1 ) ; } }

Index/key variables: i, j, k, k2, m, prev
Accumulator variables: i, j, k2
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class Node { int val ; Node left , right ; } static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . val = data ; temp . left = null ; temp . right = null ; return temp ; } public static boolean checkEvenOddLevel ( Node root ) { if ( root == null ) return true ; Queue < Node > q = new LinkedList < > ( ) ; q . add ( root ) ; int level = 0 ; while ( ! q . isEmpty ( ) ) { ArrayList < Integer > list = new ArrayList < > ( ) ; int size = q . size ( ) ; for ( int i = 0 ; i < size ; i ++ ) { Node node = q . poll ( ) ; list . add ( node . val ) ; if ( node . left != null ) q . add ( node . left ) ; if ( node . right != null ) q . add ( node . right ) ; } if ( level % 2 == 0 ) { for ( int i = 0 ; i < list . size ( ) - 1 ; i ++ ) { if ( list . get ( i + 1 ) > list . get ( i ) ) continue ; return false ; } } else if ( level % 2 == 1 ) { for ( int i = 0 ; i < list . size ( ) - 1 ; i ++ ) { if ( list . get ( i + 1 ) < list . get ( i ) ) continue ; return false ; } } level ++ ; } return true ; } public static void main ( String [ ] args ) { Node root = null ; root = newNode ( 2 ) ; root . left = newNode ( 6 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 7 ) ; root . right . right = newNode ( 11 ) ; root . left . left . left = newNode ( 10 ) ; root . left . left . right = newNode ( 5 ) ; root . left . right . right = newNode ( 1 ) ; if ( checkEvenOddLevel ( root ) ) { System . out . println ( " YES " ) ; } else { System . out . println ( " NO " ) ; } } }

Accumulator variables: i, level
Iterator variables: i
Class/struct names: GFG, Node
Java program:
import java . io . * ; import java . util . * ; class GFG { static int longestCommonSum ( int [ ] arr1 , int [ ] arr2 , int n ) { int [ ] arr = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) arr [ i ] = arr1 [ i ] - arr2 [ i ] ; HashMap < Integer , Integer > hM = new HashMap < > ( ) ; int sum = 0 ; int max_len = 0 ; for ( int i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; if ( sum == 0 ) max_len = i + 1 ; if ( hM . containsKey ( sum ) ) max_len = Math . max ( max_len , i - hM . get ( sum ) ) ; else hM . put ( sum , i ) ; } return max_len ; } public static void main ( String args [ ] ) { int [ ] arr1 = { 0 , 1 , 0 , 1 , 1 , 1 , 1 } ; int [ ] arr2 = { 1 , 1 , 1 , 1 , 1 , 0 , 1 } ; int n = arr1 . length ; System . out . println ( longestCommonSum ( arr1 , arr2 , n ) ) ; } }

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