dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
public class GFG { static int findkey ( int A , int B , int C ) { int ans = 0 ; int cur = 1 ; while ( A > 0 ) { int a = A % 10 ; int b = B % 10 ; int c = C % 10 ; A = A / 10 ; B = B / 10 ; C = C / 10 ; int m = Math . max ( a , Math . max ( c , b ) ) ; ans += cur * m ; cur = cur * 10 ; } return ans ; } public static void main ( String args [ ] ) { int A = 3521 , B = 2452 , C = 1352 ; System . out . println ( findkey ( A , B , C ) ) ; } }

Accumulator variables: ans
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int gcd ( int a , int b ) { return b == 0 ? a : gcd ( b , a % b ) ; } static int distinctGCDs ( int [ ] arr , int N ) { int M = - 1 , ans = 0 ; HashMap < Integer , Integer > Mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { M = Math . max ( M , arr [ i ] ) ; if ( Mp . containsKey ( arr [ i ] ) ) Mp . put ( arr [ i ] , 1 ) ; else Mp . put ( arr [ i ] , 0 ) ; } for ( int i = 1 ; i <= M ; i ++ ) { int currGcd = 0 ; for ( int j = i ; j <= M ; j += i ) { if ( Mp . containsKey ( j ) ) { currGcd = gcd ( currGcd , j ) ; if ( currGcd == i ) { ans ++ ; break ; } } } } return ans ; } public static void main ( String [ ] args ) { int [ ] arr = { 3 , 11 , 14 , 6 , 12 } ; int N = arr . length ; System . out . println ( distinctGCDs ( arr , N ) ) ; } }

Index/key variables: i
Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
public class GFG { static int eggDrop ( int n , int k ) { if ( k == 1 k == 0 ) return k ; if ( n == 1 ) return k ; int min = Integer . MAX_VALUE ; int x , res ; for ( x = 1 ; x <= k ; x ++ ) { res = Math . max ( eggDrop ( n - 1 , x - 1 ) , eggDrop ( n , k - x ) ) ; if ( res < min ) min = res ; } return min + 1 ; } public static void main ( String args [ ] ) { int n = 2 , k = 10 ; System . out . print ( " Minimum ▁ number ▁ of ▁ " + " trials ▁ in ▁ worst ▁ case ▁ with ▁ " + n + " ▁ eggs ▁ and ▁ " + k + " ▁ floors ▁ is ▁ " + eggDrop ( n , k ) ) ; } }

Accumulator variables: x
Iterator variables: x
Class/struct names: GFG
Java program:
import java . io . * ; class GFG { public static void kthDigitFromLast ( int n , int k ) { if ( k <= 0 ) { System . out . println ( - 1 ) ; return ; } while ( ( k - 1 ) > 0 && n > 0 ) { n = n / 10 ; k -- ; } if ( n == 0 ) { System . out . println ( - 1 ) ; } else { System . out . println ( n % 10 ) ; } } public static void main ( String [ ] args ) { int n = 2354 ; int k = 2 ; kthDigitFromLast ( n , k ) ; } }

Accumulator variables: k
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void EditDistDP ( String str1 , String str2 ) { int len1 = str1 . length ( ) ; int len2 = str2 . length ( ) ; int [ ] [ ] DP = new int [ 2 ] [ len1 + 1 ] ; for ( int i = 0 ; i <= len1 ; i ++ ) DP [ 0 ] [ i ] = i ; for ( int i = 1 ; i <= len2 ; i ++ ) { for ( int j = 0 ; j <= len1 ; j ++ ) { if ( j == 0 ) DP [ i % 2 ] [ j ] = i ; else if ( str1 . charAt ( j - 1 ) == str2 . charAt ( i - 1 ) ) { DP [ i % 2 ] [ j ] = DP [ ( i - 1 ) % 2 ] [ j - 1 ] ; } else { DP [ i % 2 ] [ j ] = 1 + Math . min ( DP [ ( i - 1 ) % 2 ] [ j ] , Math . min ( DP [ i % 2 ] [ j - 1 ] , DP [ ( i - 1 ) % 2 ] [ j - 1 ] ) ) ; } } } System . out . print ( DP [ len2 % 2 ] [ len1 ] + "NEW_LINE"); } public static void main ( String [ ] args ) { String str1 = " food " ; String str2 = " money " ; EditDistDP ( str1 , str2 ) ; } }

Index/key variables: i, j, len1
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { static int xorSumOfArray ( int arr [ ] , int n , int k , int count [ ] ) { int sum = 0 ; int p = 1 ; for ( int i = 0 ; i < 31 ; i ++ ) { int val = 0 ; if ( ( k & ( 1 << i ) ) != 0 ) { int not_set = n - count [ i ] ; val = ( ( not_set ) * p ) ; } else { val = ( count [ i ] * p ) ; } sum += val ; p = ( p * 2 ) ; } return sum ; } static void sumOfXors ( int arr [ ] , int n , int queries [ ] , int q ) { int [ ] count = new int [ 32 ] ; Arrays . fill ( count , 0 ) ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < 31 ; j ++ ) { if ( ( arr [ i ] & ( 1 << j ) ) != 0 ) count [ j ] ++ ; } } for ( int i = 0 ; i < q ; i ++ ) { int k = queries [ i ] ; System . out . print ( xorSumOfArray ( arr , n , k , count ) + " ▁ " ) ; } } public static void main ( String args [ ] ) { int arr [ ] = { 5 , 2 , 3 } ; int queries [ ] = { 3 , 8 , 7 } ; int n = arr . length ; int q = queries . length ; sumOfXors ( arr , n , queries , q ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, sum
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static class Node { Node left , right ; int key ; } ; static Node root ; static Node newNode ( int key ) { Node temp = new Node ( ) ; temp . key = key ; temp . left = temp . right = null ; return temp ; } static Node createFactorTree ( Node node_ref , int v ) { ( node_ref ) = newNode ( v ) ; for ( int i = 2 ; i < v / 2 ; i ++ ) { if ( v % i != 0 ) continue ; node_ref . left = createFactorTree ( ( ( node_ref ) . left ) , i ) ; node_ref . right = createFactorTree ( ( ( node_ref ) . right ) , v / i ) ; return node_ref ; } return node_ref ; } static void printLevelOrder ( Node root ) { if ( root == null ) return ; Queue < Node > q = new LinkedList < > ( ) ; q . add ( root ) ; while ( q . isEmpty ( ) == false ) { Node node = q . peek ( ) ; System . out . print ( node . key + " ▁ " ) ; q . remove ( ) ; if ( node . left != null ) q . add ( node . left ) ; if ( node . right != null ) q . add ( node . right ) ; } } public static void main ( String [ ] args ) { root = null ; root = createFactorTree ( root , val ) ; System . out . println ( " Level ▁ order ▁ traversal ▁ of ▁ " + " constructed ▁ factor ▁ tree " ) ; printLevelOrder ( root ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, Node
Java program:
import java . util . * ; class GFG { static final int M = 3 ; static final int N = 3 ; static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static void findHeightMatrixUtil ( int mat [ ] [ ] , int height [ ] [ ] ) { Queue < pair > q = new LinkedList < > ( ) ; int [ ] [ ] vis = new int [ M ] [ N ] ; for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { if ( mat [ i ] [ j ] == 1 ) { q . add ( new pair ( i , j ) ) ; height [ i ] [ j ] = 0 ; vis [ i ] [ j ] = 1 ; } } } while ( q . isEmpty ( ) == false ) { pair k = q . peek ( ) ; q . remove ( ) ; int x = k . first , y = k . second ; if ( x > 0 && vis [ x - 1 ] [ y ] == 0 ) { height [ x - 1 ] [ y ] = height [ x ] [ y ] + 1 ; vis [ x - 1 ] [ y ] = 1 ; q . add ( new pair ( x - 1 , y ) ) ; } if ( y > 0 && vis [ x ] [ y - 1 ] == 0 ) { height [ x ] [ y - 1 ] = height [ x ] [ y ] + 1 ; vis [ x ] [ y - 1 ] = 1 ; q . add ( new pair ( x , y - 1 ) ) ; } if ( x < M - 1 && vis [ x + 1 ] [ y ] == 0 ) { height [ x + 1 ] [ y ] = height [ x ] [ y ] + 1 ; vis [ x + 1 ] [ y ] = 1 ; q . add ( new pair ( x + 1 , y ) ) ; } if ( y < N - 1 && vis [ x ] [ y + 1 ] == 0 ) { height [ x ] [ y + 1 ] = height [ x ] [ y ] + 1 ; vis [ x ] [ y + 1 ] = 1 ; q . add ( new pair ( x , y + 1 ) ) ; } } } static void findHeightMatrix ( int mat [ ] [ ] ) { int [ ] [ ] height = new int [ M ] [ N ] ; findHeightMatrixUtil ( mat , height ) ; for ( int i = 0 ; i < M ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) System . out . print ( height [ i ] [ j ] + " ▁ " ) ; System . out . println ( ) ; } } public static void main ( String [ ] args ) { int mat [ ] [ ] = { { 0 , 0 , 0 } , { 0 , 1 , 0 } , { 0 , 0 , 0 } } ; findHeightMatrix ( mat ) ; } }

Index/key variables: M, N, i, j, x, y
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG, pair
Java program:
import java . util . * ; class GFG { static class Node { Node left , right ; int key ; } ; static Vector < Integer > interNodes = new Vector < Integer > ( ) ; static Node newNode ( int key ) { Node temp = new Node ( ) ; temp . key = key ; temp . left = temp . right = null ; return temp ; } static Node insertNode ( Node node , int key ) { if ( node == null ) return newNode ( key ) ; if ( key < node . key ) node . left = insertNode ( node . left , key ) ; else if ( key > node . key ) node . right = insertNode ( node . right , key ) ; return node ; } static void getIntermediateNodes ( Node root , int node1 , int node2 ) { if ( root == null ) return ; getIntermediateNodes ( root . left , node1 , node2 ) ; if ( root . key <= node2 && root . key >= node1 ) { interNodes . add ( root . key ) ; } getIntermediateNodes ( root . right , node1 , node2 ) ; } static float findMedian ( Node root , int node1 , int node2 ) { getIntermediateNodes ( root , node1 , node2 ) ; int nSize = interNodes . size ( ) ; return ( nSize % 2 == 1 ) ? ( float ) interNodes . get ( nSize / 2 ) : ( float ) ( interNodes . get ( ( nSize - 1 ) / 2 ) + interNodes . get ( nSize / 2 ) ) / 2 ; } public static void main ( String [ ] args ) { Node root = null ; root = insertNode ( root , 8 ) ; insertNode ( root , 3 ) ; insertNode ( root , 1 ) ; insertNode ( root , 6 ) ; insertNode ( root , 4 ) ; insertNode ( root , 11 ) ; insertNode ( root , 15 ) ; System . out . print ( findMedian ( root , 3 , 11 ) ) ; } }

Class/struct names: GFG, Node
Java program:
import java . util . * ; class GFG { static void computeTotient ( int N , int phi [ ] ) { for ( int p = 2 ; p <= N ; p ++ ) { if ( phi [ p ] == p ) { phi [ p ] = p - 1 ; for ( int i = 2 * p ; i <= N ; i += p ) { phi [ i ] = ( phi [ i ] / p ) * ( p - 1 ) ; } } } } static void countPairs ( int N ) { int cnt_type1 = 0 , cnt_type2 = 0 ; int half_N = N / 2 ; cnt_type1 = ( half_N * ( half_N - 1 ) ) / 2 ; int [ ] phi = new int [ N + 1 ] ; for ( int i = 1 ; i <= N ; i ++ ) { phi [ i ] = i ; } computeTotient ( N , phi ) ; for ( int i = ( N / 2 ) + 1 ; i <= N ; i ++ ) cnt_type2 += ( i - phi [ i ] - 1 ) ; System . out . print ( cnt_type1 + cnt_type2 ) ; } public static void main ( String [ ] args ) { int N = 6 ; countPairs ( N ) ; } }

Index/key variables: i, p
Accumulator variables: cnt_type2, i, p
Iterator variables: i, p
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; public class GFG { static int ans = Integer . MAX_VALUE ; static int mini = Integer . MAX_VALUE ; static void findClosestTarget ( int i , int curr , int B [ ] , int M , int K ) { if ( Math . abs ( curr - K ) < mini ) { mini = Math . abs ( curr - K ) ; ans = curr ; } if ( Math . abs ( curr - K ) == mini ) { ans = Math . min ( ans , curr ) ; } if ( i >= M ) return ; findClosestTarget ( i + 1 , curr + B [ i ] , B , M , K ) ; findClosestTarget ( i + 1 , curr + 2 * B [ i ] , B , M , K ) ; findClosestTarget ( i + 1 , curr , B , M , K ) ; } static int findClosest ( int A [ ] , int B [ ] , int N , int M , int K ) { for ( int i = 0 ; i < N ; i ++ ) { findClosestTarget ( 0 , A [ i ] , B , M , K ) ; } return ans ; } public static void main ( String [ ] args ) { int A [ ] = { 2 , 3 } ; int B [ ] = { 4 , 5 , 30 } ; int N = A . length ; int M = B . length ; int K = 18 ; System . out . print ( findClosest ( A , B , N , M , K ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . HashMap ; class GFG { public static void findNode ( HashMap < Integer , Integer > map , int n ) { int [ ] a = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { a [ i ] = map . getOrDefault ( i + 1 , 0 ) ; } int count0 = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == 0 ) { count0 ++ ; } } count0 -= 1 ; if ( count0 <= Math . floor ( ( ( double ) n ) / ( ( double ) 2 ) ) ) { System . out . println ( " Yes " ) ; } else System . out . println ( " No ▁ " ) ; } public static void main ( String [ ] args ) { int N = 3 ; HashMap < Integer , Integer > map = new HashMap < > ( ) ; map . put ( 1 , 0 ) ; map . put ( 2 , 2 ) ; map . put ( 3 , 0 ) ; findNode ( map , N ) ; } }

Index/key variables: i, n
Accumulator variables: count0, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . ArrayList ; import java . util . Collections ; class GFG { static int convert ( ArrayList < Integer > p ) { int ans = 0 ; for ( int i : p ) { ans = ( ans << 1 ) | i ; } return ans ; } static int count ( int num ) { int ans = 0 ; while ( num > 0 ) { ans += num & 1 ; num >>= 1 ; } return ans ; } static void checkGoodMatrix ( int mat [ ] [ ] ) { ArrayList < Integer > P = new ArrayList < Integer > ( ) ; ArrayList < Integer > S = new ArrayList < Integer > ( ) ; ArrayList < Integer > MR = new ArrayList < Integer > ( ) ; ArrayList < Integer > MC = new ArrayList < Integer > ( ) ; for ( int i = 0 ; i < mat . length ; i ++ ) { for ( int j = 0 ; j < mat [ 0 ] . length ; j ++ ) { if ( i == j ) P . add ( mat [ i ] [ j ] ) ; if ( i + j == mat . length - 1 ) S . add ( mat [ i ] [ j ] ) ; if ( i == Math . floor ( ( mat . length - 1 ) / 2 ) ) MR . add ( mat [ i ] [ j ] ) ; if ( j == Math . floor ( ( mat . length - 1 ) / 2 ) ) MC . add ( mat [ i ] [ j ] ) ; } } Collections . reverse ( S ) ; int P0 = convert ( P ) ; int S0 = convert ( S ) ; int MR0 = convert ( MR ) ; int MC0 = convert ( MC ) ; int setBitsPS = count ( ( P0 & S0 ) ) ; int setBitsMM = count ( ( MR0 & MC0 ) ) ; if ( setBitsPS > setBitsMM ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } public static void main ( String [ ] args ) { int mat [ ] [ ] = { { 1 , 0 , 1 } , { 0 , 0 , 1 } , { 0 , 1 , 1 } } ; checkGoodMatrix ( mat ) ; } }

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void assignValues ( int Edges [ ] [ ] , int n ) { ArrayList < ArrayList < Integer > > tree = new ArrayList < > ( ) ; for ( int i = 0 ; i < n + 1 ; i ++ ) tree . add ( new ArrayList < > ( ) ) ; for ( int i = 0 ; i < n - 1 ; i ++ ) { int u = Edges [ i ] [ 0 ] ; int v = Edges [ i ] [ 1 ] ; tree . get ( u ) . add ( v ) ; tree . get ( v ) . add ( u ) ; } boolean [ ] visited = new boolean [ n + 1 ] ; int [ ] answer = new int [ n + 1 ] ; int K = 1 ; Queue < Integer > q = new LinkedList < > ( ) ; q . add ( 1 ) ; answer [ 1 ] = K ; while ( ! q . isEmpty ( ) ) { int node = q . peek ( ) ; q . poll ( ) ; visited [ node ] = true ; K = ( ( answer [ node ] == 1 ) ? 2 : 1 ) ; for ( Integer child : tree . get ( node ) ) { if ( ! visited [ child ] ) { q . add ( child ) ; answer [ child ] = K ; } } } for ( int i = 1 ; i <= n ; i ++ ) { System . out . print ( answer [ i ] + " ▁ " ) ; } } public static void main ( String [ ] args ) { int N = 11 ; int Edges [ ] [ ] = { { 1 , 2 } , { 1 , 3 } , { 1 , 4 } , { 1 , 5 } , { 2 , 6 } , { 2 , 10 } , { 10 , 11 } , { 3 , 7 } , { 4 , 8 } , { 5 , 9 } } ; assignValues ( Edges , N ) ; } }

Index/key variables: child, i, node
Accumulator variables: i
Iterator variables: child, i
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { static int numoffbt ( int arr [ ] , int n ) { int maxvalue = - 2147483647 ; int minvalue = 2147483647 ; for ( int i = 0 ; i < n ; i ++ ) { maxvalue = Math . max ( maxvalue , arr [ i ] ) ; minvalue = Math . min ( minvalue , arr [ i ] ) ; } int mark [ ] = new int [ maxvalue + 2 ] ; int value [ ] = new int [ maxvalue + 2 ] ; Arrays . fill ( mark , 0 ) ; Arrays . fill ( value , 0 ) ; for ( int i = 0 ; i < n ; i ++ ) { mark [ arr [ i ] ] = 1 ; value [ arr [ i ] ] = 1 ; } int ans = 0 ; for ( int i = minvalue ; i <= maxvalue ; i ++ ) { if ( mark [ i ] != 0 ) { for ( int j = i + i ; j <= maxvalue && j / i <= i ; j += i ) { if ( mark [ j ] == 0 ) continue ; value [ j ] = value [ j ] + ( value [ i ] * value [ j / i ] ) ; if ( i != j / i ) value [ j ] = value [ j ] + ( value [ i ] * value [ j / i ] ) ; } } ans += value [ i ] ; } return ans ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 3 , 4 , 6 } ; int n = arr . length ; System . out . print ( numoffbt ( arr , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: ans, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static int limit = 100000 ; static boolean prime [ ] ; static void sieve ( ) { prime = new boolean [ limit + 1 ] ; Arrays . fill ( prime , true ) ; for ( int p = 2 ; p * p <= limit ; p ++ ) { if ( prime [ p ] == true ) { for ( int i = p * p ; i <= limit ; i += p ) prime [ i ] = false ; } } } static int findOperations ( int arr [ ] , int n ) { sieve ( ) ; int minm = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { minm = Math . min ( minm , arr [ i ] ) ; } int val = minm ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == minm + 1 ) { val = minm - 2 ; break ; } } int cnt = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int D = arr [ i ] - val ; if ( D == 0 ) { continue ; } else if ( prime [ D ] == true ) { cnt += 1 ; } else if ( D % 2 == 0 ) { cnt += 2 ; } else { if ( prime [ D - 2 ] == true ) { cnt += 2 ; } else { cnt += 3 ; } } } return cnt ; } public static void main ( String [ ] args ) { int arr [ ] = { 7 , 10 , 4 , 5 } ; int N = 4 ; System . out . println ( findOperations ( arr , N ) ) ; } }

Index/key variables: D, i, p
Accumulator variables: cnt, i, p
Iterator variables: i, p
Class/struct names: GFG
Java program:
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static int calcScore ( ArrayList < Integer > p , int arr [ ] ) { int ans = 0 ; for ( int i = 0 ; i < arr . length ; i ++ ) { ans += ( p . get ( i ) & arr [ i ] ) ; } return ans ; } static int getMaxUtil ( ArrayList < Integer > p , int arr [ ] , int ans , boolean chosen [ ] , int N ) { if ( p . size ( ) == N ) { ans = Math . max ( ans , calcScore ( p , arr ) ) ; return ans ; } for ( int i = 0 ; i < N ; i ++ ) { if ( chosen [ i ] ) { continue ; } chosen [ i ] = true ; p . add ( i ) ; ans = getMaxUtil ( p , arr , ans , chosen , N ) ; chosen [ i ] = false ; p . remove ( p . size ( ) - 1 ) ; } return ans ; } static void getMax ( int arr [ ] , int N ) { int ans = 0 ; boolean chosen [ ] = new boolean [ N ] ; ArrayList < Integer > p = new ArrayList < > ( ) ; int res = getMaxUtil ( p , arr , ans , chosen , N ) ; System . out . println ( res ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 4 , 2 , 3 , 6 } ; int N = arr . length ; getMax ( arr , N ) ; } }

Index/key variables: N, i
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int setBitCount ( int n ) { int ans = 0 ; while ( n != 0 ) { ans += n & 1 ; n >>= 1 ; } return ans ; } static void getSum ( int [ ] arr , int n ) { Map < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; int ans = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int key = setBitCount ( arr [ i ] ) ; if ( mp . containsKey ( key ) ) mp . put ( key , mp . get ( key ) + 1 ) ; else mp . put ( key , 1 ) ; } for ( int i = 0 ; i < n ; i ++ ) { int key = setBitCount ( arr [ i ] ) ; if ( mp . containsKey ( key ) && mp . get ( key ) == 1 ) ans += arr [ i ] ; } System . out . print ( ans ) ; } public static void main ( String args [ ] ) { int [ ] arr = { 8 , 3 , 7 , 5 , 3 } ; int n = arr . length ; getSum ( arr , n ) ; } }

Index/key variables: i
Accumulator variables: ans, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static void findSplit ( int arr [ ] , int N ) { int [ ] sum = new int [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { sum [ i ] = arr [ i ] ; } for ( int i = 1 ; i < N ; i ++ ) { sum [ i ] += sum [ i - 1 ] ; } for ( int l = 1 ; l <= N - 4 ; l ++ ) { for ( int r = l + 2 ; r <= N - 2 ; r ++ ) { int lsum = 0 , rsum = 0 , msum = 0 ; lsum = sum [ l - 1 ] ; msum = sum [ r - 1 ] - sum [ l ] ; rsum = sum [ N - 1 ] - sum [ r ] ; if ( lsum == rsum && rsum == msum ) { System . out . print ( l + " ▁ " + r + "NEW_LINE"); return ; } } } System . out . print ( - 1 + "NEW_LINE"); } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 5 , 12 , 7 , 19 , 4 , 3 } ; int N = arr . length ; findSplit ( arr , N ) ; } }

Index/key variables: N, i, l, r
Accumulator variables: i, l, r
Iterator variables: i, l, r
Class/struct names: GFG
Java program:
public class GFG { static void findSplit ( int [ ] arr , int N ) { int l = 1 , r = N - 2 ; int lsum , msum , rsum ; int sum [ ] = new int [ N ] ; sum [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < N ; i ++ ) { sum [ i ] = sum [ i - 1 ] + arr [ i ] ; } while ( l < r ) { lsum = sum [ l - 1 ] ; msum = sum [ r - 1 ] - sum [ l ] ; rsum = sum [ N - 1 ] - sum [ r ] ; if ( lsum == msum && msum == rsum ) { System . out . println ( l + " ▁ " + r ) ; return ; } if ( lsum < rsum ) l ++ ; else if ( lsum > rsum ) r -- ; else { l ++ ; r -- ; } } System . out . println ( - 1 ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 2 , 5 , 12 , 7 , 19 , 4 , 3 } ; int N = arr . length ; findSplit ( arr , N ) ; } }

Index/key variables: N, i, l, r
Accumulator variables: i, l, r
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GfG { static class Node { int data ; Node left , right ; } static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = null ; node . right = null ; return ( node ) ; } static class P { int pcount = 0 ; } static int countRec ( Node root , P p ) { if ( root == null ) return 0 ; int c = countRec ( root . left , p ) ; c += countRec ( root . right , p ) ; if ( root . data % 2 == 0 ) c += 1 ; if ( c % 2 != 0 ) ( p . pcount ) ++ ; return c ; } static int countSubtrees ( Node root ) { P p = new P ( ) ; countRec ( root , p ) ; return p . pcount ; } public static void main ( String [ ] args ) { Node root = newNode ( 2 ) ; root . left = newNode ( 1 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 10 ) ; root . right . left = newNode ( 8 ) ; root . right . right = newNode ( 5 ) ; root . left . right . left = newNode ( 6 ) ; System . out . println ( " Count ▁ = ▁ " + countSubtrees ( root ) ) ; } }

Accumulator variables: c
Class/struct names: GfG, Node, P
Java program:
class Solution { static class Node { int data ; Node left , right ; } static Node temp = new Node ( ) ; static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = temp . right = null ; return temp ; } static Node leftMostNode ( Node node ) { while ( node != null && node . left != null ) node = node . left ; return node ; } static Node rightMostNode ( Node node ) { while ( node != null && node . right != null ) node = node . right ; return node ; } static Node findInorderRecursive ( Node root , Node x ) { if ( root == null ) return null ; if ( root == x || ( temp = findInorderRecursive ( root . left , x ) ) != null || ( temp = findInorderRecursive ( root . right , x ) ) != null ) { if ( temp != null ) { if ( root . left == temp ) { System . out . print ( " Inorder ▁ Successor ▁ of ▁ " + x . data ) ; System . out . print ( " ▁ is ▁ " + root . data + "NEW_LINE");  return null ; } } return root ; } return null ; } static void inorderSuccesor ( Node root , Node x ) { if ( x . right != null ) { Node inorderSucc = leftMostNode ( x . right ) ; System . out . print ( " Inorder ▁ Successor ▁ of ▁ " + x . data + " ▁ is ▁ " ) ; System . out . print ( inorderSucc . data + "NEW_LINE");  } if ( x . right == null ) { int f = 0 ; Node rightMost = rightMostNode ( root ) ; if ( rightMost == x ) System . out . print ( "No inorder successor! Right most node.NEW_LINE");  else findInorderRecursive ( root , x ) ; } } public static void main ( String args [ ] ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 5 ) ; root . right . right = newNode ( 6 ) ; inorderSuccesor ( root , root . right ) ; inorderSuccesor ( root , root . left . left ) ; inorderSuccesor ( root , root . right . right ) ; } }

Class/struct names: Node, Solution