codeparrot/xlcost-text-to-code huggingface dataset:
Deepest left leaf node in a binary tree | A Binary Tree node ; Constructor ; Class to evaluate pass by reference ; maxlevel : gives the value of level of maximum left leaf ; Node to store resultant node after left traversal ; A utility function to find deepest leaf node . lvl : level of current node . isLeft : A bool indicate that this node is left child ; Base case ; Update result if this node is left leaf and its level is more than the maxl level of the current result ; Recur for left and right subtrees ; A wrapper over deepestLeftLeafUtil ( ) . ; Driver program to test above functions
class Node { int data ; Node left , right ; public Node ( int data ) { this . data = data ; left = right = null ; } } class Level { int maxlevel = 0 ; } class BinaryTree { Node root ; Node result ; void deepestLeftLeafUtil ( Node node , int lvl , Level level , boolean isLeft ) { if ( node == null ) return ; if ( isLeft != false && node . left == null && node . right == null && lvl > level . maxlevel ) { result = node ; level . maxlevel = lvl ; } deepestLeftLeafUtil ( node . left , lvl + 1 , level , true ) ; deepestLeftLeafUtil ( node . right , lvl + 1 , level , false ) ; } void deepestLeftLeaf ( Node node ) { Level level = new Level ( ) ; deepestLeftLeafUtil ( node , 0 , level , false ) ; } public static void main ( String [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . right . left = new Node ( 5 ) ; tree . root . right . right = new Node ( 6 ) ; tree . root . right . left . right = new Node ( 7 ) ; tree . root . right . right . right = new Node ( 8 ) ; tree . root . right . left . right . left = new Node ( 9 ) ; tree . root . right . right . right . right = new Node ( 10 ) ; tree . deepestLeftLeaf ( tree . root ) ; if ( tree . result != null ) System . out . println ( " The ▁ deepest ▁ left ▁ child " + " ▁ is ▁ " + tree . result . data ) ; else System . out . println ( " There ▁ is ▁ no ▁ left ▁ leaf ▁ in " + " ▁ the ▁ given ▁ tree " ) ; } }
Check if an array contains all elements of a given range | JAVA Code for Check if an array contains all elements of a given range ; Function to check the array for elements in given range ; Range is the no . of elements that are to be checked ; Traversing the array ; If an element is in range ; Checking whether elements in range 0 - range are negative ; Element from range is missing from array ; All range elements are present ; Driver program to test above function ; Defining Array and size ; A is lower limit and B is the upper limit of range ; True denotes all elements were present ; False denotes any element was not present
import java . util . * ; class GFG { public static boolean check_elements ( int arr [ ] , int n , int A , int B ) { int range = B - A ; for ( int i = 0 ; i < n ; i ++ ) { if ( Math . abs ( arr [ i ] ) >= A && Math . abs ( arr [ i ] ) <= B ) { int z = Math . abs ( arr [ i ] ) - A ; if ( arr [ z ] > 0 ) { arr [ z ] = arr [ z ] * - 1 ; } } } int count = 0 ; for ( int i = 0 ; i <= range && i < n ; i ++ ) { if ( arr [ i ] > 0 ) return false ; else count ++ ; } if ( count != ( range + 1 ) ) return false ; return true ; } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 4 , 5 , 2 , 7 , 8 , 3 } ; int n = arr . length ; int A = 2 , B = 5 ; if ( check_elements ( arr , n , A , B ) ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } }
Recursive Programs to find Minimum and Maximum elements of array | Recursive Java program to find minimum ; function to return minimum element using recursion ; if size = 0 means whole array has been traversed ; Driver code
import java . util . * ; class GFG { public static int findMinRec ( int A [ ] , int n ) { if ( n == 1 ) return A [ 0 ] ; return Math . min ( A [ n - 1 ] , findMinRec ( A , n - 1 ) ) ; } public static void main ( String args [ ] ) { int A [ ] = { 1 , 4 , 45 , 6 , - 50 , 10 , 2 } ; int n = A . length ; System . out . println ( findMinRec ( A , n ) ) ; } }
Allocate minimum number of pages | Java program for optimal allocation of pages ; Utility method to check if current minimum value is feasible or not . ; iterate over all books ; check if current number of pages are greater than curr_min that means we will get the result after mid no . of pages ; count how many students are required to distribute curr_min pages ; increment student count ; update curr_sum ; if students required becomes greater than given no . of students , return false ; else update curr_sum ; method to find minimum pages ; return - 1 if no . of books is less than no . of students ; Count total number of pages ; initialize start as 0 pages and end as total pages ; traverse until start <= end ; check if it is possible to distribute books by using mid is current minimum ; update result to current distribution as it 's the best we have found till now. ; as we are finding minimum and books are sorted so reduce end = mid - 1 that means ; if not possible means pages should be increased so update start = mid + 1 ; at - last return minimum no . of pages ; Driver Method ; Number of pages in books ; int m = 2 ; No . of students
public class GFG { static boolean isPossible ( int arr [ ] , int n , int m , int curr_min ) { int studentsRequired = 1 ; int curr_sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] > curr_min ) return false ; if ( curr_sum + arr [ i ] > curr_min ) { studentsRequired ++ ; curr_sum = arr [ i ] ; if ( studentsRequired > m ) return false ; } else curr_sum += arr [ i ] ; } return true ; } static int findPages ( int arr [ ] , int n , int m ) { long sum = 0 ; if ( n < m ) return - 1 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; int start = 0 , end = ( int ) sum ; int result = Integer . MAX_VALUE ; while ( start <= end ) { int mid = ( start + end ) / 2 ; if ( isPossible ( arr , n , m , mid ) ) { result = mid ; end = mid - 1 ; } else start = mid + 1 ; } return result ; } public static void main ( String [ ] args ) { int arr [ ] = { 12 , 34 , 67 , 90 } ; System . out . println ( " Minimum ▁ number ▁ of ▁ pages ▁ = ▁ " + findPages ( arr , arr . length , m ) ) ; } }
Maximum number of plates that can be placed from top to bottom in increasing order of size | Java program for the above approach ; Recursive function to count and return the max number of plates that can be placed ; If no plate remains ; If length and width of previous plate exceeds that of the current plate ; Calculate including the plate ; Calculate excluding the plate ; Otherwise ; Calculate only excluding the plate ; Driver code ; Sorting plates in decreasing order of area ; Assuming first plate to be of maximum size
import java . lang . * ; import java . util . * ; class GFG { static int countPlates ( int [ ] [ ] plates , int lastLength , int lastWidth , int i , int n ) { if ( i == n ) return 0 ; int taken = 0 , notTaken = 0 ; if ( lastLength > plates [ i ] [ 0 ] && lastWidth > plates [ i ] [ 1 ] ) { taken = 1 + countPlates ( plates , plates [ i ] [ 0 ] , plates [ i ] [ 1 ] , i + 1 , n ) ; notTaken = countPlates ( plates , lastLength , lastWidth , i + 1 , n ) ; } else notTaken = countPlates ( plates , lastLength , lastWidth , i + 1 , n ) ; return Math . max ( taken , notTaken ) ; } public static void main ( String [ ] args ) { int [ ] [ ] plates = { { 6 , 4 } , { 5 , 7 } , { 1 , 2 } , { 3 , 3 } , { 7 , 9 } } ; int n = plates . length ; Arrays . sort ( plates , ( v1 , v2 ) -> ( v2 [ 0 ] * v2 [ 1 ] ) - ( v1 [ 0 ] * v1 [ 1 ] ) ) ; int lastLength = Integer . MAX_VALUE ; int lastWidth = Integer . MAX_VALUE ; System . out . println ( countPlates ( plates , lastLength , lastWidth , 0 , n ) ) ; } }
Smallest element with K set bits such that sum of Bitwise AND of each array element with K is maximum | Java program for the above approach ; Function to find the value of X such that Bitwise AND of all array elements with X is maximum ; Stores the count of set bit at each position ; Stores the resultant value of X ; Calculate the count of set bits at each position ; If the jth bit is set ; Stores the contribution of each set bit ; Store all bit and amount of contribution ; Find the total contribution ; Sort V [ ] in decreasing order of second parameter ; Choose exactly K set bits ; Print the answer ; Driver Code
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static void maximizeSum ( int arr [ ] , int n , int k ) { int cnt [ ] = new int [ 30 ] ; int X = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < 30 ; j ++ ) { if ( ( arr [ i ] & ( 1 << j ) ) != 0 ) cnt [ j ] ++ ; } } ArrayList < int [ ] > v = new ArrayList < > ( ) ; for ( int i = 0 ; i < 30 ; i ++ ) { int gain = cnt [ i ] * ( 1 << i ) ; v . add ( new int [ ] { i , gain } ) ; } Collections . sort ( v , ( a , b ) -> { if ( a [ 1 ] != b [ 1 ] ) return b [ 1 ] - a [ 1 ] ; return a [ 0 ] - b [ 0 ] ; } ) ; for ( int i = 0 ; i < k ; i ++ ) { X |= ( 1 << v . get ( i ) [ 0 ] ) ; } System . out . println ( X ) ; } public static void main ( String [ ] args ) { int arr [ ] = { 3 , 4 , 5 , 1 } ; int K = 1 ; int N = arr . length ; maximizeSum ( arr , N , K ) ; } }
Largest Roman Numeral possible by rearranging characters of a given string | Java program for the above approach ; Function to find decimal value of a roman character ; Function to convert string representing roman number to equivalent decimal value ; Stores the decimal value of the string S ; Stores the size of the S ; Update res ; Traverse the string ; Return res ; Function to convert decimal to equivalent roman numeral ; Stores the string ; Stores all the digit values of a roman digit ; Iterate while number is greater than 0 ; Return res ; Function to find largest roman value possible by rearranging the characters of the string ; Stores all roman characters ; Traverse the string ; If X is not found ; Stores the decimal value of the roman number ; Find the roman value equivalent to the decimal value of N ; Return result ; Driver Code
import java . io . * ; import java . lang . * ; import java . util . * ; class GFG { static int charVal ( char c ) { if ( c == ' I ' ) return 1 ; if ( c == ' V ' ) return 5 ; if ( c == ' X ' ) return 10 ; if ( c == ' L ' ) return 50 ; if ( c == ' C ' ) return 100 ; if ( c == ' D ' ) return 500 ; if ( c == ' M ' ) return 1000 ; return - 1 ; } static int romanToDec ( String S ) { int res = 0 ; int n = S . length ( ) ; res = charVal ( S . charAt ( n - 1 ) ) ; for ( int i = n - 2 ; i >= 0 ; i -- ) { if ( charVal ( S . charAt ( i ) ) < charVal ( S . charAt ( i + 1 ) ) ) res -= charVal ( S . charAt ( i ) ) ; else res += charVal ( S . charAt ( i ) ) ; } return res ; } static String DecToRoman ( int number ) { String res = " " ; int num [ ] = { 1 , 4 , 5 , 9 , 10 , 40 , 50 , 90 , 100 , 400 , 500 , 900 , 1000 } ; String sym [ ] = { " I " , " IV " , " V " , " IX " , " X " , " XL " , " L " , " XC " , " C " , " CD " , " D " , " CM " , " M " } ; int i = 12 ; while ( number > 0 ) { int div = number / num [ i ] ; number = number % num [ i ] ; while ( div -- > 0 ) { res += sym [ i ] ; } i -- ; } return res ; } static String findLargest ( String S ) { char arr [ ] = { ' I ' , ' V ' , ' X ' , ' L ' , ' C ' , ' D ' , ' M ' } ; Set < Character > st = new HashSet < > ( ) ; for ( char x : arr ) st . add ( x ) ; Character s [ ] = new Character [ S . length ( ) ] ; for ( int i = 0 ; i < S . length ( ) ; i ++ ) s [ i ] = S . charAt ( i ) ; for ( char x : s ) { if ( ! st . contains ( x ) ) return " Invalid " ; } Arrays . sort ( s , new Comparator < Character > ( ) { @ Override public int compare ( Character x , Character y ) { return charVal ( y ) - charVal ( x ) ; } } ) ; String ss = " " ; for ( char ch : s ) ss += ch ; int N = romanToDec ( ss ) ; String R = DecToRoman ( N ) ; if ( ! ss . equals ( R ) ) return " Invalid " ; return ss ; } public static void main ( String [ ] args ) { String S = " MCMIV " ; int N = S . length ( ) ; System . out . println ( findLargest ( S ) ) ; } }
Find Minimum Depth of a Binary Tree | Class containing left and right child of current node and key value ; Root of the Binary Tree ; Function to calculate the minimum depth of the tree ; Corner case . Should never be hit unless the code is called on root = NULL ; Base case : Leaf Node . This accounts for height = 1. ; If left subtree is NULL , recur for right subtree ; If right subtree is NULL , recur for left subtree ; Driver program to test above functions ; Let us construct the Tree shown in the above figure
class Node { int data ; Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } public class BinaryTree { Node root ; int minimumDepth ( ) { return minimumDepth ( root ) ; } int minimumDepth ( Node root ) { if ( root == null ) return 0 ; if ( root . left == null && root . right == null ) return 1 ; if ( root . left == null ) return minimumDepth ( root . right ) + 1 ; if ( root . right == null ) return minimumDepth ( root . left ) + 1 ; return Math . min ( minimumDepth ( root . left ) , minimumDepth ( root . right ) ) + 1 ; } public static void main ( String args [ ] ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; System . out . println ( " The ▁ minimum ▁ depth ▁ of ▁ " + " binary ▁ tree ▁ is ▁ : ▁ " + tree . minimumDepth ( ) ) ; } }
Remove an occurrence of most frequent array element exactly K times | Java program to implement the above approach ; Function to print the most frequent array element exactly K times ; Stores frequency array element ; Count frequency of array element ; Maximum array element ; Traverse the Map ; Find the element with maximum frequency ; If the frequency is maximum , store that number in element ; Print element as it contains the element having highest frequency ; Decrease the frequency of the maximum array element ; Reduce the number of operations ; Driver code ; Given array ; Size of the array ; Given K
import java . util . * ; class GFG { static void maxFreqElements ( int arr [ ] , int N , int K ) { HashMap < Integer , Integer > mp = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( mp . containsKey ( arr [ i ] ) ) { mp . put ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) ; } else { mp . put ( arr [ i ] , 1 ) ; } } while ( K > 0 ) { int max = 0 ; int element = 0 ; for ( Map . Entry < Integer , Integer > i : mp . entrySet ( ) ) { if ( i . getValue ( ) > max ) { max = i . getValue ( ) ; element = i . getKey ( ) ; } } System . out . print ( element + " ▁ " ) ; if ( mp . containsKey ( element ) ) { mp . put ( element , mp . get ( element ) + 1 ) ; } else { mp . put ( element , 1 ) ; } K -- ; } } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 3 , 2 , 1 , 4 , 1 } ; int N = arr . length ; int K = 2 ; maxFreqElements ( arr , N , K ) ; } }
Maximize difference between maximum and minimum array elements after K operations | Java program to implement the above approach ; Reverse array ; Function to find the maximum difference between the maximum and minimum in the array after K operations ; Stores maximum difference between largest and smallest array element ; Sort the array in descending order ; Traverse the array arr [ ] ; Update maxDiff ; Driver Code
import java . util . * ; class GFG { static int [ ] reverse ( int a [ ] ) { int i , n = a . length , t ; for ( i = 0 ; i < n / 2 ; i ++ ) { t = a [ i ] ; a [ i ] = a [ n - i - 1 ] ; a [ n - i - 1 ] = t ; } return a ; } static int maxDiffLargSmallOper ( int arr [ ] , int N , int K ) { int maxDiff = 0 ; Arrays . sort ( arr ) ; arr = reverse ( arr ) ; for ( int i = 0 ; i <= Math . min ( K , N - 1 ) ; i ++ ) { maxDiff += arr [ i ] ; } return maxDiff ; } public static void main ( String [ ] args ) { int arr [ ] = { 7 , 7 , 7 , 7 } ; int N = arr . length ; int K = 1 ; System . out . print ( maxDiffLargSmallOper ( arr , N , K ) ) ; } }
Minimize cost to convert all characters of a binary string to 0 s | Java program to implement the above approach ; Function to get the minimum Cost to convert all characters of given string to 0 s ; Stores the range of indexes of characters that need to be flipped ; Stores the number of times current character is flipped ; Stores minimum cost to get the required string ; Traverse the given string ; Remove all value from pq whose value is less than i ; Update flip ; Get the current number ; If current character is flipped odd times ; If current character contains non - zero value ; Update flip ; Update cost ; Append R [ i ] into pq ; Driver Code ; Function call
import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { public static int minCost ( String s , int R [ ] , int C [ ] , int N ) { char ch [ ] = s . toCharArray ( ) ; PriorityQueue < Integer > pq = new PriorityQueue < > ( ) ; int flip = 0 ; int cost = 0 ; for ( int i = 0 ; i < N ; i ++ ) { while ( pq . size ( ) > 0 && pq . peek ( ) < i ) { pq . poll ( ) ; flip -- ; } int cn = ch [ i ] - '0' ; if ( flip % 2 == 1 ) cn = 1 - cn ; if ( cn == 1 ) { flip ++ ; cost += C [ i ] ; pq . add ( R [ i ] ) ; } } return cost ; } public static void main ( String [ ] args ) { int N = 4 ; String s = "1010" ; int R [ ] = { 1 , 2 , 2 , 3 } ; int C [ ] = { 3 , 1 , 2 , 3 } ; System . out . println ( minCost ( s , R , C , N ) ) ; } }
Find Minimum Depth of a Binary Tree | Java program to find minimum depth of a given Binary Tree ; A binary Tree node ; A queue item ( Stores pointer tonode and an integer ) ; Iterative method to find minimum depth of Binary Tree ; Corner Case ; Create an empty queue for level order traversal ; Enqueue Root and initialize depth as 1 ; Do level order traversal ; Remove the front queue item ; Get details of the remove item ; If this is the first leaf node seen so far Then return its depth as answer ; If left subtree is not null , add it to queue ; If right subtree is not null , add it to queue ; Utility function to create a new tree Node ; Driver Code ; Let us create binary tree shown in above diagram
import java . util . * ; class GFG { static class Node { int data ; Node left , right ; } static class qItem { Node node ; int depth ; public qItem ( Node node , int depth ) { this . node = node ; this . depth = depth ; } } static int minDepth ( Node root ) { if ( root == null ) return 0 ; Queue < qItem > q = new LinkedList < > ( ) ; qItem qi = new qItem ( root , 1 ) ; q . add ( qi ) ; while ( q . isEmpty ( ) == false ) { qi = q . peek ( ) ; q . remove ( ) ; Node node = qi . node ; int depth = qi . depth ; if ( node . left == null && node . right == null ) return depth ; if ( node . left != null ) { qi . node = node . left ; qi . depth = depth + 1 ; q . add ( qi ) ; } if ( node . right != null ) { qi . node = node . right ; qi . depth = depth + 1 ; q . add ( qi ) ; } } return 0 ; } 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 ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 5 ) ; System . out . println ( minDepth ( root ) ) ; } }
Maximum Manhattan distance between a distinct pair from N coordinates | Java program for the above approach ; Pair class ; Function to calculate the maximum Manhattan distance ; ArrayLists to store maximum and minimum of all the four forms ; Sorting both the ArrayLists ; Driver Code ; Given Co - ordinates ; Function call
import java . io . * ; import java . util . * ; class GFG { public static class Pair { int x ; int y ; Pair ( int x , int y ) { this . x = x ; this . y = y ; } } static void MaxDist ( ArrayList < Pair > A , int N ) { ArrayList < Integer > V = new ArrayList < > ( ) ; ArrayList < Integer > V1 = new ArrayList < > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { V . add ( A . get ( i ) . x + A . get ( i ) . y ) ; V1 . add ( A . get ( i ) . x - A . get ( i ) . y ) ; } Collections . sort ( V ) ; Collections . sort ( V1 ) ; int maximum = Math . max ( ( V . get ( V . size ( ) - 1 ) - V . get ( 0 ) ) , ( V1 . get ( V1 . size ( ) - 1 ) - V1 . get ( 0 ) ) ) ; System . out . println ( maximum ) ; } public static void main ( String [ ] args ) { int n = 3 ; ArrayList < Pair > al = new ArrayList < > ( ) ; Pair p1 = new Pair ( 1 , 2 ) ; al . add ( p1 ) ; Pair p2 = new Pair ( 2 , 3 ) ; al . add ( p2 ) ; Pair p3 = new Pair ( 3 , 4 ) ; al . add ( p3 ) ; MaxDist ( al , n ) ; } }
Maximum distance between two points in coordinate plane using Rotating Caliper 's Method |  ; Function calculates distance between two points ; Function to find the maximum distance between any two points ; Iterate over all possible pairs ; Update max ; Return actual distance ; Driver Code ; Number of points ; Given points ; Function Call
import java . awt . * ; import java . util . ArrayList ; public class Main { static long dist ( Point p1 , Point p2 ) { long x0 = p1 . x - p2 . x ; long y0 = p1 . y - p2 . y ; return x0 * x0 + y0 * y0 ; } static double maxDist ( Point p [ ] ) { int n = p . length ; double max = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { max = Math . max ( max , dist ( p [ i ] , p [ j ] ) ) ; } } return Math . sqrt ( max ) ; } public static void main ( String [ ] args ) { int n = 5 ; Point p [ ] = new Point [ n ] ; p [ 0 ] = new Point ( 4 , 0 ) ; p [ 1 ] = new Point ( 0 , 2 ) ; p [ 2 ] = new Point ( - 1 , - 7 ) ; p [ 3 ] = new Point ( 1 , 10 ) ; p [ 4 ] = new Point ( 2 , - 3 ) ; System . out . println ( maxDist ( p ) ) ; } }
Reorder an array such that sum of left half is not equal to sum of right half | Java program for the above approach ; Function to print the required reordering of array if possible ; Sort the array in increasing order ; If all elements are equal , then it is not possible ; Else print the sorted array arr [ ] ; Driver code ; Given array ; Function call
import java . util . * ; class GFG { public static void printArr ( int [ ] arr , int n ) { Arrays . sort ( arr ) ; if ( arr [ 0 ] == arr [ n - 1 ] ) { System . out . println ( " No " ) ; } else { System . out . println ( " Yes " ) ; for ( int i = 0 ; i < n ; i ++ ) { System . out . print ( arr [ i ] + " ▁ " ) ; } } } public static void main ( String [ ] args ) { int arr [ ] = { 1 , 2 , 2 , 1 , 3 , 1 } ; int N = arr . length ; printArr ( arr , N ) ; } }
Find Minimum Depth of a Binary Tree | Class containing left and right child of current Node and key value ; Root of the Binary Tree ; Function to calculate the minimum depth of the tree ; Driver program to test above functions
class Node { int data ; Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } public class MinimumTreeHeight { Node root ; int minimumDepth ( ) { return minimumDepth ( root , 0 ) ; } int minimumDepth ( Node root , int level ) { if ( root == null ) return level ; level ++ ; return Math . min ( minimumDepth ( root . left , level ) , minimumDepth ( root . right , level ) ) ; } public static void main ( String args [ ] ) { MinimumTreeHeight tree = new MinimumTreeHeight ( ) ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; System . out . println ( " The ▁ minimum ▁ depth ▁ of ▁ " + " binary ▁ tree ▁ is ▁ : ▁ " + tree . minimumDepth ( ) ) ; } }