codeparrot/xlcost-text-to-code huggingface dataset:
Maximum points collected by two persons allowed to meet once | C # program to find maximum points that can be collected by two persons in a matrix . ; To store points collected by Person P1 when he / she begins journy from start and from end . ; To store points collected by Person P2 when he / she begins journey from start and from end . ; Table for P1 's journey from  start to meeting cell ; Table for P1 's journey from  end to meet cell ; Table for P2 's journey from start to meeting cell ; Table for P2 's journey from end to meeting cell ; Now iterate over all meeting positions ( i , j ) ; Driver code ; input the calories burnt matrix
using System ; class GFG { static readonly int M = 3 ; static readonly int N = 3 ; static int findMaxPoints ( int [ , ] A ) { int [ , ] P1S = new int [ M + 2 , N + 2 ] ; int [ , ] P1E = new int [ M + 2 , N + 2 ] ; int [ , ] P2S = new int [ M + 2 , N + 2 ] ; int [ , ] P2E = new int [ M + 2 , N + 2 ] ; for ( int i = 1 ; i <= N ; i ++ ) for ( int j = 1 ; j <= M ; j ++ ) P1S [ i , j ] = Math . Max ( P1S [ i - 1 , j ] , P1S [ i , j - 1 ] ) + A [ i - 1 , j - 1 ] ; for ( int i = N ; i >= 1 ; i -- ) for ( int j = M ; j >= 1 ; j -- ) P1E [ i , j ] = Math . Max ( P1E [ i + 1 , j ] , P1E [ i , j + 1 ] ) + A [ i - 1 , j - 1 ] ; for ( int i = N ; i >= 1 ; i -- ) for ( int j = 1 ; j <= M ; j ++ ) P2S [ i , j ] = Math . Max ( P2S [ i + 1 , j ] , P2S [ i , j - 1 ] ) + A [ i - 1 , j - 1 ] ; for ( int i = 1 ; i <= N ; i ++ ) for ( int j = M ; j >= 1 ; j -- ) P2E [ i , j ] = Math . Max ( P2E [ i - 1 , j ] , P2E [ i , j + 1 ] ) + A [ i - 1 , j - 1 ] ; int ans = 0 ; for ( int i = 2 ; i < N ; i ++ ) { for ( int j = 2 ; j < M ; j ++ ) { int op1 = P1S [ i , j - 1 ] + P1E [ i , j + 1 ] + P2S [ i + 1 , j ] + P2E [ i - 1 , j ] ; int op2 = P1S [ i - 1 , j ] + P1E [ i + 1 , j ] + P2S [ i , j - 1 ] + P2E [ i , j + 1 ] ; ans = Math . Max ( ans , Math . Max ( op1 , op2 ) ) ; } } return ans ; } public static void Main ( String [ ] args ) { int [ , ] A = { { 100 , 100 , 100 } , { 100 , 1 , 100 } , { 100 , 100 , 100 } } ; Console . Write ( " Max ▁ Points ▁ : ▁ " + findMaxPoints ( A ) ) ; } }
Longest subsequence such that difference between adjacents is one | C # program to find the longest subsequence such that the difference between adjacent elements of the subsequence is one . ; Function to find the length of longest subsequence ; Initialize the dp [ ] array with 1 as a single element will be of 1 length ; Start traversing the given array ; Compare with all the previous elements ; If the element is consecutive then consider this subsequence and update dp [ i ] if required . ; Longest length will be the maximum value of dp array . ; Driver code ; Longest subsequence with one difference is { 1 , 2 , 3 , 4 , 3 , 2 }
using System ; class GFG { static int longestSubseqWithDiffOne ( int [ ] arr , int n ) { int [ ] dp = new int [ n ] ; for ( int i = 0 ; i < n ; i ++ ) dp [ i ] = 1 ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j < i ; j ++ ) { if ( ( arr [ i ] == arr [ j ] + 1 ) || ( arr [ i ] == arr [ j ] - 1 ) ) dp [ i ] = Math . Max ( dp [ i ] , dp [ j ] + 1 ) ; } } int result = 1 ; for ( int i = 0 ; i < n ; i ++ ) if ( result < dp [ i ] ) result = dp [ i ] ; return result ; } public static void Main ( ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 , 3 , 2 } ; int n = arr . Length ; Console . Write ( longestSubseqWithDiffOne ( arr , n ) ) ; } }
Non | C # program to count number of ways to connect n ( wheren is even ) points on a circle such that no two connecting lines cross each other and every point is connected with one other point . ; A dynamic programming based function to find nth Catalan number ; Table to store results of subproblems ; Initialize first two values in table ; Fill entries in catalan [ ] using recursive formula ; Return last entry ; Returns count of ways to connect n points on a circle such that no two connecting lines cross each other and every point is connected with one other point . ; Throw error if n is odd ; Else return n / 2 'th  Catalan number ; Driver Code
using System ; class GFG { static int catalanDP ( int n ) { int [ ] catalan = new int [ n + 1 ] ; catalan [ 0 ] = catalan [ 1 ] = 1 ; for ( int i = 2 ; i <= n ; i ++ ) { catalan [ i ] = 0 ; for ( int j = 0 ; j < i ; j ++ ) catalan [ i ] += catalan [ j ] * catalan [ i - j - 1 ] ; } return catalan [ n ] ; } static int countWays ( int n ) { if ( n < 1 ) { Console . WriteLine ( " Invalid " ) ; return 0 ; } return catalanDP ( n / 2 ) ; } static public void Main ( ) { Console . WriteLine ( countWays ( 6 ) + " ▁ " ) ; } }
Construction of Longest Increasing Subsequence ( LIS ) and printing LIS sequence |  ; int [ ] array = { 10 , 2 , 9 , 3 , 5 , 4 , 6 , 8 } ; int [ ] array = { 10 , 9 , 8 , 6 , 5 , 4 } ; ; Compare previous highest subsequence ; Print list
using System ; using System . Collections . Generic ; class longestIncreasingSubsequence { public static void Main ( String [ ] args ) { int [ ] array = { 10 , 22 , 9 , 33 , 21 , 50 , 41 , 60 , 80 } ; List < int > list = new List < int > ( ) ; List < int > longestList = new List < int > ( ) ; int currentMax ; int highestCount = 0 ; for ( int i = 0 ; i < array . Length ; i ++ ) { currentMax = int . MinValue ; for ( int j = i ; j < array . Length ; j ++ ) { if ( array [ j ] > currentMax ) { list . Add ( array [ j ] ) ; currentMax = array [ j ] ; } } if ( highestCount < list . Count ) { highestCount = list . Count ; longestList = new List < int > ( list ) ; } list . Clear ( ) ; } Console . WriteLine ( ) ; Console . WriteLine ( " The ▁ longest ▁ subsequence " ) ; foreach ( int itr in longestList ) { Console . Write ( itr + " ▁ " ) ; } Console . WriteLine ( ) ; Console . WriteLine ( " Length ▁ of ▁ LIS : ▁ " + highestCount ) ; } }
Ways to arrange Balls such that adjacent balls are of different types | C # program to count number of ways to arrange three types of balls such that no two balls of same color are adjacent to each other ; table to store to store results of subproblems ; Returns count of arrangements where last placed ball is ' last ' . ' last ' is 0 for ' p ' , 1 for ' q ' and 2 for ' r ' ; if number of balls of any color becomes less than 0 the number of ways arrangements is 0. ; If last ball required is of type P and the number of balls of P type is 1 while number of balls of other color is 0 the number of ways is 1. ; Same case as above for ' q ' and ' r ' ; If this subproblem is already evaluated ; if last ball required is P and the number of ways is the sum of number of ways to form sequence with ' p - 1' P balls , q Q balss and r R balls ending with Q and R . ; Same as above case for ' q ' and ' r ' ; ( last == 2 ) ; Returns count of required arrangements ; Initialize ' dp ' array ; Three cases arise : return countWays ( p , q , r , 0 ) + Last required balls is type P countWays ( p , q , r , 1 ) + Last required balls is type Q countWays ( p , q , r , 2 ) ; Last required balls is type R ; Driver code
using System ; class GFG { static int MAX = 101 ; static int [ , , , ] dp = new int [ MAX , MAX , MAX , 4 ] ; static int countWays ( int p , int q , int r , int last ) { if ( p < 0 q < 0 r < 0 ) return 0 ; if ( p == 1 && q == 0 && r == 0 && last == 0 ) return 1 ; if ( p == 0 && q == 1 && r == 0 && last == 1 ) return 1 ; if ( p == 0 && q == 0 && r == 1 && last == 2 ) return 1 ; if ( dp [ p , q , r , last ] != - 1 ) return dp [ p , q , r , last ] ; if ( last == 0 ) dp [ p , q , r , last ] = countWays ( p - 1 , q , r , 1 ) + countWays ( p - 1 , q , r , 2 ) ; else if ( last == 1 ) dp [ p , q , r , last ] = countWays ( p , q - 1 , r , 0 ) + countWays ( p , q - 1 , r , 2 ) ; else dp [ p , q , r , last ] = countWays ( p , q , r - 1 , 0 ) + countWays ( p , q , r - 1 , 1 ) ; return dp [ p , q , r , last ] ; } static int countUtil ( int p , int q , int r ) { for ( int i = 0 ; i < MAX ; i ++ ) for ( int j = 0 ; j < MAX ; j ++ ) for ( int k = 0 ; k < MAX ; k ++ ) for ( int l = 0 ; l < 4 ; l ++ ) dp [ i , j , k , l ] = - 1 ; } static void Main ( ) { int p = 1 , q = 1 , r = 1 ; Console . WriteLine ( countUtil ( p , q , r ) ) ; } }
Count Derangements ( Permutation such that no element appears in its original position ) | A Naive Recursive C # program to count derangements ; Function to count derangements ; Base cases ; countDer ( n ) = ( n - 1 ) [ countDer ( n - 1 ) + der ( n - 2 ) ] ; Driver Code
using System ; class GFG { static int countDer ( int n ) { if ( n == 1 ) return 0 ; if ( n == 2 ) return 1 ; return ( n - 1 ) * ( countDer ( n - 1 ) + countDer ( n - 2 ) ) ; } public static void Main ( ) { int n = 4 ; Console . Write ( " Count ▁ of ▁ Derangements ▁ is ▁ " + countDer ( n ) ) ; } }
Count Derangements ( Permutation such that no element appears in its original position ) | A Dynamic programming based C # program to count derangements ; Function to count derangements ; Create an array to store counts for subproblems ; Base cases ; Fill der [ 0. . n ] in bottom up manner using above recursive formula ; Return result for n ; Driver code
using System ; class GFG { static int countDer ( int n ) { int [ ] der = new int [ n + 1 ] ; der [ 1 ] = 0 ; der [ 2 ] = 1 ; for ( int i = 3 ; i <= n ; ++ i ) der [ i ] = ( i - 1 ) * ( der [ i - 1 ] + der [ i - 2 ] ) ; return der [ n ] ; } public static void Main ( ) { int n = 4 ; Console . Write ( " Count ▁ of ▁ Derangements ▁ is ▁ " + countDer ( n ) ) ; } }
Find number of solutions of a linear equation of n variables | A Dynamic programming based C # program to find number of non - negative solutions for a given linear equation ; Returns counr of solutions for given rhs and coefficients coeff [ 0. . n - 1 ] ; Create and initialize a table to store results of subproblems ; Fill table in bottom up manner ; Driver code
using System ; class GFG { static int countSol ( int [ ] coeff , int n , int rhs ) { int [ ] dp = new int [ rhs + 1 ] ; dp [ 0 ] = 1 ; for ( int i = 0 ; i < n ; i ++ ) for ( int j = coeff [ i ] ; j <= rhs ; j ++ ) dp [ j ] += dp [ j - coeff [ i ] ] ; return dp [ rhs ] ; } public static void Main ( ) { int [ ] coeff = { 2 , 2 , 5 } ; int rhs = 4 ; int n = coeff . Length ; Console . Write ( countSol ( coeff , n , rhs ) ) ; } }
Find all distinct palindromic sub | C # program to find all distinct palindrome sub - strings of a given string ; Function to print all distinct palindrome sub - strings of s ; table for storing results ( 2 rows for odd - and even - length palindromes ; Find all sub - string palindromes from the given input string insert ' guards ' to iterate easily over s ; int rp = 0 ; length of ' palindrome ▁ radius ' ; Attempt to expand palindrome centered at i ; Incrementing the length of palindromic radius as and when we find vaid palindrome ; Assigning the found palindromic length to odd / even length array ; remove ' guards ' ; Put all obtained palindromes in a hash map to find only distinct palindromess ; printing all distinct palindromes from hash map ; Driver Code
using System ; using System . Collections . Generic ; class GFG { public static void palindromeSubStrs ( string s ) { Dictionary < string , int > m = new Dictionary < string , int > ( ) ; 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 [ i - rp - 1 ] == s [ i + j + rp ] ) 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 ) ; if ( ! m . ContainsKey ( s . Substring ( 0 , 1 ) ) ) m . Add ( s . Substring ( 0 , 1 ) , 1 ) ; else m [ s . Substring ( 0 , 1 ) ] ++ ; for ( int i = 1 ; i < n ; i ++ ) { for ( int j = 0 ; j <= 1 ; j ++ ) for ( int rp = R [ j , i ] ; rp > 0 ; rp -- ) { if ( ! m . ContainsKey ( s . Substring ( i - rp - 1 , 2 * rp + j ) ) ) m . Add ( s . Substring ( i - rp - 1 , 2 * rp + j ) , 1 ) ; else m [ s . Substring ( i - rp - 1 , 2 * rp + j ) ] ++ ; } if ( ! m . ContainsKey ( s . Substring ( i , 1 ) ) ) m . Add ( s . Substring ( i , 1 ) , 1 ) ; else m [ s . Substring ( i , 1 ) ] ++ ; } Console . WriteLine ( " Below ▁ are ▁ " + ( m . Count ) ) ; foreach ( KeyValuePair < string , int > ii in m ) Console . WriteLine ( ii . Key ) ; } public static void Main ( string [ ] args ) { palindromeSubStrs ( " abaaa " ) ; } }
Largest value in each level of Binary Tree | Set | C # implementation to print largest value in each level of Binary Tree ; structure of a node of binary tree ; function to get a new node ; allocate space ; put in the data ; function to print largest value in each level of Binary Tree ; if tree is empty ; push root to the queue ' q ' ; node count for the current level ; if true then all the nodes of the tree have been traversed ; maximum element for the current level ; get the front element from ' q ' ; remove front element from ' q ' ; if true , then update ' max ' ; if left child exists ; if right child exists ; print maximum element of current level ; Driver code ; Construct a Binary Tree 4 / \ 9 2 / \ \ 3 5 7 ; Function call
using System ; using System . Collections . Generic ; class GfG { class Node { public int data ; public Node left = null ; public 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 Queue < Node > ( ) ; int nc , max ; q . Enqueue ( root ) ; while ( true ) { nc = q . Count ; if ( nc == 0 ) break ; max = int . MinValue ; while ( nc != 0 ) { Node front = q . Peek ( ) ; q . Dequeue ( ) ; if ( max < front . data ) max = front . data ; if ( front . left != null ) q . Enqueue ( front . left ) ; if ( front . right != null ) q . Enqueue ( front . right ) ; nc -- ; } Console . Write ( 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 ) ; } }
Populate Inorder Successor for all nodes | C # program to populate inorder traversal of all nodes ; A binary tree node ; Set next of p and all descendants of p by traversing them in reverse Inorder ; The first visited node will be the rightmost node next of the rightmost node will be NULL ; First set the next pointer in right subtree ; Set the next as previously visited node in reverse Inorder ; Change the prev for subsequent node ; Finally , set the next pointer in left subtree ; Constructed binary tree is 10 / \ 8 12 / 3 ; Populates nextRight pointer in all nodes ; Let us see the populated values ; - 1 is printed if there is no successor
using System ; class BinaryTree { class Node { public int data ; public Node left , right , next ; public Node ( int item ) { data = item ; left = right = next = null ; } } Node root ; static Node next = null ; void populateNext ( Node node ) { if ( node != null ) { populateNext ( node . right ) ; node . next = next ; next = node ; populateNext ( node . left ) ; } } static public 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 ; Console . WriteLine ( " Next ▁ of ▁ " + ptr . data + " ▁ is : ▁ " + print ) ; ptr = ptr . next ; } } }
Dice Throw | DP | C # program to find number of ways to get sum ' x ' with ' n ' dice where every dice has ' m ' faces ; The main function that returns number of ways to get sum ' x ' with ' n ' dice and ' m ' with m faces . ; Create a table to store results of subproblems . row and column are used for simpilicity ( Number of dice is directly used as row index and sum is directly used as column index ) . The entries in 0 th row and 0 th column are never used . ; Table entries for only one dice ; Fill rest of the entries in table using recursive relation i : number of dice , j : sum ; Return value ; Driver Code
using System ; class GFG { static int findWays ( int m , int n , int x ) { int [ , ] table = new int [ n + 1 , x + 1 ] ; for ( int i = 0 ; i <= n ; i ++ ) for ( int j = 0 ; j <= x ; j ++ ) table [ i , j ] = 0 ; 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 <= m && k < j ; k ++ ) table [ i , j ] += table [ i - 1 , j - k ] ; return table [ n , x ] ; } public static void Main ( ) { Console . WriteLine ( findWays ( 4 , 2 , 1 ) ) ; Console . WriteLine ( findWays ( 2 , 2 , 3 ) ) ; Console . WriteLine ( findWays ( 6 , 3 , 8 ) ) ; Console . WriteLine ( findWays ( 4 , 2 , 5 ) ) ; Console . WriteLine ( findWays ( 4 , 3 , 5 ) ) ; } }
Dice Throw | DP | C # program The main function that returns number of ways to get sum ' x ' with ' n ' dice and ' m ' with m faces . ; * * Count ways * * @ param f * @ param d * @ param s * @ return ; Create a table to store results of subproblems . One extra row and column are used for simpilicity ( Number of dice is directly used as row index and sum is directly used as column index ) . The entries in 0 th row and 0 th column are never used . ; Table entries for no dices If you do not have any data , then the value must be 0 , so the result is 1 ; Iterate over dices ; Iterate over sum ; The result is obtained in two ways , pin the current dice and spending 1 of the value , so we have mem [ i - 1 , j - 1 ] remaining combinations , to find the remaining combinations we would have to pin the values ? ? above 1 then we use mem [ i , j - 1 ] to sum all combinations that pin the remaining j - 1 's. But there is a way, when "j-f-1> = 0" we would be adding  extra combinations, so we remove the combinations that only pin the extrapolated dice face and  subtract the extrapolated combinations. ; Driver code
using System ; 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 ) { Console . WriteLine ( findWays ( 4 , 2 , 1 ) ) ; Console . WriteLine ( findWays ( 2 , 2 , 3 ) ) ; Console . WriteLine ( findWays ( 6 , 3 , 8 ) ) ; Console . WriteLine ( findWays ( 4 , 2 , 5 ) ) ; Console . WriteLine ( findWays ( 4 , 3 , 5 ) ) ; } }
Minimum insertions to form a palindrome | DP | A Naive recursive C # program to find minimum number insertions needed to make a string palindrom ; Recursive function to find minimum number of insertions ; Base Cases ; Check if the first and last characters are same . On the basis of the comparison result , decide which subrpoblem ( s ) to call ; Driver Code
using System ; class GFG { static int findMinInsertions ( char [ ] str , int l , int h ) { if ( l > h ) return int . MaxValue ; 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 ) : ( Math . Min ( findMinInsertions ( str , l , h - 1 ) , findMinInsertions ( str , l + 1 , h ) ) + 1 ) ; } public static void Main ( ) { string str = " geeks " ; Console . WriteLine ( findMinInsertions ( str . ToCharArray ( ) , 0 , str . Length - 1 ) ) ; } }
Longest Palindromic Subsequence | DP | C # program of the above approach ; A utility function to get max of two integers ; Returns the length of the longest palindromic subsequence in seq ; Base Case 1 : If there is only 1 character ; Base Case 2 : If there are only 2 characters and both are same ; If the first and last characters match ; If the first and last characters do not match ; Driver program to test above function
using System ; public 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 seq = " GEEKSFORGEEKS " ; int n = seq . Length ; Console . Write ( " The ▁ length ▁ of ▁ the ▁ LPS ▁ is ▁ " + lps ( seq . ToCharArray ( ) , 0 , n - 1 ) ) ; } }
Smallest value in each level of Binary Tree | C # program to print smallest element in each level of binary tree . ; A Binary Tree Node ; return height of tree ; Inorder Traversal Search minimum element in each level and store it into vector array . ; height of tree for the size of vector array ; vector for store all minimum of every level ; save every level minimum using inorder traversal ; print every level minimum ; Utility function to create a new tree node ; Driver Code ; Let us create binary tree shown in above diagram ; 7 / \ 6 5 / \ / \ 4 3 2 1
using System ; class GFG { static int INT_MAX = ( int ) 10e6 ; public class Node { public int data ; public 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 ] ; for ( i = 0 ; i < n ; i ++ ) res [ i ] = INT_MAX ; printPerLevelMinimum ( root , res , 0 ) ; Console . Write ( " Every ▁ level ▁ minimum ▁ is STRNEWLINE " ) ; for ( i = 0 ; i < n ; i ++ ) { Console . Write ( " level ▁ " + i + " ▁ min ▁ is ▁ = ▁ " + res [ i ] + " STRNEWLINE " ) ; } } 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 ) ; } }