dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . * ; class GFG { static int maxLeftSubArraySum ( int a [ ] , int size , int sum [ ] ) { int max_so_far = a [ 0 ] ; int curr_max = a [ 0 ] ; sum [ 0 ] = max_so_far ; for ( int i = 1 ; i < size ; i ++ ) { curr_max = Math . max ( a [ i ] , curr_max + a [ i ] ) ; max_so_far = Math . max ( max_so_far , curr_max ) ; sum [ i ] = max_so_far ; } return max_so_far ; } static int maxRightSubArraySum ( int a [ ] , int n , int sum [ ] ) { int max_so_far = a [ n ] ; int curr_max = a [ n ] ; sum [ n ] = max_so_far ; for ( int i = n - 1 ; i >= 0 ; i -- ) { curr_max = Math . max ( a [ i ] , curr_max + a [ i ] ) ; max_so_far = Math . max ( max_so_far , curr_max ) ; sum [ i ] = max_so_far ; } return max_so_far ; } static int findMaxAbsDiff ( int arr [ ] , int n ) { int leftMax [ ] = new int [ n ] ; maxLeftSubArraySum ( arr , n , leftMax ) ; int rightMax [ ] = new int [ n ] ; maxRightSubArraySum ( arr , n - 1 , rightMax ) ; int invertArr [ ] = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) invertArr [ i ] = - arr [ i ] ; int leftMin [ ] = new int [ n ] ; maxLeftSubArraySum ( invertArr , n , leftMin ) ; for ( int i = 0 ; i < n ; i ++ ) leftMin [ i ] = - leftMin [ i ] ; int rightMin [ ] = new int [ n ] ; maxRightSubArraySum ( invertArr , n - 1 , rightMin ) ; for ( int i = 0 ; i < n ; i ++ ) rightMin [ i ] = - rightMin [ i ] ; int result = - 2147483648 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int absValue = Math . max ( Math . abs ( leftMax [ i ] - rightMin [ i + 1 ] ) , Math . abs ( leftMin [ i ] - rightMax [ i + 1 ] ) ) ; if ( absValue > result ) result = absValue ; } return result ; } public static void main ( String [ ] args ) { int a [ ] = { - 2 , - 3 , 4 , - 1 , - 2 , 1 , 5 , - 3 } ; int n = a . length ; System . out . print ( findMaxAbsDiff ( a , n ) ) ; } }

Index/key variables: i, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int M = 4 ; static int N = 4 ; static class Point { int x , y ; public Point ( int x , int y ) { this . x = x ; this . y = y ; } } ; static List < Point > findPath ( int grid [ ] [ ] , int mat [ ] [ ] , int i , int j ) { List < Point > path = new LinkedList < > ( ) ; Point pt = new Point ( i , j ) ; path . add ( 0 , pt ) ; while ( grid [ i ] [ j ] != 0 ) { if ( i > 0 && grid [ i ] [ j ] - 1 == grid [ i - 1 ] [ j ] ) { pt = new Point ( i - 1 , j ) ; path . add ( 0 , pt ) ; i -- ; } else if ( j > 0 && grid [ i ] [ j ] - 1 == grid [ i ] [ j - 1 ] ) { pt = new Point ( i , j - 1 ) ; path . add ( 0 , pt ) ; j -- ; } } return path ; } static void findSnakeSequence ( int mat [ ] [ ] ) { int [ ] [ ] lookup = new int [ M ] [ N ] ; int max_len = 0 ; int max_row = 0 ; int max_col = 0 ; for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { if ( i != 0 j != 0 ) { if ( i > 0 && Math . abs ( mat [ i - 1 ] [ j ] - mat [ i ] [ j ] ) == 1 ) { lookup [ i ] [ j ] = Math . max ( lookup [ i ] [ j ] , lookup [ i - 1 ] [ j ] + 1 ) ; if ( max_len < lookup [ i ] [ j ] ) { max_len = lookup [ i ] [ j ] ; max_row = i ; max_col = j ; } } if ( j > 0 && Math . abs ( mat [ i ] [ j - 1 ] - mat [ i ] [ j ] ) == 1 ) { lookup [ i ] [ j ] = Math . max ( lookup [ i ] [ j ] , lookup [ i ] [ j - 1 ] + 1 ) ; if ( max_len < lookup [ i ] [ j ] ) { max_len = lookup [ i ] [ j ] ; max_row = i ; max_col = j ; } } } } } System . out . print ( " Maximum ▁ length ▁ of ▁ Snake ▁ " + " sequence ▁ is : ▁ " + max_len + "NEW_LINE"); List < Point > path = findPath ( lookup , mat , max_row , max_col ) ; System . out . print ( " Snake ▁ sequence ▁ is : " ) ; for ( Point it : path ) System . out . print ( " " ▁ + ▁ mat [ it . x ] [ it . y ] ▁ + ▁ " ( " ▁ + ▁ it . x ▁ + ▁ " , " ▁ + ▁ it . y ▁ + ▁ " ) "); } public static void main ( String [ ] args ) { int mat [ ] [ ] = { { 9 , 6 , 5 , 2 } , { 8 , 7 , 6 , 5 } , { 7 , 3 , 1 , 6 } , { 1 , 1 , 1 , 7 } } ; findSnakeSequence ( mat ) ; } }

Index/key variables: M, N, i, j
Accumulator variables: i, j
Iterator variables: i, it, j
Class/struct names: GFG, Point
Java program:
class GFG { static int countWays ( int p , int q , int r , int last ) { if ( p < 0 q < 0 r < 0 ) return 0 ; if ( p == 1 && q == 0 && r == 0 && last == 0 ) return 1 ; if ( p == 0 && q == 1 && r == 0 && last == 1 ) return 1 ; if ( p == 0 && q == 0 && r == 1 && last == 2 ) return 1 ; if ( last == 0 ) return countWays ( p - 1 , q , r , 1 ) + countWays ( p - 1 , q , r , 2 ) ; if ( last == 1 ) return countWays ( p , q - 1 , r , 0 ) + countWays ( p , q - 1 , r , 2 ) ; if ( last == 2 ) return countWays ( p , q , r - 1 , 0 ) + countWays ( p , q , r - 1 , 1 ) ; return 0 ; } static int countUtil ( int p , int q , int r ) { } public static void main ( String [ ] args ) { int p = 1 , q = 1 , r = 1 ; System . out . print ( countUtil ( p , q , r ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { public static int findMinRec ( int arr [ ] , int i , int sumCalculated , int sumTotal ) { if ( i == 0 ) return Math . abs ( ( sumTotal - sumCalculated ) - sumCalculated ) ; return Math . min ( findMinRec ( arr , i - 1 , sumCalculated + arr [ i - 1 ] , sumTotal ) , findMinRec ( arr , i - 1 , sumCalculated , sumTotal ) ) ; } public static int findMin ( int arr [ ] , int n ) { int sumTotal = 0 ; for ( int i = 0 ; i < n ; i ++ ) sumTotal += arr [ i ] ; return findMinRec ( arr , n , 0 , sumTotal ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 1 , 4 , 2 , 2 , 1 } ; int n = arr . length ; System . out . print ( " The ▁ minimum ▁ difference " + " ▁ between ▁ two ▁ sets ▁ is ▁ " + findMin ( arr , n ) ) ; } }

Index/key variables: i
Accumulator variables: i, sumTotal
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int minDifference ( int arr [ ] , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; int y = sum / 2 + 1 ; boolean dp [ ] = new boolean [ y ] , dd [ ] = new boolean [ y ] ; for ( int i = 0 ; i < y ; i ++ ) { dp [ i ] = dd [ i ] = false ; } dd [ 0 ] = true ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j + arr [ i ] < y ; j ++ ) { if ( dp [ j ] ) dd [ j + arr [ i ] ] = true ; } for ( int j = 0 ; j < y ; j ++ ) { if ( dd [ j ] ) dp [ j ] = true ; } } for ( int i = y - 1 ; i >= 0 ; i -- ) { if ( dp [ i ] ) return ( sum - 2 * i ) ; } return 0 ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 6 , 11 , 5 } ; int n = arr . length ; System . out . print ( " The ▁ Minimum ▁ difference ▁ of ▁ 2 ▁ sets ▁ is ▁ " + minDifference ( arr , n ) + 'NEW_LINE'); } }

Index/key variables: i, j, y
Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { public static int countP ( int n , int k ) { if ( n == 0 k == 0 k > n ) return 0 ; if ( k == 1 k == n ) return 1 ; return ( k * countP ( n - 1 , k ) + countP ( n - 1 , k - 1 ) ) ; } public static void main ( String args [ ] ) { System . out . println ( countP ( 3 , 2 ) ) ; } }

Class/struct names: GFG
Java program:
class GFG { static int countP ( int n , int k ) { int [ ] [ ] dp = new int [ n + 1 ] [ k + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) dp [ i ] [ 0 ] = 0 ; for ( int i = 0 ; i <= k ; i ++ ) dp [ 0 ] [ k ] = 0 ; for ( int i = 1 ; i <= n ; i ++ ) for ( int j = 1 ; j <= k ; j ++ ) if ( j == 1 i == j ) dp [ i ] [ j ] = 1 ; else dp [ i ] [ j ] = j * dp [ i - 1 ] [ j ] + dp [ i - 1 ] [ j - 1 ] ; return dp [ n ] [ k ] ; } public static void main ( String [ ] args ) { System . out . println ( countP ( 5 , 2 ) ) ; } }

Index/key variables: i, j, k, n
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int printCountRec ( int dist ) { if ( dist < 0 ) return 0 ; if ( dist == 0 ) return 1 ; return printCountRec ( dist - 1 ) + printCountRec ( dist - 2 ) + printCountRec ( dist - 3 ) ; } public static void main ( String [ ] args ) { int dist = 4 ; System . out . println ( printCountRec ( dist ) ) ; } }

Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int printCountDP ( int dist ) { int [ ] ways = new int [ 3 ] ; int n = dist ; ways [ 0 ] = 1 ; ways [ 1 ] = 1 ; ways [ 2 ] = 2 ; for ( int i = 3 ; i <= n ; i ++ ) ways [ i % 3 ] = ways [ ( i - 1 ) % 3 ] + ways [ ( i - 2 ) % 3 ] + ways [ ( i - 3 ) % 3 ] ; return ways [ n % 3 ] ; } public static void main ( String arg [ ] ) { int dist = 4 ; System . out . print ( printCountDP ( dist ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int countNumbersWith4 ( int n ) { int result = 0 ; for ( int x = 1 ; x <= n ; x ++ ) result += has4 ( x ) ? 1 : 0 ; return result ; } static boolean has4 ( int x ) { while ( x != 0 ) { if ( x % 10 == 4 ) return true ; x = x / 10 ; } return false ; } public static void main ( String args [ ] ) { int n = 328 ; System . out . println ( " Count ▁ of ▁ numbers ▁ from ▁ 1 ▁ to ▁ " + " ▁ that ▁ have ▁ 4 ▁ as ▁ a ▁ a ▁ digit ▁ is ▁ " + countNumbersWith4 ( n ) ) ; } }

Accumulator variables: result, x
Iterator variables: x
Class/struct names: GFG
Java program:
class GFG { static int countNumbersWith4 ( int n ) { if ( n < 4 ) return 0 ; int d = ( int ) Math . log10 ( n ) ; int [ ] a = new int [ d + 2 ] ; a [ 0 ] = 0 ; a [ 1 ] = 1 ; for ( int i = 2 ; i <= d ; i ++ ) a [ i ] = a [ i - 1 ] * 9 + ( int ) Math . ceil ( Math . pow ( 10 , i - 1 ) ) ; int p = ( int ) Math . ceil ( Math . pow ( 10 , d ) ) ; int msd = n / p ; if ( msd == 4 ) return ( msd ) * a [ d ] + ( n % p ) + 1 ; if ( msd > 4 ) return ( msd - 1 ) * a [ d ] + p + countNumbersWith4 ( n % p ) ; return ( msd ) * a [ d ] + countNumbersWith4 ( n % p ) ; } public static void main ( String [ ] args ) { int n = 328 ; System . out . println ( " Count ▁ of ▁ numbers ▁ from ▁ 1 ▁ to ▁ " + n + " ▁ that ▁ have ▁ 4 ▁ as ▁ a ▁ digit ▁ is ▁ " + countNumbersWith4 ( n ) ) ; } }

Index/key variables: d, i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int minRemovalsDP ( int arr [ ] , int n ) { int longest_start = - 1 , longest_end = 0 ; for ( int start = 0 ; start < n ; start ++ ) { int min = Integer . MAX_VALUE , max = Integer . MIN_VALUE ; for ( int end = start ; end < n ; end ++ ) { int val = arr [ end ] ; if ( val < min ) { min = val ; } if ( val > max ) { max = val ; } if ( 2 * min <= max ) { break ; } if ( end - start > longest_end - longest_start longest_start == - 1 ) { longest_start = start ; longest_end = end ; } } } if ( longest_start == - 1 ) { return n ; } return ( n - ( longest_end - longest_start + 1 ) ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 5 , 100 , 9 , 10 , 11 , 12 , 15 , 200 } ; int n = arr . length ; System . out . println ( minRemovalsDP ( arr , n ) ) ; } }

Index/key variables: end
Accumulator variables: end, start
Iterator variables: end, start
Class/struct names: GFG
Java program:
static boolean arithmeticThree ( int set [ ] , int n ) { for ( int j = 1 ; j < n - 1 ; j ++ ) { int i = j - 1 , k = j + 1 ; while ( i >= 0 && k <= n - 1 ) { if ( set [ i ] + set [ k ] == 2 * set [ j ] ) return true ; ( set [ i ] + set [ k ] < 2 * set [ j ] ) ? k ++ : i -- ; } } return false ; }

Index/key variables: i, j, k
Accumulator variables: i, j, k
Iterator variables: j
Java program:
import java . io . * ; class GFG { static int optimalStrategyOfGame ( int arr [ ] , int n ) { int table [ ] [ ] = new int [ n ] [ n ] ; int gap , i , j , x , y , z ; for ( gap = 0 ; gap < n ; ++ gap ) { for ( i = 0 , j = gap ; j < n ; ++ i , ++ j ) { x = ( ( i + 2 ) <= j ) ? table [ i + 2 ] [ j ] : 0 ; y = ( ( i + 1 ) <= ( j - 1 ) ) ? table [ i + 1 ] [ j - 1 ] : 0 ; z = ( i <= ( j - 2 ) ) ? table [ i ] [ j - 2 ] : 0 ; table [ i ] [ j ] = Math . max ( arr [ i ] + Math . min ( x , y ) , arr [ j ] + Math . min ( y , z ) ) ; } } return table [ 0 ] [ n - 1 ] ; } public static void main ( String [ ] args ) { int arr1 [ ] = { 8 , 15 , 3 , 7 } ; int n = arr1 . length ; System . out . println ( " " + optimalStrategyOfGame ( arr1 , n ) ) ; int arr2 [ ] = { 2 , 2 , 2 , 2 } ; n = arr2 . length ; System . out . println ( " " + optimalStrategyOfGame ( arr2 , n ) ) ; int arr3 [ ] = { 20 , 30 , 2 , 2 , 2 , 10 } ; n = arr3 . length ; System . out . println ( " " + optimalStrategyOfGame ( arr3 , n ) ) ; } }

Index/key variables: i, j, n
Iterator variables: gap, i
Class/struct names: GFG
Java program:
class GFG { static int maxSumIS ( int arr [ ] , int n ) { int i , j , max = 0 ; int msis [ ] = new int [ n ] ; for ( i = 0 ; i < n ; i ++ ) msis [ i ] = arr [ i ] ; for ( i = 1 ; i < n ; i ++ ) for ( j = 0 ; j < i ; j ++ ) if ( arr [ i ] > arr [ j ] && msis [ i ] < msis [ j ] + arr [ i ] ) msis [ i ] = msis [ j ] + arr [ i ] ; for ( i = 0 ; i < n ; i ++ ) if ( max < msis [ i ] ) max = msis [ i ] ; return max ; } public static void main ( String args [ ] ) { int arr [ ] = new int [ ] { 1 , 101 , 2 , 3 , 100 , 4 , 5 } ; int n = arr . length ; System . out . println ( " Sum ▁ of ▁ maximum ▁ sum ▁ " + " increasing ▁ subsequence ▁ is ▁ " + maxSumIS ( 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 . * ; class GFG { static int checkArray ( int arr [ ] , int N , int k ) { if ( N < 3 ) return - 1 ; int i , Sum = 0 , temp = 0 ; for ( i = 0 ; i < N ; i ++ ) Sum += arr [ i ] ; int R = ( k * k + k + 1 ) ; if ( Sum % R != 0 ) return 0 ; int Mid = k * ( Sum / R ) ; for ( i = 1 ; i < N - 1 ; i ++ ) { temp += arr [ i - 1 ] ; if ( arr [ i ] == Mid ) { if ( temp == Mid / k ) return i + 1 ; else return 0 ; } } return 0 ; } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 1 , 4 , 20 , 6 , 15 , 9 , 10 } ; int N = arr . length ; int K = 2 ; System . out . println ( checkArray ( arr , N , K ) ) ; } }

Index/key variables: i
Accumulator variables: Sum, i, temp
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void encodeString ( String str ) { String res = " " ; int small [ ] = new int [ 26 ] ; int capital [ ] = new int [ 26 ] ; int num [ ] = new int [ 10 ] ; for ( int i = 0 ; i < 26 ; i ++ ) { small [ i ] = 0 ; capital [ i ] = 0 ; } for ( int i = 0 ; i < 10 ; i ++ ) { num [ i ] = 0 ; } int n = str . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( str . charAt ( i ) >= '0' && str . charAt ( i ) <= '9' ) { num [ str . charAt ( i ) - 48 ] = i ; } else if ( str . charAt ( i ) >= ' a ' && str . charAt ( i ) <= ' z ' ) { small [ str . charAt ( i ) - 97 ] = i ; } else if ( str . charAt ( i ) >= ' A ' && str . charAt ( i ) <= ' Z ' ) { capital [ str . charAt ( i ) - 65 ] = i ; } } for ( int i = 0 ; i < n ; i ++ ) { if ( ( str . charAt ( i ) >= ' a ' && str . charAt ( i ) <= ' z ' ) && small [ str . charAt ( i ) - 97 ] == i ) { int occ = str . charAt ( i ) - 96 ; while ( occ -- > 0 ) { res += str . charAt ( i ) ; } } else if ( ( str . charAt ( i ) >= ' A ' && str . charAt ( i ) <= ' Z ' ) && capital [ str . charAt ( i ) - 65 ] == i ) { int occ = str . charAt ( i ) - 64 ; while ( occ -- > 0 ) { res = res + str . charAt ( i ) ; } } else if ( ( str . charAt ( i ) >= '0' && str . charAt ( i ) <= '9' ) && num [ str . charAt ( i ) - 48 ] == i ) { int occ = str . charAt ( i ) - 48 ; while ( occ -- > 0 ) { res = res + str . charAt ( i ) ; } } else { res = res + str . charAt ( i ) ; } } System . out . print ( res ) ; } public static void main ( String [ ] args ) { String str = " Ea2 , ▁ 0 , ▁ E " ; encodeString ( str ) ; } }

Index/key variables: i
Accumulator variables: i, occ, res
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int minimumPalindromicStrings ( String S ) { int N = S . length ( ) ; int [ ] freq = new int [ 26 ] ; for ( int i = 0 ; i < N ; i ++ ) { freq [ S . charAt ( i ) - ' a ' ] ++ ; } Vector < Integer > oddFreqCharacters = new Vector < Integer > ( ) ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( freq [ i ] % 2 == 1 ) { oddFreqCharacters . add ( i ) ; freq [ i ] -- ; } freq [ i ] /= 2 ; } Vector < String > ans = new Vector < String > ( ) ; if ( oddFreqCharacters . isEmpty ( ) ) { String left = " " ; for ( int i = 0 ; i < 26 ; i ++ ) { for ( int j = 0 ; j < freq [ i ] ; j ++ ) { left += ( char ) ( i + ' a ' ) ; } } String right = left ; right = reverse ( right ) ; ans . add ( left + right ) ; } else { String middle = " " ; int c = oddFreqCharacters . lastElement ( ) ; oddFreqCharacters . remove ( oddFreqCharacters . size ( ) - 1 ) ; middle += ( char ) ( c + ' a ' ) ; String left = " " ; for ( int i = 0 ; i < 26 ; i ++ ) { for ( int j = 0 ; j < freq [ i ] ; j ++ ) { left += ( char ) ( i + ' a ' ) ; } } String right = left ; right = reverse ( right ) ; ans . add ( left + middle + right ) ; while ( ! oddFreqCharacters . isEmpty ( ) ) { c = oddFreqCharacters . lastElement ( ) ; oddFreqCharacters . remove ( oddFreqCharacters . size ( ) - 1 ) ; middle = " " ; middle += ( char ) ( c + ' a ' ) ; ans . add ( middle ) ; } } System . out . print ( " [ " ) ; for ( int i = 0 ; i < ans . size ( ) ; i ++ ) { System . out . print ( ans . get ( i ) ) ; if ( i != ans . size ( ) - 1 ) { System . out . print ( " , ▁ " ) ; } } System . out . print ( " ] " ) ; return 0 ; } static String reverse ( String input ) { char [ ] a = input . toCharArray ( ) ; int l , r = a . length - 1 ; for ( l = 0 ; l < r ; l ++ , r -- ) { char temp = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = temp ; } return String . valueOf ( a ) ; } public static void main ( String [ ] args ) { String S = " geeksforgeeks " ; minimumPalindromicStrings ( S ) ; } }

Index/key variables: i, l, r
Accumulator variables: i, j, l, left, middle, r
Iterator variables: i, j, l
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static void possibleEqualArray ( int A [ ] , int N ) { int [ ] pref = new int [ N ] ; pref [ 0 ] = A [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { pref [ i ] = pref [ i - 1 ] ^ A [ i ] ; } if ( pref [ N - 1 ] == 0 ) { System . out . println ( " YES " ) ; return ; } int cur_xor = 0 ; for ( int i = N - 1 ; i >= 0 ; i -- ) { cur_xor ^= A [ i ] ; for ( int j = 0 ; j < i ; j ++ ) { if ( j != 0 ) { int middle_xor = pref [ j - 1 ] ^ pref [ i - 1 ] ; int left_xor = pref [ j - 1 ] ; int right_xor = cur_xor ; if ( left_xor == middle_xor && middle_xor == right_xor ) { System . out . println ( " YES " ) ; return ; } } } } System . out . println ( " NO " ) ; } public static void main ( String [ ] args ) { int A [ ] = { 0 , 2 , 2 } ; int N = A . length ; possibleEqualArray ( A , N ) ; } }

Index/key variables: N, i
Accumulator variables: cur_xor, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static void GenerateArray ( int N , int X ) { int prev_xor = X ; for ( int i = 1 ; i <= N ; i ++ ) { System . out . print ( i ^ prev_xor ) ; if ( i != N ) { System . out . print ( " ▁ " ) ; } prev_xor = i ; } } public static void main ( String args [ ] ) { int N = 4 , X = 3 ; System . out . print ( " The ▁ generated ▁ array ▁ is ▁ " ) ; GenerateArray ( N , X ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { public static void createGrid ( char [ ] [ ] grid , boolean is1 , int N , int M ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( is1 ) { grid [ i ] [ j ] = '0' ; is1 = false ; } else { grid [ i ] [ j ] = '1' ; is1 = true ; } } if ( M % 2 == 0 ) is1 = ! is1 ; } } public static boolean testGrid ( char [ ] [ ] testGrid , char [ ] [ ] Grid , int N , int M ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( Grid [ i ] [ j ] != ' * ' ) { if ( Grid [ i ] [ j ] != testGrid [ i ] [ j ] ) { return false ; } } } } return true ; } public static void printGrid ( char [ ] [ ] grid , int N , int M ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { System . out . print ( grid [ i ] [ j ] + " ▁ " ) ; } System . out . println ( ) ; } } public static void findPossibleGrid ( int N , int M , char [ ] [ ] grid ) { char [ ] [ ] gridTest1 = new char [ N ] [ 1001 ] ; char [ ] [ ] gridTest2 = new char [ N ] [ 1001 ] ; createGrid ( gridTest1 , true , N , M ) ; createGrid ( gridTest2 , false , N , M ) ; if ( testGrid ( gridTest1 , grid , N , M ) ) { System . out . println ( " Yes " ) ; printGrid ( gridTest1 , N , M ) ; } else if ( testGrid ( gridTest2 , grid , N , M ) ) { System . out . println ( " Yes " ) ; printGrid ( gridTest2 , N , M ) ; } else { System . out . println ( " No " ) ; } } public static void main ( String [ ] args ) { int N = 4 , M = 4 ; char [ ] [ ] grid = { { ' * ' , ' * ' , '1' , '0' } , { ' * ' , ' * ' , ' * ' , ' * ' } , { ' * ' , ' * ' , ' * ' , ' * ' } , { ' * ' , ' * ' , '0' , '1' } } ; findPossibleGrid ( N , M , grid ) ; } }

Index/key variables: N, i, j
Accumulator variables: i, j
Iterator variables: i, j
Boolean variables: is1
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int INF64 = ( int ) 1e10 ; static int N = 200 * 1000 + 13 ; static int n ; static int arr [ ] = new int [ N ] ; static int brr [ ] = new int [ N ] ; static void brute ( int ind , int l , int r ) { if ( ind == n / 2 ) { for ( int i = 0 ; i < ( int ) n ; i ++ ) System . out . print ( brr [ i ] + " ▁ " ) ; System . exit ( 0 ) ; } for ( int i = l ; i <= arr [ ind ] / 2 ; ++ i ) if ( arr [ ind ] - i <= r ) { brr [ ind ] = i ; brr [ n - ind - 1 ] = arr [ ind ] - i ; brute ( ind + 1 , i , arr [ ind ] - i ) ; } } public static void main ( String [ ] args ) { n = 2 ; n *= 2 ; arr [ 0 ] = 5 ; arr [ 1 ] = 6 ; brute ( 0 , 0 , INF64 ) ; } }

Index/key variables: N, i, ind
Accumulator variables: i, n
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int minCount ( int N , int K ) { int SmallestNumber [ ] = new int [ 10 ] ; int MinimumSteps [ ] = new int [ 10 ] ; for ( int i = 0 ; i <= 9 ; i ++ ) { SmallestNumber [ i ] = Integer . MAX_VALUE ; MinimumSteps [ i ] = Integer . MAX_VALUE ; } for ( int i = 1 ; i <= 10 ; i ++ ) { int num = K * i ; SmallestNumber [ num % 10 ] = Math . min ( SmallestNumber [ num % 10 ] , num ) ; MinimumSteps [ num % 10 ] = Math . min ( MinimumSteps [ num % 10 ] , i ) ; } if ( N < SmallestNumber [ N % 10 ] ) { return - 1 ; } else { return MinimumSteps [ N % 10 ] ; } } public static void main ( String [ ] args ) { int N = 42 , K = 7 ; System . out . println ( minCount ( N , K ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int countMinSteps ( int arr [ ] , int N ) { int val = 0 ; int mx = Integer . MIN_VALUE ; for ( int i = 0 ; i < N ; i ++ ) { int curr = arr [ i ] ; mx = Math . max ( mx , curr ) ; val = Math . max ( val , mx - curr ) ; } long res = 0 ; while ( ( 1 << res ) - 1 < val ) { ++ res ; } return ( int ) res ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 7 , 6 , 5 } ; int N = arr . length ; System . out . println ( countMinSteps ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int func2 ( int L , int R , int K ) { if ( R - L >= 2 ) return 1 ; return Math . min ( L , L ^ R ) ; } static int func3 ( int L , int R , int K ) { if ( ( R ^ L ) > L && ( R ^ L ) < R ) return 0 ; return func2 ( L , R , K ) ; } static int func4 ( int L , int R , int K ) { if ( R - L >= 4 ) return 0 ; int minval = L ^ ( L + 1 ) ^ ( L + 2 ) ^ ( L + 3 ) ; return Math . min ( minval , func3 ( L , R , K ) ) ; } static int minimumXor ( int L , int R , int K ) { if ( K > 4 ) return 0 ; else if ( K == 4 ) return func4 ( L , R , K ) ; else if ( K == 3 ) return func3 ( L , R , K ) ; else if ( K == 2 ) return func2 ( L , R , K ) ; else return L ; } public static void main ( String [ ] args ) { int L = 1 , R = 3 , K = 3 ; System . out . println ( minimumXor ( L , R , K ) ) ; } }

Class/struct names: GFG