dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
import java . util . Map ; import java . util . TreeMap ; public class GFG { static void palindromeSubStrs ( String s ) { TreeMap < String , Integer > m = new TreeMap < > ( ) ; int n = s . length ( ) ; int [ ] [ ] R = new int [ 2 ] [ n + 1 ] ; s = " @ " + s + " # " ; for ( int j = 0 ; j <= 1 ; j ++ ) { R [ j ] [ 0 ] = 0 ; int i = 1 ; while ( i <= n ) { while ( s . charAt ( i - rp - 1 ) == s . charAt ( i + j + rp ) ) R [ j ] [ i ] = rp ; int k = 1 ; while ( ( R [ j ] [ i - k ] != rp - k ) && ( k < rp ) ) { R [ j ] [ i + k ] = Math . min ( R [ j ] [ i - k ] , rp - k ) ; k ++ ; } rp = Math . max ( rp - k , 0 ) ; i += k ; } } s = s . substring ( 1 , s . length ( ) - 1 ) ; m . put ( s . substring ( 0 , 1 ) , 1 ) ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j <= 1 ; j ++ ) for ( int rp = R [ j ] [ i ] ; rp > 0 ; rp -- ) m . put ( s . substring ( i - rp - 1 , i - rp - 1 + 2 * rp + j ) , 1 ) ; m . put ( s . substring ( i , i + 1 ) , 1 ) ; } System . out . println ( " Below ▁ are ▁ " + ( m . size ( ) ) + " ▁ palindrome ▁ sub - strings " ) ; for ( Map . Entry < String , Integer > ii : m . entrySet ( ) ) System . out . println ( ii . getKey ( ) ) ; } public static void main ( String args [ ] ) { palindromeSubStrs ( " abaaa " ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, k, rp
Iterator variables: i, j, rp
Class/struct names: GFG
Java program:
import java . util . * ; class GfG { static class Node { int data ; Node left = null ; Node right = null ; } static Node newNode ( int val ) { Node temp = new Node ( ) ; temp . data = val ; temp . left = null ; temp . right = null ; return temp ; } static void largestValueInEachLevel ( Node root ) { if ( root == null ) return ; Queue < Node > q = new LinkedList < Node > ( ) ; int nc , max ; q . add ( root ) ; while ( true ) { nc = q . size ( ) ; if ( nc == 0 ) break ; max = Integer . MIN_VALUE ; while ( nc != 0 ) { Node front = q . peek ( ) ; q . remove ( ) ; if ( max < front . data ) max = front . data ; if ( front . left != null ) q . add ( front . left ) ; if ( front . right != null ) q . add ( front . right ) ; nc -- ; } System . out . println ( max + " ▁ " ) ; } } public static void main ( String [ ] args ) { Node root = null ; root = newNode ( 4 ) ; root . left = newNode ( 9 ) ; root . right = newNode ( 2 ) ; root . left . left = newNode ( 3 ) ; root . left . right = newNode ( 5 ) ; root . right . right = newNode ( 7 ) ; largestValueInEachLevel ( root ) ; } }

Accumulator variables: nc
Class/struct names: GfG, Node
Java program:
class Node { int data ; Node left , right , next ; Node ( int item ) { data = item ; left = right = next = null ; } } class BinaryTree { Node root ; static Node next = null ; void populateNext ( Node node ) { if ( node != null ) { populateNext ( node . right ) ; node . next = next ; next = node ; populateNext ( node . left ) ; } } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 10 ) ; tree . root . left = new Node ( 8 ) ; tree . root . right = new Node ( 12 ) ; tree . root . left . left = new Node ( 3 ) ; tree . populateNext ( tree . root ) ; Node ptr = tree . root . left . left ; while ( ptr != null ) { int print = ptr . next != null ? ptr . next . data : - 1 ; System . out . println ( " Next ▁ of ▁ " + ptr . data + " ▁ is : ▁ " + print ) ; ptr = ptr . next ; } } }

Class/struct names: BinaryTree, Node
Java program:
import java . io . * ; class GFG { static int maxProd ( int n ) { if ( n == 2 n == 3 ) return ( n - 1 ) ; int res = 1 ; while ( n > 4 ) { n -= 3 ; res *= 3 ; } return ( n * res ) ; } public static void main ( String [ ] args ) { System . out . println ( " Maximum ▁ Product ▁ is ▁ " + maxProd ( 10 ) ) ; } }

Accumulator variables: n, res
Class/struct names: GFG
Java program:
import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { public static long findWays ( int m , int n , int x ) { long [ ] [ ] table = new long [ n + 1 ] [ x + 1 ] ; for ( int j = 1 ; j <= m && j <= x ; j ++ ) table [ 1 ] [ j ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= x ; j ++ ) { for ( int k = 1 ; k < j && k <= m ; k ++ ) table [ i ] [ j ] += table [ i - 1 ] [ j - k ] ; } } return table [ n ] [ x ] ; } public static void main ( String [ ] args ) { System . out . println ( findWays ( 4 , 2 , 1 ) ) ; System . out . println ( findWays ( 2 , 2 , 3 ) ) ; System . out . println ( findWays ( 6 , 3 , 8 ) ) ; System . out . println ( findWays ( 4 , 2 , 5 ) ) ; System . out . println ( findWays ( 4 , 3 , 5 ) ) ; } }

Index/key variables: i, j, n, x
Accumulator variables: i, j, k
Iterator variables: i, j, k
Class/struct names: GFG
Java program:
public class GFG { public static long findWays ( int f , int d , int s ) { long mem [ ] [ ] = new long [ d + 1 ] [ s + 1 ] ; mem [ 0 ] [ 0 ] = 1 ; for ( int i = 1 ; i <= d ; i ++ ) { for ( int j = i ; j <= s ; j ++ ) { mem [ i ] [ j ] = mem [ i ] [ j - 1 ] + mem [ i - 1 ] [ j - 1 ] ; if ( j - f - 1 >= 0 ) mem [ i ] [ j ] -= mem [ i - 1 ] [ j - f - 1 ] ; } } return mem [ d ] [ s ] ; } public static void main ( String [ ] args ) { System . out . println ( findWays ( 4 , 2 , 1 ) ) ; System . out . println ( findWays ( 2 , 2 , 3 ) ) ; System . out . println ( findWays ( 6 , 3 , 8 ) ) ; System . out . println ( findWays ( 4 , 2 , 5 ) ) ; System . out . println ( findWays ( 4 , 3 , 5 ) ) ; } }

Index/key variables: d, i, j, s
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int findMinInsertions ( char str [ ] , int l , int h ) { if ( l > h ) return Integer . MAX_VALUE ; if ( l == h ) return 0 ; if ( l == h - 1 ) return ( str [ l ] == str [ h ] ) ? 0 : 1 ; return ( str [ l ] == str [ h ] ) ? findMinInsertions ( str , l + 1 , h - 1 ) : ( Integer . min ( findMinInsertions ( str , l , h - 1 ) , findMinInsertions ( str , l + 1 , h ) ) + 1 ) ; } public static void main ( String args [ ] ) { String str = " geeks " ; System . out . println ( findMinInsertions ( str . toCharArray ( ) , 0 , str . length ( ) - 1 ) ) ; } }

Index/key variables: h, l
Class/struct names: GFG
Java program:
class GFG { static int max ( int x , int y ) { return ( x > y ) ? x : y ; } static int lps ( char seq [ ] , int i , int j ) { if ( i == j ) { return 1 ; } if ( seq [ i ] == seq [ j ] && i + 1 == j ) { return 2 ; } if ( seq [ i ] == seq [ j ] ) { return lps ( seq , i + 1 , j - 1 ) + 2 ; } return max ( lps ( seq , i , j - 1 ) , lps ( seq , i + 1 , j ) ) ; } public static void main ( String [ ] args ) { String seq = " GEEKSFORGEEKS " ; int n = seq . length ( ) ; System . out . printf ( " The ▁ length ▁ of ▁ the ▁ LPS ▁ is ▁ % d " , lps ( seq . toCharArray ( ) , 0 , n - 1 ) ) ; } }

Index/key variables: i, j
Class/struct names: GFG
Java program:
import java . util . Arrays ; class GFG { static int INT_MAX = ( int ) 10e6 ; static class Node { int data ; Node left , right ; } ; static int heightoftree ( Node root ) { if ( root == null ) return 0 ; int left = heightoftree ( root . left ) ; int right = heightoftree ( root . right ) ; return ( ( left > right ? left : right ) + 1 ) ; } static void printPerLevelMinimum ( Node root , int [ ] res , int level ) { if ( root != null ) { printPerLevelMinimum ( root . left , res , level + 1 ) ; if ( root . data < res [ level ] ) res [ level ] = root . data ; printPerLevelMinimum ( root . right , res , level + 1 ) ; } } static void perLevelMinimumUtility ( Node root ) { int n = heightoftree ( root ) , i ; int [ ] res = new int [ n ] ; Arrays . fill ( res , INT_MAX ) ; printPerLevelMinimum ( root , res , 0 ) ; System . out . print ( "Every level minimum isNEW_LINE"); for ( i = 0 ; i < n ; i ++ ) { System . out . print ( " level ▁ " + i + " ▁ min ▁ is ▁ = ▁ " + res [ i ] + "NEW_LINE"); } } static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = temp . right = null ; return temp ; } public static void main ( String [ ] args ) { Node root = newNode ( 7 ) ; root . left = newNode ( 6 ) ; root . right = newNode ( 5 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 3 ) ; root . right . left = newNode ( 2 ) ; root . right . right = newNode ( 1 ) ; perLevelMinimumUtility ( root ) ; } }

Index/key variables: i, level, n
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG, Node
Java program:
import java . util . * ; class GFG { static class Node { int data ; Node left , right ; } ; static int heightoftree ( Node root ) { if ( root == null ) return 0 ; int left = heightoftree ( root . left ) ; int right = heightoftree ( root . right ) ; return ( ( left > right ? left : right ) + 1 ) ; } static void printPerLevelMinimum ( Node root ) { if ( root == null ) return ; Queue < Node > q = new LinkedList < Node > ( ) ; q . add ( root ) ; q . add ( null ) ; int min = Integer . MAX_VALUE ; int level = 0 ; while ( q . isEmpty ( ) == false ) { Node node = q . peek ( ) ; q . remove ( ) ; if ( node == null ) { System . out . print ( " level ▁ " + level + " ▁ min ▁ is ▁ = ▁ " + min + "NEW_LINE"); if ( q . isEmpty ( ) ) break ; q . add ( null ) ; level ++ ; min = Integer . MAX_VALUE ; continue ; } if ( min > node . data ) min = node . data ; if ( node . left != null ) { q . add ( node . left ) ; } if ( node . right != null ) { q . add ( node . right ) ; } } } static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = temp . right = null ; return temp ; } public static void main ( String [ ] args ) { Node root = newNode ( 7 ) ; root . left = newNode ( 6 ) ; root . right = newNode ( 5 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 3 ) ; root . right . left = newNode ( 2 ) ; root . right . right = newNode ( 1 ) ; System . out . print ( " Every ▁ Level ▁ minimum ▁ is " + "NEW_LINE"); printPerLevelMinimum ( root ) ; } }

Accumulator variables: level
Class/struct names: GFG, Node
Java program:
class GFG { static int findCount ( String str1 , String str2 ) { int len = str1 . length ( ) ; int len2 = str2 . length ( ) ; int ans = Integer . MAX_VALUE ; int [ ] hash1 = new int [ 26 ] ; int [ ] hash2 = new int [ 26 ] ; for ( int i = 0 ; i < len ; i ++ ) hash1 [ ( int ) ( str1 . charAt ( i ) - ' a ' ) ] ++ ; for ( int i = 0 ; i < len2 ; i ++ ) hash2 [ ( int ) ( str2 . charAt ( i ) - ' a ' ) ] ++ ; for ( int i = 0 ; i < 26 ; i ++ ) if ( hash2 [ i ] != 0 ) ans = Math . min ( ans , hash1 [ i ] / hash2 [ i ] ) ; return ans ; } public static void main ( String [ ] args ) { String str1 = " geeksclassesatnoida " ; String str2 = " sea " ; System . out . println ( findCount ( str1 , str2 ) ) ; } }

Index/key variables: i
Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
public class Improve { static boolean isVowel ( char c ) { String vowel = " aeiou " ; for ( int i = 0 ; i < vowel . length ( ) ; ++ i ) if ( vowel . charAt ( i ) == c ) return true ; return false ; } static boolean printRLE ( String str , String typed ) { int n = str . length ( ) , m = typed . length ( ) ; int j = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str . charAt ( i ) != typed . charAt ( j ) ) return false ; if ( isVowel ( str . charAt ( i ) ) == false ) { j ++ ; continue ; } int count1 = 1 ; while ( i < n - 1 && str . charAt ( i ) == str . charAt ( i + 1 ) ) { count1 ++ ; i ++ ; } int count2 = 1 ; while ( j < m - 1 && typed . charAt ( j ) == str . charAt ( i ) ) { count2 ++ ; j ++ ; } if ( count1 > count2 ) return false ; } return true ; } public static void main ( String args [ ] ) { String name = " alex " , typed = " aaalaeex " ; if ( printRLE ( name , typed ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }

Accumulator variables: count1, count2, i, j
Iterator variables: i
Class/struct names: Improve
Java program:
class Node { int data ; Node left , right ; public Node ( int d ) { data = d ; left = right = null ; } } class BinaryTree { Node root ; int getLevelUtil ( Node node , int data , int level ) { if ( node == null ) return 0 ; if ( node . data == data ) return level ; int downlevel = getLevelUtil ( node . left , data , level + 1 ) ; if ( downlevel != 0 ) return downlevel ; downlevel = getLevelUtil ( node . right , data , level + 1 ) ; return downlevel ; } int getLevel ( Node node , int data ) { return getLevelUtil ( node , data , 1 ) ; } public static void main ( String [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 3 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 5 ) ; tree . root . left . left = new Node ( 1 ) ; tree . root . left . right = new Node ( 4 ) ; for ( int x = 1 ; x <= 5 ; x ++ ) { int level = tree . getLevel ( tree . root , x ) ; if ( level != 0 ) System . out . println ( " Level ▁ of ▁ " + x + " ▁ is ▁ " + tree . getLevel ( tree . root , x ) ) ; else System . out . println ( x + " ▁ is ▁ not ▁ present ▁ in ▁ tree " ) ; } } }

Accumulator variables: x
Iterator variables: x
Class/struct names: BinaryTree, Node
Java program:
class GFG { static String censor ( String text , String word ) { String [ ] word_list = text . split ( " \\ s + " ) ; String result = " " ; String stars = " " ; for ( int i = 0 ; i < word . length ( ) ; i ++ ) stars += ' * ' ; int index = 0 ; for ( String i : word_list ) { if ( i . compareTo ( word ) == 0 ) word_list [ index ] = stars ; index ++ ; } for ( String i : word_list ) result += i + ' ▁ ' ; return result ; } public static void main ( String [ ] args ) { String extract = " GeeksforGeeks ▁ is ▁ a ▁ computer ▁ science ▁ " + " portal ▁ for ▁ geeks . ▁ I ▁ am ▁ pursuing ▁ my ▁ " + " major ▁ in ▁ computer ▁ science . ▁ " ; String cen = " computer " ; System . out . println ( censor ( extract , cen ) ) ; } }

Index/key variables: index
Accumulator variables: i, index, result, stars
Iterator variables: i
Class/struct names: GFG
Java program:
class GFG { static int NO_OF_CHARS = 256 ; static int getNextState ( char [ ] pat , int M , int state , int x ) { if ( state < M && x == pat [ state ] ) return state + 1 ; int ns , i ; for ( ns = state ; ns > 0 ; ns -- ) { if ( pat [ ns - 1 ] == x ) { for ( i = 0 ; i < ns - 1 ; i ++ ) if ( pat [ i ] != pat [ state - ns + 1 + i ] ) break ; if ( i == ns - 1 ) return ns ; } } return 0 ; } static void computeTF ( char [ ] pat , int M , int TF [ ] [ ] ) { int state , x ; for ( state = 0 ; state <= M ; ++ state ) for ( x = 0 ; x < NO_OF_CHARS ; ++ x ) TF [ state ] [ x ] = getNextState ( pat , M , state , x ) ; } static void search ( char [ ] pat , char [ ] txt ) { int M = pat . length ; int N = txt . length ; int [ ] [ ] TF = new int [ M + 1 ] [ NO_OF_CHARS ] ; computeTF ( pat , M , TF ) ; int i , state = 0 ; for ( i = 0 ; i < N ; i ++ ) { state = TF [ state ] [ txt [ i ] ] ; if ( state == M ) System . out . println ( " Pattern ▁ found ▁ " + " at ▁ index ▁ " + ( i - M + 1 ) ) ; } } public static void main ( String [ ] args ) { char [ ] pat = " AABAACAADAABAAABAA " . toCharArray ( ) ; char [ ] txt = " AABA " . toCharArray ( ) ; search ( txt , pat ) ; } }

Index/key variables: NO_OF_CHARS, i, state, x
Accumulator variables: i, ns
Iterator variables: i, ns, state, x
Class/struct names: GFG
Java program:
class GFG { static int maxlength ( String s ) { int n = s . length ( ) , i , j ; int ans = 0 ; for ( i = 0 ; i <= n - 1 ; i ++ ) { if ( s . charAt ( i ) == '1' ) { int count = 1 ; for ( j = i + 1 ; j <= n - 1 && s . charAt ( j ) == '1' ; j ++ ) count ++ ; ans = Math . max ( ans , count ) ; } } return ans ; } public static void main ( String [ ] args ) { String s = "11101110" ; System . out . println ( " Length ▁ of ▁ longest ▁ substring ▁ containing ▁ ' 1 ' ▁ = ▁ " + maxlength ( s ) ) ; } }

Accumulator variables: count, i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . util . HashMap ; class GFG { public static void generateLetters ( String S , int P , HashMap < Character , Character > M ) { if ( P == S . length ( ) ) { System . out . println ( S ) ; return ; } generateLetters ( S , P + 1 , M ) ; S = S . substring ( 0 , P ) + M . get ( S . charAt ( P ) ) + S . substring ( P + 1 ) ; generateLetters ( S , P + 1 , M ) ; return ; } public static void main ( String args [ ] ) { String S = " aBc " ; HashMap < Character , Character > M = new HashMap < Character , Character > ( ) ; M . put ( ' a ' , ' $ ' ) ; M . put ( ' B ' , ' # ' ) ; M . put ( ' c ' , ' ^ ' ) ; M . put ( ' d ' , ' & ' ) ; M . put ( '1' , ' * ' ) ; M . put ( '2' , ' ! ' ) ; M . put ( ' E ' , ' @ ' ) ; generateLetters ( S , 0 , M ) ; } }

Class/struct names: GFG
Java program:
import java . util . HashMap ; import java . util . Map ; public class GFG { int solve ( int n , String str ) { HashMap < Integer , Integer > mymap = new HashMap < > ( ) ; int len = str . length ( ) ; for ( int i = 0 ; i < len ; i ++ ) { char c = str . charAt ( i ) ; if ( c == '5' ) c = '2' ; else if ( c == '9' ) c = '6' ; int c_int = Integer . parseInt ( String . valueOf ( c ) ) ; if ( mymap . containsKey ( c_int ) ) mymap . put ( c_int , mymap . get ( c_int ) + 1 ) ; else mymap . put ( c_int , 1 ) ; } HashMap < Integer , Integer > rems = new HashMap < > ( ) ; while ( n > 0 ) { int rem = n % 10 ; if ( rem == 5 ) rem = 2 ; if ( rem == 9 ) rem = 6 ; if ( rems . containsKey ( rem ) ) rems . put ( rem , rems . get ( rem ) + 1 ) ; else rems . put ( rem , 1 ) ; n = n / 10 ; } int cnt = Integer . MAX_VALUE ; for ( Map . Entry < Integer , Integer > ele : rems . entrySet ( ) ) { int key = ele . getKey ( ) ; if ( ! mymap . containsKey ( key ) ) return 0 ; int temp = mymap . get ( key ) / ele . getValue ( ) ; cnt = Math . min ( cnt , temp ) ; } return cnt ; } public static void main ( String args [ ] ) { GFG obj = new GFG ( ) ; int N = 56 ; String M = "245769" ; System . out . println ( obj . solve ( N , M ) ) ; } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static int ansSwaps ; static boolean check ( char [ ] S ) { for ( int i = 1 ; i < S . length ; i ++ ) { if ( S [ i - 1 ] == S [ i ] ) { return false ; } } return true ; } static void minimumSwaps ( char [ ] S , int swaps , int idx ) { if ( check ( S ) ) { ansSwaps = Math . min ( ansSwaps , swaps ) ; } for ( int i = idx ; i < S . length ; i ++ ) { for ( int j = i + 1 ; j < S . length ; j ++ ) { swap ( S , i , j ) ; minimumSwaps ( S , swaps + 1 , i + 1 ) ; S = swap ( S , i , j ) ; } } } static char [ ] swap ( char [ ] arr , int i , int j ) { char temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; return arr ; } static void findMinimumSwaps ( char [ ] S ) { ansSwaps = Integer . MAX_VALUE ; minimumSwaps ( S , 0 , 0 ) ; if ( ansSwaps == Integer . MAX_VALUE ) System . out . print ( " - 1" ) ; else System . out . print ( ansSwaps ) ; } public static void main ( String [ ] args ) { String S = " ABAACD " ; findMinimumSwaps ( S . toCharArray ( ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . lang . * ; import java . util . * ; class GFG { static void countOsBetween1s ( String S , int N , int [ ] [ ] Q ) { int [ ] leftBound = new int [ N ] ; int [ ] rightBound = new int [ N ] ; int count = 0 ; int total = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( S . charAt ( i ) == '1' ) { count = total ; } else if ( S . charAt ( i ) == '0' ) { total ++ ; } rightBound [ i ] = count ; } count = 0 ; total = 0 ; for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( S . charAt ( i ) == '1' ) { count = total ; } else if ( S . charAt ( i ) == '0' ) { total ++ ; } leftBound [ i ] = count ; } for ( int q = 0 ; q < Q . length ; q ++ ) { int L = Q [ q ] [ 0 ] ; int R = Q [ q ] [ 1 ] ; count = leftBound [ L ] + rightBound [ R ] - total ; System . out . print ( count + " ▁ " ) ; } } public static void main ( String [ ] args ) { String S = "1001010" ; int Q [ ] [ ] = { { 0 , 4 } , { 0 , 5 } } ; int N = S . length ( ) ; countOsBetween1s ( S , N , Q ) ; } }

Index/key variables: L, N, R, i, q
Accumulator variables: i, q, total
Iterator variables: i, q
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { static class node { int data ; node left , right ; node ( int data ) { this . data = data ; this . left = this . right = null ; } } static int getLevel ( node root , int data ) { Queue < node > q = new LinkedList < > ( ) ; int level = 1 ; q . add ( root ) ; q . add ( null ) ; while ( ! q . isEmpty ( ) ) { node temp = q . poll ( ) ; if ( temp == null ) { if ( q . peek ( ) != null ) { q . add ( null ) ; } level += 1 ; } else { if ( temp . data == data ) { return level ; } if ( temp . left != null ) { q . add ( temp . left ) ; } if ( temp . right != null ) { q . add ( temp . right ) ; } } } return 0 ; } public static void main ( String [ ] args ) { node root = new node ( 20 ) ; root . left = new node ( 10 ) ; root . right = new node ( 30 ) ; root . left . left = new node ( 5 ) ; root . left . right = new node ( 15 ) ; root . left . right . left = new node ( 12 ) ; root . right . left = new node ( 25 ) ; root . right . right = new node ( 40 ) ; int level = getLevel ( root , 30 ) ; if ( level != 0 ) System . out . println ( " level ▁ of ▁ node ▁ 30 ▁ is ▁ " + level ) ; else System . out . println ( " node ▁ 30 ▁ not ▁ found " ) ; level = getLevel ( root , 12 ) ; if ( level != 0 ) System . out . println ( " level ▁ of ▁ node ▁ 12 ▁ is ▁ " + level ) ; else System . out . println ( " node ▁ 12 ▁ not ▁ found " ) ; level = getLevel ( root , 25 ) ; if ( level != 0 ) System . out . println ( " level ▁ of ▁ node ▁ 25 ▁ is ▁ " + level ) ; else System . out . println ( " node ▁ 25 ▁ not ▁ found " ) ; level = getLevel ( root , 27 ) ; if ( level != 0 ) System . out . println ( " level ▁ of ▁ node ▁ 27 ▁ is ▁ " + level ) ; else System . out . println ( " node ▁ 27 ▁ not ▁ found " ) ; } }

Accumulator variables: level
Class/struct names: GFG, node
Java program:
import java . util . * ; class GFG { static String finalAns = " " ; static class Node { char data ; Node left , right ; } ; static Node newNode ( char data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = temp . right = null ; return temp ; } static boolean checkPalindrome ( String s ) { int low = 0 , high = ( int ) s . length ( ) - 1 ; while ( low < high ) { if ( s . charAt ( low ) != s . charAt ( high ) ) return false ; low ++ ; high -- ; } return true ; } static void lexicographicallySmall ( Node root , String s ) { if ( root == null ) return ; s += root . data ; if ( root . left == null && root . right == null ) { if ( checkPalindrome ( s ) ) { if ( finalAns == " $ " ) finalAns = s ; else finalAns = finalAns . compareTo ( s ) <= 0 ? finalAns : s ; } return ; } lexicographicallySmall ( root . left , s ) ; lexicographicallySmall ( root . right , s ) ; } static void getPalindromePath ( Node root ) { finalAns = " $ " ; lexicographicallySmall ( root , " " ) ; if ( finalAns == " $ " ) System . out . print ( " No ▁ Palindromic ▁ Path ▁ exists " ) ; else System . out . print ( finalAns ) ; } public static void main ( String [ ] args ) { Node root = newNode ( ' a ' ) ; root . left = newNode ( ' c ' ) ; root . left . left = newNode ( ' a ' ) ; root . left . right = newNode ( ' g ' ) ; root . right = newNode ( ' b ' ) ; root . right . left = newNode ( ' b ' ) ; root . right . right = newNode ( ' x ' ) ; root . right . left . right = newNode ( ' a ' ) ; getPalindromePath ( root ) ; } }

Accumulator variables: high, low, s
Class/struct names: GFG, Node