dhyuti-n/xlcost-variable-roles huggingface dataset:
Java program:
class GfG { static class Node { int key ; Node left , right ; } static Node newNode ( int key ) { Node n = new Node ( ) ; n . key = key ; n . left = null ; n . right = null ; return n ; } static int findMirrorRec ( int target , Node left , Node right ) { if ( left == null right == null ) return 0 ; if ( left . key == target ) return right . key ; if ( right . key == target ) return left . key ; int mirror_val = findMirrorRec ( target , left . left , right . right ) ; if ( mirror_val != 0 ) return mirror_val ; return findMirrorRec ( target , left . right , right . left ) ; } static int findMirror ( Node root , int target ) { if ( root == null ) return 0 ; if ( root . key == target ) return target ; return findMirrorRec ( target , root . left , root . right ) ; } public static void main ( String [ ] args ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . left . left = newNode ( 4 ) ; root . left . left . right = newNode ( 7 ) ; root . right = newNode ( 3 ) ; root . right . left = newNode ( 5 ) ; root . right . right = newNode ( 6 ) ; root . right . left . left = newNode ( 8 ) ; root . right . left . right = newNode ( 9 ) ; int target = root . left . left . key ; int mirror = findMirror ( root , target ) ; if ( mirror != 0 ) System . out . println ( " Mirror ▁ of ▁ Node ▁ " + target + " ▁ is ▁ Node ▁ " + mirror ) ; else System . out . println ( " Mirror ▁ of ▁ Node ▁ " + target + " ▁ is ▁ null ▁ " ) ; } }

Class/struct names: GfG, Node
Java program:
import java . io . * ; import java . util . * ; class GFG { static boolean balanced ( int small [ ] , int caps [ ] ) { for ( int i = 0 ; i < 26 ; i ++ ) { if ( small [ i ] != 0 && ( caps [ i ] == 0 ) ) return false ; else if ( ( small [ i ] == 0 ) && ( caps [ i ] != 0 ) ) return false ; } return true ; } static void smallestBalancedSubstring ( String s ) { int [ ] small = new int [ 26 ] ; int [ ] caps = new int [ 26 ] ; Arrays . fill ( small , 0 ) ; Arrays . fill ( caps , 0 ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { if ( s . charAt ( i ) >= 65 && s . charAt ( i ) <= 90 ) caps [ s . charAt ( i ) - ' A ' ] ++ ; else small [ s . charAt ( i ) - ' a ' ] ++ ; } Map < Character , Integer > mp = new HashMap < Character , Integer > ( ) ; for ( int i = 0 ; i < 26 ; i ++ ) { if ( small [ i ] != 0 && caps [ i ] == 0 ) mp . put ( ( char ) ( i + ' a ' ) , 1 ) ; else if ( caps [ i ] != 0 && small [ i ] == 0 ) mp . put ( ( char ) ( i + ' A ' ) , 1 ) ; } Arrays . fill ( small , 0 ) ; Arrays . fill ( caps , 0 ) ; int i = 0 , st = 0 ; int start = - 1 , end = - 1 ; int minm = Integer . MAX_VALUE ; while ( i < s . length ( ) ) { if ( mp . get ( s . charAt ( i ) ) != null ) { while ( st < i ) { if ( s . charAt ( st ) >= 65 && s . charAt ( st ) <= 90 ) caps [ s . charAt ( st ) - ' A ' ] -- ; else small [ s . charAt ( st ) - ' a ' ] -- ; st ++ ; } i += 1 ; st = i ; } else { if ( s . charAt ( i ) >= 65 && s . charAt ( i ) <= 90 ) caps [ s . charAt ( i ) - ' A ' ] ++ ; else small [ s . charAt ( i ) - ' a ' ] ++ ; while ( true ) { if ( s . charAt ( st ) >= 65 && s . charAt ( st ) <= 90 && caps [ s . charAt ( st ) - ' A ' ] > 1 ) { caps [ s . charAt ( st ) - ' A ' ] -- ; st ++ ; } else if ( s . charAt ( st ) >= 97 && s . charAt ( st ) <= 122 && small [ s . charAt ( st ) - ' a ' ] > 1 ) { small [ s . charAt ( st ) - ' a ' ] -- ; st ++ ; } else break ; } if ( balanced ( small , caps ) ) { if ( minm > ( i - st + 1 ) ) { minm = i - st + 1 ; start = st ; end = i ; } } i += 1 ; } } if ( start == - 1 end == - 1 ) System . out . println ( - 1 ) ; else { String ans = " " ; for ( int j = start ; j <= end ; j ++ ) ans += s . charAt ( j ) ; System . out . println ( ans ) ; } } public static void main ( String [ ] args ) { String s = " azABaabba " ; smallestBalancedSubstring ( s ) ; } }

Index/key variables: i
Accumulator variables: ans, i, j, st
Iterator variables: i, j
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class TrieNode { TrieNode [ ] child = new TrieNode [ 256 ] ; TrieNode ( ) { } } class GFG { private static void insertTrie ( TrieNode root , String str ) { int M = str . length ( ) ; for ( int i = 0 ; i < M ; i ++ ) { if ( root . child [ str . charAt ( i ) ] == null ) { root . child [ str . charAt ( i ) ] = new TrieNode ( ) ; } root = root . child [ str . charAt ( i ) ] ; } } private static int findStrLen ( TrieNode root , String str ) { int M = str . length ( ) ; int len = 0 ; for ( int i = 0 ; i < M ; i ++ ) { if ( root . child [ str . charAt ( i ) ] != null ) { len ++ ; root = root . child [ str . charAt ( i ) ] ; } else { return len ; } } return len ; } private static void findMaxLenPair ( List < String > arr , int N ) { int idx = - 1 ; int len = 0 ; TrieNode root = new TrieNode ( ) ; insertTrie ( root , arr . get ( 0 ) ) ; for ( int i = 1 ; i < N ; i ++ ) { int temp = findStrLen ( root , arr . get ( i ) ) ; if ( temp > len ) { len = temp ; idx = i ; } insertTrie ( root , arr . get ( i ) ) ; } for ( int i = 0 ; i < N ; i ++ ) { int M = arr . get ( i ) . length ( ) ; if ( i != idx && M >= len ) { boolean found = true ; for ( int j = 0 ; j < len ; j ++ ) { if ( arr . get ( i ) . charAt ( j ) != arr . get ( idx ) . charAt ( j ) ) { found = false ; break ; } } if ( found ) { System . out . println ( " ( " + arr . get ( i ) + " , ▁ " + arr . get ( idx ) + " ) " ) ; return ; } } } } public static void main ( String [ ] args ) { List < String > arr = Arrays . asList ( new String [ ] { " geeksforgeeks " , " geeks " , " geeksforcse " } ) ; int N = arr . size ( ) ; findMaxLenPair ( arr , N ) ; } }

Accumulator variables: i, j, len
Iterator variables: i, j
Boolean variables: found
Class/struct names: GFG, TrieNode
Java program:
import java . util . * ; import java . lang . * ; class GFG { static void transformString ( String str1 , String str2 ) { int N = str1 . length ( ) ; ArrayList < ArrayList < Integer > > convChar = new ArrayList < > ( ) ; ArrayList < ArrayList < Integer > > str1array = new ArrayList < > ( ) ; for ( int i = 0 ; i < 26 ; i ++ ) { convChar . add ( new ArrayList < > ( ) ) ; str1array . add ( new ArrayList < > ( ) ) ; } Map < Integer , Character > convertMap = new HashMap < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { str1array . get ( str1 . charAt ( i ) - ' a ' ) . add ( i ) ; } for ( int i = 0 ; i < N ; i ++ ) { if ( str1 . charAt ( i ) < str2 . charAt ( i ) ) { System . out . println ( - 1 ) ; return ; } else if ( str1 . charAt ( i ) == str2 . charAt ( i ) ) continue ; else { convChar . get ( str2 . charAt ( i ) - ' a ' ) . add ( i ) ; convertMap . put ( i , str2 . charAt ( i ) ) ; } } int ret = 0 ; ArrayList < ArrayList < Integer > > retv = new ArrayList < > ( ) ; for ( int i = 25 ; i >= 0 ; i -- ) { ArrayList < Integer > v = convChar . get ( i ) ; if ( v . size ( ) == 0 ) continue ; ret ++ ; ArrayList < Integer > v1 = str1array . get ( i ) ; if ( v1 . size ( ) == 0 ) { System . out . println ( - 1 ) ; return ; } boolean isScompleted = false ; for ( int j = 0 ; j < v1 . size ( ) ; j ++ ) { if ( convertMap . containsKey ( v1 . get ( j ) ) ) { char a = convertMap . get ( v1 . get ( j ) ) ; if ( a > i + ' a ' ) continue ; else { v . add ( v1 . get ( j ) ) ; isScompleted = true ; retv . add ( v ) ; break ; } } else { v . add ( v1 . get ( j ) ) ; isScompleted = true ; retv . add ( v ) ; break ; } } if ( ! isScompleted ) { System . out . println ( - 1 ) ; return ; } } System . out . println ( ret ) ; } public static void main ( String [ ] args ) { String A = " abcab " ; String B = " aabab " ; transformString ( A , B ) ; } }

Accumulator variables: i, j, ret
Iterator variables: i, j
Boolean variables: isScompleted
Class/struct names: GFG
Java program:
class GFG { static class Node { int data ; Node left , right ; } ; static Node newNode ( int data ) { Node node = new Node ( ) ; node . data = data ; node . left = node . right = null ; return ( node ) ; } static class string { String str ; } static int maxSize ; static Node maxNode ; static class pair { int first ; String second ; pair ( int a , String b ) { first = a ; second = b ; } } static pair largestSubtreeUtil ( Node root , String str ) { if ( root == null ) return new pair ( 0 , str ) ; String left = " " , right = " " ; pair ls1 = largestSubtreeUtil ( root . left , left ) ; left = ls1 . second ; int ls = ls1 . first ; pair rs1 = largestSubtreeUtil ( root . right , right ) ; right = rs1 . second ; int rs = rs1 . first ; int size = ls + rs + 1 ; if ( left . equals ( right ) ) { if ( size > maxSize ) { maxSize = size ; maxNode = root ; } } str += " | " + left + " | " ; str += " | " + root . data + " | " ; str += " | " + right + " | " ; return new pair ( size , str ) ; } static int largestSubtree ( Node node ) { maxSize = 0 ; largestSubtreeUtil ( node , " " ) ; return maxSize ; } public static void main ( String args [ ] ) { Node root = newNode ( 50 ) ; root . left = newNode ( 10 ) ; root . right = newNode ( 60 ) ; root . left . left = newNode ( 5 ) ; root . left . right = newNode ( 20 ) ; root . right . left = newNode ( 70 ) ; root . right . left . left = newNode ( 65 ) ; root . right . left . right = newNode ( 80 ) ; root . right . right = newNode ( 70 ) ; root . right . right . left = newNode ( 65 ) ; root . right . right . right = newNode ( 80 ) ; maxNode = null ; maxSize = largestSubtree ( root ) ; System . out . println ( " Largest ▁ Subtree ▁ is ▁ rooted ▁ at ▁ node ▁ " + maxNode . data + " and its size is " + maxSize); } }

Accumulator variables: str
Class/struct names: GFG, Node, pair, string
Java program:
import java . io . * ; import java . util . * ; import java . lang . * ; class GeeksforGeeks { static Set < String > visited ; static StringBuilder ans ; public static void dfs ( String curr , int D ) { for ( int x = 0 ; x < D ; ++ x ) { String neighbour = curr + x ; if ( ! visited . contains ( neighbour ) ) { visited . add ( neighbour ) ; dfs ( neighbour . substring ( 1 ) , D ) ; ans . append ( x ) ; } } } public static String reqString ( int N , int D ) { if ( N == 1 && D == 1 ) return "0" ; visited = new HashSet < > ( ) ; ans = new StringBuilder ( ) ; StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < N - 1 ; ++ i ) { sb . append ( "0" ) ; } String start = sb . toString ( ) ; dfs ( start , D ) ; ans . append ( start ) ; return new String ( ans ) ; } public static void main ( String args [ ] ) { int N = 2 ; int D = 2 ; System . out . println ( reqString ( N , D ) ) ; } }

Iterator variables: i, x
Class/struct names: GeeksforGeeks
Java program:
import java . util . * ; class GFG { static boolean isScramble ( String S1 , String S2 ) { if ( S1 . length ( ) != S2 . length ( ) ) { return false ; } int n = S1 . length ( ) ; if ( n == 0 ) { return true ; } if ( S1 . equals ( S2 ) ) { return true ; } char [ ] tempArray1 = S1 . toCharArray ( ) ; char [ ] tempArray2 = S2 . toCharArray ( ) ; Arrays . sort ( tempArray1 ) ; Arrays . sort ( tempArray2 ) ; String copy_S1 = new String ( tempArray1 ) ; String copy_S2 = new String ( tempArray2 ) ; if ( ! copy_S1 . equals ( copy_S2 ) ) { return false ; } for ( int i = 1 ; i < n ; i ++ ) { if ( isScramble ( S1 . substring ( 0 , i ) , S2 . substring ( 0 , i ) ) && isScramble ( S1 . substring ( i , n ) , S2 . substring ( i , n ) ) ) { return true ; } if ( isScramble ( S1 . substring ( n - i , n ) , S2 . substring ( 0 , i ) ) && isScramble ( S1 . substring ( 0 , n - i ) , S2 . substring ( i , n ) ) ) { return true ; } } return false ; } public static void main ( String [ ] args ) { String S1 = " coder " ; String S2 = " ocred " ; if ( isScramble ( S1 , S2 ) ) { System . out . println ( " Yes " ) ; } else { System . out . println ( " No " ) ; } } }

Accumulator variables: i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; class GFG { static String findAns ( String s ) { int digit ; Vector < Integer > odd = new Vector < Integer > ( ) ; Vector < Integer > even = new Vector < Integer > ( ) ; for ( char c : s . toCharArray ( ) ) { digit = c - '0' ; if ( digit % 2 == 1 ) odd . add ( digit ) ; else even . add ( digit ) ; } int i = 0 ; int j = 0 ; String ans = " " ; while ( i < odd . size ( ) && j < even . size ( ) ) { if ( odd . get ( i ) < even . get ( j ) ) ans += ( char ) ( odd . get ( i ++ ) + '0' ) ; else ans += ( char ) ( even . get ( j ++ ) + '0' ) ; } while ( i < odd . size ( ) ) ans += ( char ) ( odd . get ( i ++ ) + '0' ) ; while ( j < even . size ( ) ) ans += ( char ) ( even . get ( j ++ ) + '0' ) ; while ( ans . charAt ( 0 ) == '0' ) { ans = ans . substring ( 1 ) ; } return ans ; } public static void main ( String [ ] args ) { String s = "894687536" ; System . out . print ( findAns ( s ) ) ; } }

Accumulator variables: ans, i, j
Iterator variables: c
Class/struct names: GFG
Java program:
import java . io . * ; import java . util . * ; class GFG { public static int bcdToDecimal ( String s ) { int len = s . length ( ) ; int check = 0 , check0 = 0 ; int num = 0 , sum = 0 ; int mul = 1 , rev = 0 ; for ( int i = len - 1 ; i >= 0 ; i -- ) { sum += ( s . charAt ( i ) - '0' ) * mul ; mul *= 2 ; check ++ ; if ( check == 4 i == 0 ) { if ( sum == 0 && check0 == 0 ) { num = 1 ; check0 = 1 ; } else { num = num * 10 + sum ; } check = 0 ; sum = 0 ; mul = 1 ; } } while ( num > 0 ) { rev = rev * 10 + ( num % 10 ) ; num /= 10 ; } if ( check0 == 1 ) return rev - 1 ; return rev ; } public static void main ( String [ ] args ) { String s = "100000101000" ; System . out . println ( bcdToDecimal ( s ) ) ; } }

Accumulator variables: check, i, mul, num, sum
Iterator variables: i
Class/struct names: GFG
Java program:
class Node { int data ; Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } class Count { int count = 0 ; } class BinaryTree { Node root ; Count ct = new Count ( ) ; boolean countSingleRec ( Node node , Count c ) { if ( node == null ) return true ; boolean left = countSingleRec ( node . left , c ) ; boolean right = countSingleRec ( node . right , c ) ; if ( left == false right == false ) return false ; if ( node . left != null && node . data != node . left . data ) return false ; if ( node . right != null && node . data != node . right . data ) return false ; c . count ++ ; return true ; } int countSingle ( ) { return countSingle ( root ) ; } int countSingle ( Node node ) { countSingleRec ( node , ct ) ; return ct . count ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 5 ) ; tree . root . left = new Node ( 4 ) ; tree . root . right = new Node ( 5 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 4 ) ; tree . root . right . right = new Node ( 5 ) ; System . out . println ( " The ▁ count ▁ of ▁ single ▁ valued ▁ sub ▁ trees ▁ is ▁ : ▁ " + tree . countSingle ( ) ) ; } }

Accumulator variables: count
Class/struct names: BinaryTree, Count, Node
Java program:
import java . io . * ; import java . util . * ; class GFG { static String reverse ( String str ) { String rev = " " ; for ( int i = str . length ( ) - 1 ; i >= 0 ; i -- ) rev = rev + str . charAt ( i ) ; return rev ; } static String strBitwiseXOR ( String [ ] arr , int n ) { String result = " " ; int max_len = Integer . MIN_VALUE ; for ( int i = 0 ; i < n ; i ++ ) { max_len = Math . max ( max_len , ( int ) arr [ i ] . length ( ) ) ; arr [ i ] = reverse ( arr [ i ] ) ; } for ( int i = 0 ; i < n ; i ++ ) { String s = " " ; for ( int j = 0 ; j < max_len - arr [ i ] . length ( ) ; j ++ ) s += '0' ; arr [ i ] = arr [ i ] + s ; } for ( int i = 0 ; i < max_len ; i ++ ) { int pres_bit = 0 ; for ( int j = 0 ; j < n ; j ++ ) pres_bit = pres_bit ^ ( arr [ j ] . charAt ( i ) - '0' ) ; result += ( char ) ( pres_bit + '0' ) ; } result = reverse ( result ) ; return result ; } public static void main ( String [ ] args ) { String [ ] arr = { "1000" , "10001" , "0011" } ; int n = arr . length ; System . out . print ( strBitwiseXOR ( arr , n ) ) ; } }

Index/key variables: i, j
Accumulator variables: i, j, result, s
Iterator variables: i, j
Class/struct names: GFG
Java program:
class GFG { static int sticks [ ] = { 6 , 7 , 4 , 6 , 5 , 4 , 6 , 5 , 2 , 4 , 4 , 3 , 6 , 6 , 6 , 5 , 7 , 6 , 5 , 3 , 5 , 4 , 6 , 4 , 3 , 4 } ; static int number [ ] = { 6 , 2 , 5 , 5 , 4 , 5 , 6 , 3 , 7 , 6 } ; static int countSticks ( String str ) { int cnt = 0 ; for ( int i = 0 ; i < str . length ( ) ; i ++ ) { char ch = str . charAt ( i ) ; if ( ch >= ' A ' && ch <= ' Z ' ) { cnt += sticks [ ch - ' A ' ] ; } else { cnt += number [ ch - '0' ] ; } } return cnt ; } public static void main ( String [ ] args ) { String str = " GEEKSFORGEEKS " ; System . out . println ( countSticks ( str ) ) ; } }

Accumulator variables: cnt, i
Iterator variables: i
Class/struct names: GFG
Java program:
import java . util . * ; public class GfG { private static String remainingDigit ( String S , int N ) { char c [ ] = S . toCharArray ( ) ; int del [ ] = { 0 , 0 } ; int count [ ] = { 0 , 0 } ; Queue < Integer > q = new LinkedList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { int x = c [ i ] == '1' ? 1 : 0 ; count [ x ] ++ ; q . add ( x ) ; } while ( count [ 0 ] > 0 && count [ 1 ] > 0 ) { int t = q . poll ( ) ; if ( del [ t ] > 0 ) { del [ t ] -- ; count [ t ] -- ; } else { del [ t ^ 1 ] ++ ; q . add ( t ) ; } } if ( count [ 0 ] > 0 ) return "0" ; return "1" ; } public static void main ( String args [ ] ) { String S = "1010100100000" ; int N = S . length ( ) ; System . out . print ( remainingDigit ( S , N ) ) ; } }

Index/key variables: i, t, x
Accumulator variables: i
Iterator variables: i
Class/struct names: GfG
Java program:
class Node { int key ; Node left , right ; public Node ( int key ) { this . key = key ; left = right = null ; } } class Distance { int minDis = Integer . MAX_VALUE ; } class BinaryTree { Node root ; void findLeafDown ( Node root , int lev , Distance minDist ) { if ( root == null ) return ; if ( root . left == null && root . right == null ) { if ( lev < ( minDist . minDis ) ) minDist . minDis = lev ; return ; } findLeafDown ( root . left , lev + 1 , minDist ) ; findLeafDown ( root . right , lev + 1 , minDist ) ; } int findThroughParent ( Node root , Node x , Distance minDist ) { if ( root == null ) return - 1 ; if ( root == x ) return 0 ; int l = findThroughParent ( root . left , x , minDist ) ; if ( l != - 1 ) { findLeafDown ( root . right , l + 2 , minDist ) ; return l + 1 ; } int r = findThroughParent ( root . right , x , minDist ) ; if ( r != - 1 ) { findLeafDown ( root . left , r + 2 , minDist ) ; return r + 1 ; } return - 1 ; } int minimumDistance ( Node root , Node x ) { Distance d = new Distance ( ) ; findLeafDown ( x , 0 , d ) ; findThroughParent ( root , x , d ) ; return d . minDis ; } public static void main ( String [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 12 ) ; tree . root . right = new Node ( 13 ) ; tree . root . right . left = new Node ( 14 ) ; tree . root . right . right = new Node ( 15 ) ; tree . root . right . left . left = new Node ( 21 ) ; tree . root . right . left . right = new Node ( 22 ) ; tree . root . right . right . left = new Node ( 23 ) ; tree . root . right . right . right = new Node ( 24 ) ; tree . root . right . left . left . left = new Node ( 1 ) ; tree . root . right . left . left . right = new Node ( 2 ) ; tree . root . right . left . right . left = new Node ( 3 ) ; tree . root . right . left . right . right = new Node ( 4 ) ; tree . root . right . right . left . left = new Node ( 5 ) ; tree . root . right . right . left . right = new Node ( 6 ) ; tree . root . right . right . right . left = new Node ( 7 ) ; tree . root . right . right . right . right = new Node ( 8 ) ; Node x = tree . root . right ; System . out . println ( " The ▁ closest ▁ leaf ▁ to ▁ node ▁ with ▁ value ▁ " + x . key + " ▁ is ▁ at ▁ a ▁ distance ▁ of ▁ " + tree . minimumDistance ( tree . root , x ) ) ; } }

Class/struct names: BinaryTree, Distance, Node
Java program:
class Node { int data ; Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } class BinaryTree { Node root ; int getMin ( int x , int y ) { return ( x < y ) ? x : y ; } int closestDown ( Node node ) { if ( node == null ) return Integer . MAX_VALUE ; if ( node . left == null && node . right == null ) return 0 ; return 1 + getMin ( closestDown ( node . left ) , closestDown ( node . right ) ) ; } int findClosestUtil ( Node node , char k , Node ancestors [ ] , int index ) { if ( node == null ) return Integer . MAX_VALUE ; if ( node . data == k ) { int res = closestDown ( node ) ; for ( int i = index - 1 ; i >= 0 ; i -- ) res = getMin ( res , index - i + closestDown ( ancestors [ i ] ) ) ; return res ; } ancestors [ index ] = node ; return getMin ( findClosestUtil ( node . left , k , ancestors , index + 1 ) , findClosestUtil ( node . right , k , ancestors , index + 1 ) ) ; } int findClosest ( Node node , char k ) { Node ancestors [ ] = new Node [ 100 ] ; return findClosestUtil ( node , k , ancestors , 0 ) ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( ' A ' ) ; tree . root . left = new Node ( ' B ' ) ; tree . root . right = new Node ( ' C ' ) ; tree . root . right . left = new Node ( ' E ' ) ; tree . root . right . right = new Node ( ' F ' ) ; tree . root . right . left . left = new Node ( ' G ' ) ; tree . root . right . left . left . left = new Node ( ' I ' ) ; tree . root . right . left . left . right = new Node ( ' J ' ) ; tree . root . right . right . right = new Node ( ' H ' ) ; tree . root . right . right . right . left = new Node ( ' H ' ) ; char k = ' H ' ; System . out . println ( " Distance ▁ of ▁ the ▁ closest ▁ key ▁ from ▁ " + k + " ▁ is ▁ " + tree . findClosest ( tree . root , k ) ) ; k = ' C ' ; System . out . println ( " Distance ▁ of ▁ the ▁ closest ▁ key ▁ from ▁ " + k + " ▁ is ▁ " + tree . findClosest ( tree . root , k ) ) ; k = ' E ' ; System . out . println ( " Distance ▁ of ▁ the ▁ closest ▁ key ▁ from ▁ " + k + " ▁ is ▁ " + tree . findClosest ( tree . root , k ) ) ; k = ' B ' ; System . out . println ( " Distance ▁ of ▁ the ▁ closest ▁ key ▁ from ▁ " + k + " ▁ is ▁ " + tree . findClosest ( tree . root , k ) ) ; } }

Index/key variables: i, index
Accumulator variables: i
Iterator variables: i
Class/struct names: BinaryTree, Node
Java program:
import java . util . * ; class GFG { static String getTime ( String s , int n ) { String res = " " ; int h = Integer . parseInt ( s . substring ( 0 , 0 + 2 ) ) ; int m = Integer . parseInt ( s . substring ( 3 , 3 + 2 ) ) ; int rev_h = ( h % 10 ) * 10 + ( ( h % 100 ) - ( h % 10 ) ) / 10 ; String rev_hs = Integer . toString ( rev_h ) ; if ( h == 23 && m >= 32 ) { res = " - 1" ; } else if ( m < rev_h ) { String temp = " " ; if ( h < 10 ) temp = "0" ; temp = temp + Integer . toString ( h ) ; if ( rev_h < 10 ) res = res + temp + " : 0" + rev_hs ; else res = res + temp + " : " + rev_hs ; } else { h ++ ; rev_h = ( h % 10 ) * 10 + ( ( h % 100 ) - ( h % 10 ) ) / 10 ; rev_hs = Integer . toString ( rev_h ) ; String temp = " " ; if ( h < 10 ) temp = "0" ; temp = temp + Integer . toString ( h ) ; if ( rev_h < 10 ) res = res + temp + " : 0" + rev_hs ; else res = res + temp + " : " + rev_hs ; } return res ; } public static void main ( String [ ] args ) { String s = "21:12" ; int n = s . length ( ) ; System . out . println ( getTime ( s , n ) ) ; } }

Accumulator variables: h
Class/struct names: GFG
Java program:
class GFG { static int CountSubstring ( char str [ ] , int n ) { int ans = ( n * ( n + 1 ) ) / 2 ; int a_index = 0 ; int b_index = 0 ; int c_index = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' a ' ) { a_index = i + 1 ; ans -= Math . min ( b_index , c_index ) ; } else if ( str [ i ] == ' b ' ) { b_index = i + 1 ; ans -= Math . min ( a_index , c_index ) ; } else { c_index = i + 1 ; ans -= Math . min ( a_index , b_index ) ; } } return ans ; } public static void main ( String [ ] args ) { char str [ ] = " babac " . toCharArray ( ) ; int n = str . length ; System . out . println ( CountSubstring ( str , n ) ) ; } }

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