dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static int maximumXOR ( int arr [ ] , int n , int K ) { K ++ ; int maxXor = Integer . MIN_VALUE ; for ( int i = 0 ; i < ( 1 << n ) ; i ++ ) { if ( Integer . bitCount ( i ) == K ) { int cur_xor = 0 ; for ( int j = 0 ; j < n ; j ++ ) { if ( ( i & ( 1 << j ) ) != 0 ) cur_xor = cur_xor ^ arr [ j ] ; } maxXor = Math . max ( maxXor , cur_xor ) ; } } return maxXor ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 3 , 4 } ; int N = arr . length ; int M = 2 ; System . out . println ( maximumXOR ( arr , N , M ) ) ; } }

Index/key variables: j
Accumulator variables: K, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static void TowerOfHanoi ( int N ) { for ( int x = 1 ; x <= Math . pow ( 2 , N ) - 1 ; x ++ ) { System . out . print ( " Move ▁ from ▁ Rod ▁ " + ( ( x & x - 1 ) % 3 + 1 ) + " ▁ to ▁ Rod ▁ " + ( ( ( x x - 1 ) + 1 ) % 3 + 1 ) + "NEW_LINE"); } } public static void main ( String [ ] args ) { int N = 3 ; TowerOfHanoi ( N ) ; } }

Accumulator variables: x
Iterator variables: x
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static boolean isValid ( int [ ] [ ] board , int i , int j , int K ) { if ( board [ i ] [ j ] <= K ) { return true ; } return false ; } static boolean findPath ( int [ ] [ ] board , int X , int Y , int M , int N , int K ) { if ( X < 0 X == M Y < 0 Y == N ) { return true ; } if ( isValid ( board , X , Y , K ) ) { int board_XY = board [ X ] [ Y ] ; board [ X ] [ Y ] = Integer . MAX_VALUE ; if ( findPath ( board , X + 1 , Y , M , N , K - board_XY ) || findPath ( board , X - 1 , Y , M , N , K - board_XY ) || findPath ( board , X , Y + 1 , M , N , K - board_XY ) || findPath ( board , X , Y - 1 , M , N , K - board_XY ) ) { return true ; } board [ X ] [ Y ] = board_XY ; } return false ; } public static void main ( String [ ] args ) { int [ ] [ ] grid = { { 25 , 5 , 25 , 25 , 25 , 25 } , { 25 , 1 , 1 , 5 , 12 , 25 } , { 25 , 1 , 12 , 0 , 15 , 25 } , { 22 , 1 , 11 , 2 , 19 , 15 } , { 25 , 2 , 2 , 1 , 12 , 15 } , { 25 , 9 , 10 , 1 , 11 , 25 } , { 25 , 25 , 25 , 25 , 25 , 25 } } ; int K = 17 ; int M = grid . length ; int N = grid [ 0 ] . length ; int X = 2 , Y = 3 ; if ( findPath ( grid , X , Y , M , N , K ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Index/key variables: X, Y, i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int isPerfect ( int x ) { int sum_div = 1 ; for ( int i = 2 ; i <= x / 2 ; ++ i ) { if ( x % i == 0 ) { sum_div += i ; } } if ( sum_div == x ) { return 1 ; } else return 0 ; } static void subsetSum ( int arr [ ] , int n ) { long total = 1 << n ; for ( long i = 0 ; i < total ; i ++ ) { int sum = 0 ; for ( int j = 0 ; j < n ; j ++ ) if ( ( i & ( 1 << j ) ) != 0 ) sum += arr [ j ] ; if ( isPerfect ( sum ) != 0 ) { System . out . print ( sum + " ▁ " ) ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 5 , 4 , 6 } ; int N = arr . length ; subsetSum ( arr , N ) ; } }

Index/key variables: j
Accumulator variables: i, j, sum, sum_div
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; public class GFG { static void solve ( int N , int P1 , int P2 , int X , int Move , boolean QuitP1 , boolean QuitP2 ) { if ( N == 0 || ( QuitP1 && QuitP2 ) ) { System . out . println ( " Number ▁ of ▁ pens ▁ remaining " + " ▁ in ▁ the ▁ box : ▁ " + N ) ; System . out . println ( " Number ▁ of ▁ pens ▁ collected " + " ▁ by ▁ P1 : ▁ " + P1 ) ; System . out . println ( " Number ▁ of ▁ pens ▁ collected " + " ▁ by ▁ P2 : ▁ " + P2 ) ; return ; } if ( Move == 0 && QuitP1 == false ) { int req_P1 = ( int ) ( Math . pow ( 2 , X ) ) ; if ( req_P1 <= N ) { P1 += req_P1 ; N -= req_P1 ; } else { QuitP1 = true ; } } else if ( Move == 1 && QuitP2 == false ) { int req_P2 = ( int ) ( Math . pow ( 3 , X ) ) ; if ( req_P2 <= N ) { P2 += req_P2 ; N -= req_P2 ; } else { QuitP2 = true ; } } X ++ ; Move = ( ( Move == 1 ) ? 0 : 1 ) ; solve ( N , P1 , P2 , X , Move , QuitP1 , QuitP2 ) ; } static void PenGame ( int N ) { int P1 = 0 ; int P2 = 0 ; int X = 0 ; int Move = 0 ; boolean QuitP1 = false ; boolean QuitP2 = false ; solve ( N , P1 , P2 , X , Move , QuitP1 , QuitP2 ) ; } public static void main ( String [ ] args ) { int N = 22 ; PenGame ( N ) ; } }

Accumulator variables: N, P1, P2, X
Boolean variables: QuitP1, QuitP2
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; import java . util . stream . Collectors ; class GFG { static void findSub ( List < List < Integer > > res , int sum , int K , int N , List < Integer > temp ) { if ( K == 0 && sum == 0 ) { List < Integer > newList = temp . stream ( ) . collect ( Collectors . toList ( ) ) ; res . add ( newList ) ; return ; } if ( sum <= 0 K <= 0 ) { return ; } for ( int i = 1 ; i <= N ; i ++ ) { temp . add ( i ) ; findSub ( res , sum - i , K - 1 , N , temp ) ; temp . remove ( temp . size ( ) - 1 ) ; } } static void UtilPrintSubsequncesOfKSumN ( int N , int K ) { @ SuppressWarnings ( " unchecked " ) List < List < Integer > > res = new ArrayList ( ) ; @ SuppressWarnings ( " unchecked " ) List < Integer > temp = new ArrayList ( ) ; findSub ( res , N , K , N , temp ) ; int sz = res . size ( ) ; System . out . print ( " { ▁ " ) ; for ( int i = 0 ; i < sz ; i ++ ) { System . out . print ( " { ▁ " ) ; for ( int j = 0 ; j < K ; j ++ ) { if ( j == K - 1 ) System . out . print ( res . get ( i ) . get ( j ) + " ▁ " ) ; else System . out . print ( res . get ( i ) . get ( j ) + " , ▁ " ) ; } if ( i == sz - 1 ) System . out . print ( " } " ) ; else System . out . print ( " } , ▁ " ) ; } System . out . print ( " ▁ } " ) ; } public static void main ( String [ ] args ) { int N = 4 ; int K = 2 ; UtilPrintSubsequncesOfKSumN ( N , K ) ; } }

Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void checkUntil ( int num , int K , int N , Vector < Integer > ans ) { if ( N == 1 ) { ans . add ( num ) ; return ; } if ( ( num % 10 + K ) <= 9 ) checkUntil ( 10 * num + ( num % 10 + K ) , K , N - 1 , ans ) ; if ( K > 0 ) { if ( ( num % 10 - K ) >= 0 ) checkUntil ( 10 * num + num % 10 - K , K , N - 1 , ans ) ; } } static void check ( int K , int N , Vector < Integer > ans ) { for ( int i = 1 ; i <= 9 ; i ++ ) { checkUntil ( i , K , N , ans ) ; } } static void print ( Vector < Integer > ans ) { for ( int i = 0 ; i < ans . size ( ) ; i ++ ) { System . out . print ( ans . get ( i ) + " , ▁ " ) ; } } public static void main ( String [ ] args ) { int N = 4 , K = 8 ; Vector < Integer > ans = new Vector < Integer > ( ) ; ; check ( K , N , ans ) ; print ( ans ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class pair { int first , second ; pair ( int f , int s ) { this . first = f ; this . second = s ; } } static int minSum = Integer . MAX_VALUE ; static void getMinPathSum ( Map < Integer , ArrayList < pair > > graph , boolean [ ] visited , ArrayList < Integer > necessary , int source , int dest , int currSum ) { if ( src == dest ) { boolean flag = true ; for ( int i : necessary ) { if ( ! visited [ i ] ) { flag = false ; break ; } } if ( flag ) minSum = Math . min ( minSum , currSum ) ; return ; } else { visited [ src ] = true ; for ( pair node : graph . get ( src ) ) { if ( ! visited [ node . first ] ) { visited [ node . first ] = true ; getMinPathSum ( graph , visited , necessary , node . first , dest , currSum + node . second ) ; visited [ node . first ] = false ; } } visited [ src ] = false ; } } public static void main ( String [ ] args ) { Map < Integer , ArrayList < pair > > graph = new HashMap < > ( ) ; for ( int i = 0 ; i <= 6 ; i ++ ) graph . put ( i , new ArrayList < pair > ( ) ) ; graph . get ( 0 ) . add ( new pair ( 1 , 2 ) ) ; graph . get ( 0 ) . add ( new pair ( 2 , 3 ) ) ; graph . get ( 0 ) . add ( new pair ( 3 , 2 ) ) ; graph . get ( 1 ) . add ( new pair ( 4 , 4 ) ) ; graph . get ( 1 ) . add ( new pair ( 0 , 1 ) ) ; graph . get ( 2 ) . add ( new pair ( 4 , 5 ) ) ; graph . get ( 2 ) . add ( new pair ( 5 , 6 ) ) ; graph . get ( 3 ) . add ( new pair ( 5 , 7 ) ) ; graph . get ( 3 ) . add ( new pair ( 0 , 1 ) ) ; graph . get ( 4 ) . add ( new pair ( 6 , 4 ) ) ; graph . get ( 5 ) . add ( new pair ( 4 , 2 ) ) ; graph . get ( 6 ) . add ( new pair ( 7 , 11 ) ) ; int n = 7 ; int source = 0 ; int dest = 6 ; boolean [ ] visited = new boolean [ n ] ; ArrayList < Integer > necessary = new ArrayList < > ( Arrays . asList ( 2 , 4 ) ) ; getMinPathSum ( graph , visited , necessary , source , dest , 0 ) ; if ( minSum == Integer . MAX_VALUE ) System . out . println ( - 1 ) ; else System . out . println ( minSum ) ; } }

Index/key variables: i, n, src
Accumulator variables: i
Iterator variables: i, node
Boolean variables: flag
Class/struct names: GFG, pair
Java program:
import java . util . * ; class GFG { static void comb ( int [ ] arr , int len , int r , int ipos , int [ ] op , int opos , int sum ) { if ( opos == r ) { int sum2 = 0 ; for ( int i = 0 ; i < opos ; i ++ ) { sum2 = sum2 + op [ i ] ; } if ( sum == sum2 ) { for ( int i = 0 ; i < opos ; i ++ ) System . out . print ( op [ i ] + " , ▁ " ) ; System . out . println ( ) ; } return ; } if ( ipos < len ) { comb ( arr , len , r , ipos + 1 , op , opos , sum ) ; op [ opos ] = arr [ ipos ] ; comb ( arr , len , r , ipos + 1 , op , opos + 1 , sum ) ; } } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 6 , 8 , 2 , 12 } ; int K = 3 ; int S = 20 ; int N = arr . length ; int op [ ] = new int [ N ] ; comb ( arr , N , K , 0 , op , 0 , S ) ; } }

Index/key variables: N, i, ipos, opos
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int k1 = 0 , k2 = 0 ; static boolean flag = true ; static boolean traverseMatrixDiagonally ( int m [ ] [ ] , int i , int j , int row , int col ) { if ( i >= row j >= col ) { if ( flag ) { int a = k1 ; k1 = k2 ; k2 = a ; flag = ! flag ; k1 ++ ; } else { int a = k1 ; k1 = k2 ; k2 = a ; flag = ! flag ; } System . out . println ( ) ; return false ; } System . out . print ( m [ i ] [ j ] + " ▁ " ) ; if ( traverseMatrixDiagonally ( m , i + 1 , j + 1 , row , col ) ) { return true ; } if ( traverseMatrixDiagonally ( m , k1 , k2 , row , col ) ) { return true ; } return true ; } public static void main ( String [ ] args ) { int mtrx [ ] [ ] = { { 10 , 11 , 12 , 13 , 14 } , { 15 , 16 , 17 , 18 , 19 } , { 20 , 21 , 22 , 23 , 24 } , { 25 , 26 , 27 , 28 , 29 } , { 30 , 31 , 32 , 33 , 34 } } ; traverseMatrixDiagonally ( mtrx , 0 , 0 , 5 , 5 ) ; } }

Index/key variables: i, j
Accumulator variables: k1
Boolean variables: flag
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int n = 5 , m = 7 ; static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static Vector < pair > [ ] g = new Vector [ m ] ; static int [ ] col = new int [ n ] ; static boolean cyc ; static int [ ] res = new int [ m ] ; static void dfs ( int v ) { col [ v ] = 1 ; for ( pair p : g [ v ] ) { int to = p . first , id = p . second ; if ( col [ to ] == 0 ) { dfs ( to ) ; res [ id ] = 1 ; } else if ( col [ to ] == 2 ) { res [ id ] = 1 ; } else { res [ id ] = 2 ; cyc = true ; } } col [ v ] = 2 ; } public static void main ( String [ ] args ) { for ( int i = 0 ; i < m ; i ++ ) g [ i ] = new Vector < pair > ( ) ; g [ 0 ] . add ( new pair ( 1 , 0 ) ) ; g [ 0 ] . add ( new pair ( 2 , 1 ) ) ; g [ 1 ] . add ( new pair ( 2 , 2 ) ) ; g [ 1 ] . add ( new pair ( 3 , 3 ) ) ; g [ 2 ] . add ( new pair ( 3 , 4 ) ) ; g [ 3 ] . add ( new pair ( 4 , 5 ) ) ; g [ 4 ] . add ( new pair ( 2 , 6 ) ) ; for ( int i = 0 ; i < n ; ++ i ) { if ( col [ i ] == 0 ) { dfs ( i ) ; } } System . out . print ( ( cyc ? 2 : 1 ) + "NEW_LINE"); for ( int i = 0 ; i < m ; ++ i ) { System . out . print ( res [ i ] + " ▁ " ) ; } } }

Index/key variables: i, id, m, n, to, v
Accumulator variables: i
Iterator variables: i, p
Boolean variables: cyc
Class/struct names: GFG, pair
Java program:
import java . util . * ; class GFG { public static void sumSubsets ( int set [ ] , int n , int target ) { int x [ ] = new int [ set . length ] ; int j = set . length - 1 ; while ( n > 0 ) { x [ j ] = n % 2 ; n = n / 2 ; j -- ; } int sum = 0 ; for ( int i = 0 ; i < set . length ; i ++ ) if ( x [ i ] == 1 ) sum = sum + set [ i ] ; if ( sum == target ) { System . out . print ( " { " ) ; for ( int i = 0 ; i < set . length ; i ++ ) if ( x [ i ] == 1 ) System . out . print ( set [ i ] + " , ▁ " ) ; System . out . print ( " } , ▁ " ) ; } } public static void findSubsets ( int [ ] arr , int K ) { int x = ( int ) Math . pow ( 2 , arr . length ) ; for ( int i = 1 ; i < x ; i ++ ) sumSubsets ( arr , i , K ) ; } public static void main ( String args [ ] ) { int arr [ ] = { 5 , 10 , 12 , 13 , 15 , 18 } ; int K = 30 ; findSubsets ( arr , K ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int maxN = 10 ; static int [ ] fact = new int [ maxN ] ; static int ncr ( int n , int r ) { return ( fact [ n ] / fact [ r ] ) / fact [ n - r ] ; } static int findSum ( int [ ] arr , int n ) { fact [ 0 ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) fact [ i ] = i * fact [ i - 1 ] ; int mul = 0 ; for ( int i = 0 ; i <= n - 1 ; i ++ ) mul += ( int ) Math . pow ( 2 , i ) * ncr ( n - 1 , i ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) ans += mul * arr [ i ] ; return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 1 } ; int n = arr . length ; System . out . println ( findSum ( arr , n ) ) ; } }

Index/key variables: i, maxN, n, r
Accumulator variables: ans, i, mul
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { static int R = 4 ; static int C = 4 ; static int countPaths ( int maze [ ] [ ] ) { if ( maze [ 0 ] [ 0 ] == - 1 ) return 0 ; for ( int i = 0 ; i < R ; i ++ ) { if ( maze [ i ] [ 0 ] == 0 ) maze [ i ] [ 0 ] = 1 ; else break ; } for ( int i = 1 ; i < C ; i ++ ) { if ( maze [ 0 ] [ i ] == 0 ) maze [ 0 ] [ i ] = 1 ; else break ; } for ( int i = 1 ; i < R ; i ++ ) { for ( int j = 1 ; j < C ; j ++ ) { if ( maze [ i ] [ j ] == - 1 ) continue ; if ( maze [ i - 1 ] [ j ] > 0 ) maze [ i ] [ j ] = ( maze [ i ] [ j ] + maze [ i - 1 ] [ j ] ) ; if ( maze [ i ] [ j - 1 ] > 0 ) maze [ i ] [ j ] = ( maze [ i ] [ j ] + maze [ i ] [ j - 1 ] ) ; } } return ( maze [ R - 1 ] [ C - 1 ] > 0 ) ? maze [ R - 1 ] [ C - 1 ] : 0 ; } static int numberOfPaths ( int m , int n ) { int path = 1 ; for ( int i = n ; i < ( m + n - 1 ) ; i ++ ) { path *= i ; path /= ( i - n + 1 ) ; } return path ; } static int solve ( int maze [ ] [ ] ) { int ans = numberOfPaths ( R , C ) - countPaths ( maze ) ; return ans ; } public static void main ( String [ ] args ) { int maze [ ] [ ] = { { 0 , 0 , 0 , 0 } , { 0 , - 1 , 0 , 0 } , { - 1 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 } } ; System . out . println ( solve ( maze ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, path
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int N = 4 ; static void printSolution ( int sol [ ] [ ] ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { System . out . printf ( " ▁ % d ▁ " , sol [ i ] [ j ] ) ; } System . out . printf ( "NEW_LINE"); } } static boolean isSafe ( int maze [ ] [ ] , int x , int y ) { if ( x >= 0 && x < N && y >= 0 && y < N && maze [ x ] [ y ] != 0 ) { return true ; } return false ; } static boolean solveMaze ( int maze [ ] [ ] ) { int sol [ ] [ ] = { { 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 } } ; if ( solveMazeUtil ( maze , 0 , 0 , sol ) == false ) { System . out . printf ( " Solution ▁ doesn ' t ▁ exist " ) ; return false ; } printSolution ( sol ) ; return true ; } static boolean solveMazeUtil ( int maze [ ] [ ] , int x , int y , int sol [ ] [ ] ) { if ( x == N - 1 && y == N - 1 ) { sol [ x ] [ y ] = 1 ; return true ; } if ( isSafe ( maze , x , y ) == true ) { sol [ x ] [ y ] = 1 ; for ( int i = 1 ; i <= maze [ x ] [ y ] && i < N ; i ++ ) { if ( solveMazeUtil ( maze , x + i , y , sol ) == true ) { return true ; } if ( solveMazeUtil ( maze , x , y + i , sol ) == true ) { return true ; } } sol [ x ] [ y ] = 0 ; return false ; } return false ; } public static void main ( String [ ] args ) { int maze [ ] [ ] = { { 2 , 1 , 0 , 0 } , { 3 , 0 , 0 , 1 } , { 0 , 1 , 0 , 1 } , { 0 , 0 , 0 , 1 } } ; solveMaze ( maze ) ; } }

Index/key variables: i, j, x, y
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static ArrayList < Integer > set = new ArrayList < Integer > ( ) ; static ArrayList < Integer > prime = new ArrayList < Integer > ( ) ; static boolean isPrime ( int x ) { int sqroot = ( int ) Math . sqrt ( x ) ; if ( x == 1 ) return false ; for ( int i = 2 ; i <= sqroot ; i ++ ) if ( x % i == 0 ) return false ; return true ; } static void display ( ) { int length = set . size ( ) ; for ( int i = 0 ; i < length ; i ++ ) System . out . print ( set . get ( i ) + " ▁ " ) ; System . out . println ( ) ; } static void primeSum ( int total , int N , int S , int index ) { if ( total == S && set . size ( ) == N ) { display ( ) ; return ; } if ( total > S || index == prime . size ( ) || set . size ( ) >= N ) return ; set . add ( prime . get ( index ) ) ; primeSum ( total + prime . get ( index ) , N , S , index + 1 ) ; set . remove ( set . size ( ) - 1 ) ; primeSum ( total , N , S , index + 1 ) ; } static void allPrime ( int N , int S , int P ) { for ( int i = P + 1 ; i <= S ; i ++ ) { if ( isPrime ( i ) ) prime . add ( i ) ; } if ( prime . size ( ) < N ) return ; primeSum ( 0 , N , S , 0 ) ; } public static void main ( String args [ ] ) { int S = 54 , N = 2 , P = 3 ; allPrime ( N , S , P ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int num ; static void grayCodeUtil ( Vector < Integer > res , int n ) { if ( n == 0 ) { res . add ( num ) ; return ; } grayCodeUtil ( res , n - 1 ) ; num = num ^ ( 1 << ( n - 1 ) ) ; grayCodeUtil ( res , n - 1 ) ; } static Vector < Integer > grayCodes ( int n ) { Vector < Integer > res = new Vector < Integer > ( ) ; num = 0 ; grayCodeUtil ( res , n ) ; return res ; } public static void main ( String [ ] args ) { int n = 3 ; Vector < Integer > code = grayCodes ( n ) ; for ( int i = 0 ; i < code . size ( ) ; i ++ ) System . out . print ( code . get ( i ) + "NEW_LINE"); } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static boolean isKPartitionPossibleRec ( int arr [ ] , int subsetSum [ ] , boolean taken [ ] , int subset , int K , int N , int curIdx , int limitIdx ) { if ( subsetSum [ curIdx ] == subset ) { if ( curIdx == K - 2 ) return true ; return isKPartitionPossibleRec ( arr , subsetSum , taken , subset , K , N , curIdx + 1 , N - 1 ) ; } for ( int i = limitIdx ; i >= 0 ; i -- ) { if ( taken [ i ] ) continue ; int tmp = subsetSum [ curIdx ] + arr [ i ] ; if ( tmp <= subset ) { taken [ i ] = true ; subsetSum [ curIdx ] += arr [ i ] ; boolean nxt = isKPartitionPossibleRec ( arr , subsetSum , taken , subset , K , N , curIdx , i - 1 ) ; taken [ i ] = false ; subsetSum [ curIdx ] -= arr [ i ] ; if ( nxt ) return true ; } } return false ; } static boolean isKPartitionPossible ( int arr [ ] , int N , int K ) { if ( K == 1 ) return true ; if ( N < K ) return false ; int sum = 0 ; for ( int i = 0 ; i < N ; i ++ ) sum += arr [ i ] ; if ( sum % K != 0 ) return false ; int subset = sum / K ; int [ ] subsetSum = new int [ K ] ; boolean [ ] taken = new boolean [ N ] ; for ( int i = 0 ; i < K ; i ++ ) subsetSum [ i ] = 0 ; for ( int i = 0 ; i < N ; i ++ ) taken [ i ] = false ; subsetSum [ 0 ] = arr [ N - 1 ] ; taken [ N - 1 ] = true ; return isKPartitionPossibleRec ( arr , subsetSum , taken , subset , K , N , 0 , N - 1 ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 1 , 4 , 5 , 3 , 3 } ; int N = arr . length ; int K = 3 ; if ( isKPartitionPossible ( arr , N , K ) ) System . out . println ( " Partitions ▁ into ▁ equal ▁ sum ▁ is ▁ possible . " ) ; else System . out . println ( " Partitions ▁ into ▁ equal ▁ sum ▁ is ▁ not ▁ possible . " ) ; } }

Index/key variables: K, N, curIdx, i
Accumulator variables: i, sum
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static boolean isParenthesis ( char c ) { return ( ( c == ' ( ' ) || ( c == ' ) ' ) ) ; } static boolean isValidString ( String str ) { int cnt = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( str . charAt ( i ) == ' ( ' ) cnt ++ ; else if ( str . charAt ( i ) == ' ) ' ) cnt -- ; if ( cnt < 0 ) return false ; } return ( cnt == 0 ) ; } static void removeInvalidParenthesis ( String str ) { if ( str . isEmpty ( ) ) return ; HashSet < String > visit = new HashSet < String > ( ) ; Queue < String > q = new LinkedList < > ( ) ; String temp ; boolean level = false ; q . add ( str ) ; visit . add ( str ) ; while ( ! q . isEmpty ( ) ) { str = q . peek ( ) ; q . remove ( ) ; if ( isValidString ( str ) ) { System . out . println ( str ) ; level = true ; } if ( level ) continue ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { if ( ! isParenthesis ( str . charAt ( i ) ) ) continue ; temp = str . substring ( 0 , i ) + str . substring ( i + 1 ) ; if ( ! visit . contains ( temp ) ) { q . add ( temp ) ; visit . add ( temp ) ; } } } } public static void main ( String [ ] args ) { String expression = " ( ) ( ) ) ( ) " ; removeInvalidParenthesis ( expression ) ; expression = " ( ) v ) " ; removeInvalidParenthesis ( expression ) ; } }

Accumulator variables: cnt, i
Iterator variables: i
Boolean variables: level
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int N = 4 ; static int [ ] ld = new int [ 30 ] ; static int [ ] rd = new int [ 30 ] ; static int [ ] cl = new int [ 30 ] ; static void printSolution ( int board [ ] [ ] ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) System . out . printf ( " ▁ % d ▁ " , board [ i ] [ j ] ) ; System . out . printf ( "NEW_LINE"); } } static boolean solveNQUtil ( int board [ ] [ ] , int col ) { if ( col >= N ) return true ; for ( int i = 0 ; i < N ; i ++ ) { if ( ( ld [ i - col + N - 1 ] != 1 && rd [ i + col ] != 1 ) && cl [ i ] != 1 ) { board [ i ] [ col ] = 1 ; ld [ i - col + N - 1 ] = rd [ i + col ] = cl [ i ] = 1 ; if ( solveNQUtil ( board , col + 1 ) ) return true ; ld [ i - col + N - 1 ] = rd [ i + col ] = cl [ i ] = 0 ; } } return false ; } static boolean solveNQ ( ) { int board [ ] [ ] = { { 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 } , { 0 , 0 , 0 , 0 } } ; if ( solveNQUtil ( board , 0 ) == false ) { System . out . printf ( " Solution ▁ does ▁ not ▁ exist " ) ; return false ; } printSolution ( board ) ; return true ; } public static void main ( String [ ] args ) { solveNQ ( ) ; } }

Index/key variables: col, i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void printPairs ( int a [ ] , int n , int x ) { int i ; int [ ] rem = new int [ x ] ; for ( i = 0 ; i < x ; i ++ ) { rem [ i ] = 0 ; } for ( i = 0 ; i < n ; i ++ ) { if ( a [ i ] < x ) { rem [ a [ i ] % x ] ++ ; } } for ( i = 1 ; i < x / 2 ; i ++ ) { if ( rem [ i ] > 0 && rem [ x - i ] > 0 ) { System . out . print ( " Yes " + "NEW_LINE"); break ; } } if ( i >= x / 2 ) { if ( x % 2 == 0 ) { if ( rem [ x / 2 ] > 1 ) { System . out . print ( " Yes " + "NEW_LINE"); } else { System . out . print ( " No " + "NEW_LINE"); } } else { if ( rem [ x / 2 ] > 0 && rem [ x - x / 2 ] > 0 ) { System . out . print ( " Yes " + "NEW_LINE"); } else { System . out . print ( " No " + "NEW_LINE"); } } } } public static void main ( String [ ] args ) { int A [ ] = { 1 , 4 , 45 , 6 , 10 , 8 } ; int n = 16 ; int arr_size = A . length ; printPairs ( A , arr_size , n ) ; } }

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