codeparrot/xlcost-text-to-code huggingface dataset:
Find depth of the deepest odd level leaf node | C # program to find depth of the deepest odd level leaf node of binary tree ; tree node ; returns a new tree Node ; return max odd number depth of leaf node ; create a queue for level order traversal ; traverse until the queue is empty ; traverse for complete level ; check if the node is leaf node and level is odd if level is odd , then update result ; check for left child ; check for right child ; Driver Code ; construct a tree
using System ; using System . Collections . Generic ; class GFG { public class Node { public int data ; public Node left , right ; } ; static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = temp . right = null ; return temp ; } static int maxOddLevelDepth ( Node root ) { if ( root == null ) return 0 ; Queue < Node > q = new Queue < Node > ( ) ; q . Enqueue ( root ) ; int result = int . MaxValue ; int level = 0 ; while ( q . Count != 0 ) { int size = q . Count ; level += 1 ; while ( size > 0 ) { Node temp = q . Peek ( ) ; q . Dequeue ( ) ; if ( temp . left == null && temp . right == null && ( level % 2 != 0 ) ) { result = level ; } if ( temp . left != null ) { q . Enqueue ( temp . left ) ; } if ( temp . right != null ) { q . Enqueue ( temp . right ) ; } size -= 1 ; } } return result ; } public static void Main ( String [ ] args ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . right . left = newNode ( 5 ) ; root . right . right = newNode ( 6 ) ; root . right . left . right = newNode ( 7 ) ; root . right . right . right = newNode ( 8 ) ; root . right . left . right . left = newNode ( 9 ) ; root . right . right . right . right = newNode ( 10 ) ; root . right . right . right . right . left = newNode ( 11 ) ; int result = maxOddLevelDepth ( root ) ; if ( result == int . MaxValue ) Console . WriteLine ( " No ▁ leaf ▁ node ▁ at ▁ odd ▁ level " ) ; else { Console . Write ( result ) ; Console . WriteLine ( " ▁ is ▁ the ▁ required ▁ depth ▁ " ) ; } } }
Nth Term of a Fibonacci Series of Primes formed by concatenating pairs of Primes in a given range | C # program to implement the above approach ; Stores at each index if it 's a  prime or not  ; Sieve of Eratosthenes to generate all possible primes ; If p is a prime ; Set all multiples of p as non - prime ; Function to generate the required Fibonacci Series ; Stores all primes between n1 and n2 ; Generate all primes between n1 and n2 ; Stores all concatenations of each pair of primes ; Generate all concatenations of each pair of primes ; Stores the primes out of the numbers generated above ; Store the unique primes ; Find the minimum ; Find the minimum ; Find N ; Print the N - th term of the Fibonacci Series ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int [ ] prime = new int [ 100001 ] ; static void SieveOfEratosthenes ( ) { for ( int i = 0 ; i < 100001 ; i ++ ) prime [ i ] = 1 ; int p = 2 ; while ( p * p <= 100000 ) { if ( prime [ p ] == 1 ) { for ( int i = p * p ; i < 100001 ; i += p ) prime [ i ] = 0 ; } p += 1 ; } } static int join ( int a , int b ) { int mul = 1 ; int bb = b ; while ( b != 0 ) { mul *= 10 ; b /= 10 ; } a *= mul ; a += bb ; return a ; } static void fibonacciOfPrime ( int n1 , int n2 ) { SieveOfEratosthenes ( ) ; List < int > initial = new List < int > ( ) ; for ( int i = n1 ; i <= n2 ; i ++ ) if ( prime [ i ] == 1 ) initial . Add ( i ) ; List < int > now = new List < int > ( ) ; for ( int i = 0 ; i < initial . Count ; i ++ ) { for ( int j = 0 ; j < initial . Count ; j ++ ) { int a = initial [ i ] ; int b = initial [ j ] ; if ( a != b ) { int C = join ( a , b ) ; now . Add ( C ) ; } } } List < int > current = new List < int > ( ) ; for ( int i = 0 ; i < now . Count ; i ++ ) if ( prime [ now [ i ] ] == 1 ) current . Add ( now [ i ] ) ; int [ ] cnt = new int [ 1000009 ] ; for ( int i = 0 ; i < 1000001 ; i ++ ) cnt [ i ] = 0 ; List < int > current_set = new List < int > ( ) ; for ( int i = 0 ; i < current . Count ; i ++ ) { cnt [ current [ i ] ] ++ ; if ( cnt [ current [ i ] ] == 1 ) current_set . Add ( current [ i ] ) ; } long first = 1000000000 ; for ( int i = 0 ; i < current_set . Count ; i ++ ) first = Math . Min ( first , current_set [ i ] ) ; long second = 0 ; for ( int i = 0 ; i < current_set . Count ; i ++ ) second = Math . Max ( second , current_set [ i ] ) ; int count = current_set . Count - 1 ; long curr = 1 ; long c = 0 ; while ( curr < count ) { c = first + second ; first = second ; second = c ; curr += 1 ; } Console . WriteLine ( c ) ; } static void Main ( ) { int x = 2 ; int y = 40 ; fibonacciOfPrime ( x , y ) ; } }
Count of Array elements greater than all elements on its left and next K elements on its right | C # program to implement the above approach ; Function to print the count of Array elements greater than all elements on its left and next K elements on its right ; Iterate over the array ; If the stack is not empty and the element at the top of the stack is smaller than arr [ i ] ; Store the index of next greater element ; Pop the top element ; Insert the current index ; Stores the count ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int countElements ( int [ ] arr , int n , int k ) { Stack < int > s = new Stack < int > ( ) ; int [ ] next_greater = new int [ n + 1 ] ; Array . Fill ( next_greater , n ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( s . Count == 0 ) { s . Push ( i ) ; continue ; } while ( s . Count != 0 && arr [ s . Peek ( ) ] < arr [ i ] ) { next_greater [ s . Peek ( ) ] = i ; s . Pop ( ) ; } s . Push ( i ) ; } int count = 0 ; int maxi = Int32 . MinValue ; for ( int i = 0 ; i < n ; i ++ ) { if ( next_greater [ i ] - i > k && maxi < arr [ i ] ) { maxi = Math . Max ( maxi , arr [ i ] ) ; count ++ ; } } return count ; } static void Main ( ) { int [ ] arr = { 4 , 2 , 3 , 6 , 4 , 3 , 2 } ; int K = 2 ; int n = arr . Length ; Console . Write ( countElements ( arr , n , K ) ) ; } }
Maximize length of Subarray of 1 's after removal of a pair of consecutive Array elements | C # program to find the maximum count of 1 s ; If arr [ i - 2 ] = = 1 then we increment the count of occurences of 1 's ; Else we initialise the count with 0 ; If arr [ i + 2 ] = = 1 then we increment the count of occurences of 1 's ; Else we initialise the count with 0 ; We get the maximum count by skipping the current and the next element . ; Driver code
using System ; class GFG { static void maxLengthOf1s ( int [ ] arr , int n ) { int [ ] prefix = new int [ n ] ; for ( int i = 2 ; i < n ; i ++ ) { if ( arr [ i - 2 ] == 1 ) prefix [ i ] = prefix [ i - 1 ] + 1 ; else prefix [ i ] = 0 ; } int [ ] suffix = new int [ n ] ; for ( int i = n - 3 ; i >= 0 ; i -- ) { if ( arr [ i + 2 ] == 1 ) suffix [ i ] = suffix [ i + 1 ] + 1 ; else suffix [ i ] = 0 ; } int ans = 0 ; for ( int i = 0 ; i < n - 1 ; i ++ ) { ans = Math . Max ( ans , prefix [ i + 1 ] + suffix [ i ] ) ; } Console . WriteLine ( ans ) ; } static void Main ( ) { int n = 6 ; int [ ] arr = { 1 , 1 , 1 , 0 , 1 , 1 } ; maxLengthOf1s ( arr , n ) ; } }
Minimum number of operations required to obtain a given Binary String | C # program to implement the above approach ; Function to find the minimum number of operations required to obtain the string s ; Iterate the string s ; If first occurrence of 1 is found ; Mark the index ; Base case : If no 1 occurred ; No operations required ; Stores the character for which last operation was performed ; Stores minimum number of operations ; Iterate from pos to n ; Check if s [ i ] is 0 ; Check if last operation was performed because of 1 ; Set last to 0 ; Check if last operation was performed because of 0 ; Set last to 1 ; Return the answer ; Driver code
using System ; class GFG { static int minOperations ( String s ) { int n = s . Length ; int pos = - 1 ; for ( int i = 0 ; i < s . Length ; i ++ ) { if ( s [ i ] == '1' ) { pos = i ; break ; } } if ( pos == - 1 ) { return 0 ; } int last = 1 ; int ans = 1 ; for ( int i = pos + 1 ; i < n ; i ++ ) { if ( s [ i ] == '0' ) { if ( last == 1 ) { ans ++ ; last = 0 ; } } else { if ( last == 0 ) { ans ++ ; last = 1 ; } } } return ans ; } public static void Main ( string [ ] args ) { String s = "10111" ; Console . Write ( minOperations ( s ) ) ; } }
Find the Deepest Node in a Binary Tree | C # program to find value of the deepest node in a given binary tree ; A tree node ; maxLevel : keeps track of maximum level seen so far . res : Value of deepest node so far . level : Level of root ; Update level and resue ; Returns value of deepest node ; Initialze result and max level ; Updates value " res " and " maxLevel " Note that res and maxLen are passed by reference . ; Driver code
using System ; class GFG { public class Node { public int data ; public Node left , right ; public Node ( int key ) { data = key ; left = null ; right = null ; } } static int maxLevel = - 1 ; static int res = - 1 ; static void find ( Node root , int level ) { if ( root != null ) { find ( root . left , ++ level ) ; if ( level > maxLevel ) { res = root . data ; maxLevel = level ; } find ( root . right , level ) ; } } static int deepestNode ( Node root ) { int res = - 1 ; int maxLevel = - 1 ; find ( root , 0 ) ; return res ; } public static void Main ( String [ ] args ) { Node root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . left . left = new Node ( 4 ) ; root . right . left = new Node ( 5 ) ; root . right . right = new Node ( 6 ) ; root . right . left . right = new Node ( 7 ) ; root . right . right . right = new Node ( 8 ) ; root . right . left . right . left = new Node ( 9 ) ; Console . WriteLine ( deepestNode ( root ) ) ; } }
Find if string is K | C # program to find if String is K - Palindrome or not using all characters exactly once ; When size of String is less than k ; When size of String is equal to k ; When size of String is greater than k to store the frequencies of the characters ; To store the count of characters whose number of occurrences is odd . ; Iterating over the map ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void iskPalindromesPossible ( String s , int k ) { if ( s . Length < k ) { Console . Write ( " Not ▁ Possible " + " STRNEWLINE " ) ; return ; } if ( s . Length == k ) { Console . Write ( " Possible " + " STRNEWLINE " ) ; return ; } Dictionary < int , int > freq = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < s . Length ; i ++ ) if ( freq . ContainsKey ( s [ i ] ) ) { freq [ s [ i ] ] = freq [ s [ i ] ] + 1 ; } else { freq . Add ( s [ i ] , 1 ) ; } int count = 0 ; foreach ( KeyValuePair < int , int > it in freq ) { if ( it . Value % 2 == 1 ) count ++ ; } if ( count > k ) Console . Write ( " No " + " STRNEWLINE " ) ; else Console . Write ( " Yes " + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { String str = " poor " ; int K = 3 ; iskPalindromesPossible ( str , K ) ; str = " geeksforgeeks " ; K = 10 ; iskPalindromesPossible ( str , K ) ; } }
Find the Deepest Node in a Binary Tree | C # program to find value of the deepest node in a given binary tree ; A tree node with constructor ; Utility function to find height of a tree , rooted at ' root ' . ; levels : current Level Utility function to print all nodes at a given level . ; Driver Code ; Calculating height of tree ; Printing the deepest node
using System ; class GFG { public class Node { public int data ; public Node left , right ; public Node ( int key ) { data = key ; left = null ; right = null ; } } ; static int height ( Node root ) { if ( root == null ) return 0 ; int leftHt = height ( root . left ) ; int rightHt = height ( root . right ) ; return Math . Max ( leftHt , rightHt ) + 1 ; } static void deepestNode ( Node root , int levels ) { if ( root == null ) return ; if ( levels == 1 ) Console . Write ( root . data + " ▁ " ) ; else if ( levels > 1 ) { deepestNode ( root . left , levels - 1 ) ; deepestNode ( root . right , levels - 1 ) ; } } public static void Main ( String [ ] args ) { Node root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . left . left = new Node ( 4 ) ; root . right . left = new Node ( 5 ) ; root . right . right = new Node ( 6 ) ; root . right . left . right = new Node ( 7 ) ; root . right . right . right = new Node ( 8 ) ; root . right . left . right . left = new Node ( 9 ) ; int levels = height ( root ) ; deepestNode ( root , levels ) ; } }
Check if an array is sorted and rotated using Binary Search | C # implementation of the above approach ; Function to return the index of the pivot ; Base cases ; Check if element at ( mid - 1 ) is pivot Consider the cases like { 4 , 5 , 1 , 2 , 3 } ; Decide whether we need to go to the left half or the right half ; Function to check if a given array is sorted rotated or not ; To check if the elements to the left of the pivot are in descending or not ; To check if the elements to the right of the pivot are in ascending or not ; If any of the above if or else is true Then the array is sorted rotated ; Else the array is not sorted rotated ; Driver code
using System ; class GFG { static int findPivot ( int [ ] arr , int low , int high ) { if ( high < low ) return - 1 ; if ( high == low ) return low ; int mid = ( low + high ) / 2 ; if ( mid < high && arr [ mid + 1 ] < arr [ mid ] ) { return mid ; } if ( mid > low && arr [ mid ] < arr [ mid - 1 ] ) { return mid - 1 ; } if ( arr [ low ] > arr [ mid ] ) { return findPivot ( arr , low , mid - 1 ) ; } else { return findPivot ( arr , mid + 1 , high ) ; } } public static bool isRotated ( int [ ] arr , int n ) { int l = 0 ; int r = n - 1 ; int pivot = - 1 ; if ( arr [ l ] > arr [ r ] ) { pivot = findPivot ( arr , l , r ) ; int temp = pivot ; if ( l < pivot ) { while ( pivot > l ) { if ( arr [ pivot ] < arr [ pivot - 1 ] ) { return false ; } pivot -- ; } } pivot = temp ; else { pivot ++ ; while ( pivot < r ) { if ( arr [ pivot ] > arr [ pivot + 1 ] ) { return false ; } pivot ++ ; } } return true ; } else { return false ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 4 , 5 , 1 , 2 } ; Console . WriteLine ( isRotated ( arr , 5 ) ) ; } }
Find the Deepest Node in a Binary Tree | A C # program to find value of the deepest node in a given binary tree ; A tree node with constructor ; constructor ; Funtion to return the deepest node ; Creating a Queue ; Iterates untill queue become empty ; Driver code
using System ; using System . Collections . Generic ; public class Node { public int data ; public Node left , right ; public Node ( int key ) { data = key ; left = null ; right = null ; } } ; class Gfg { public static Node deepestNode ( Node root ) { Node tmp = null ; if ( root == null ) return null ; Queue < Node > q = new Queue < Node > ( ) ; q . Enqueue ( root ) ; while ( q . Count != 0 ) { tmp = q . Peek ( ) ; q . Dequeue ( ) ; if ( tmp . left != null ) q . Enqueue ( tmp . left ) ; if ( tmp . right != null ) q . Enqueue ( tmp . right ) ; } return tmp ; } public static void Main ( String [ ] args ) { Node root = new Node ( 1 ) ; root . left = new Node ( 2 ) ; root . right = new Node ( 3 ) ; root . left . left = new Node ( 4 ) ; root . right . left = new Node ( 5 ) ; root . right . right = new Node ( 6 ) ; root . right . left . right = new Node ( 7 ) ; root . right . right . right = new Node ( 8 ) ; root . right . left . right . left = new Node ( 9 ) ; Node deepNode = deepestNode ( root ) ; Console . WriteLine ( deepNode . data ) ; } }
Find a distinct pair ( x , y ) in given range such that x divides y | C # implementation of the approach ; Function to return the possible pair ; ans1 , ans2 store value of x and y respectively ; Driver Code
using System ; class GFG { static void findpair ( int l , int r ) { int ans1 = l ; int ans2 = 2 * l ; Console . WriteLine ( ans1 + " , ▁ " + ans2 ) ; } public static void Main ( ) { int l = 1 , r = 10 ; findpair ( l , r ) ; } }
Jump in rank of a student after updating marks | C # implementation of the approach ; Function to print the name of student who stood first after updation in rank ; Array of students ; Store the name of the student ; Update the marks of the student ; Store the current rank of the student ; Print the name and jump in rank ; Driver code ; Names of the students ; Marks of the students ; Updates that are to be done ; Number of students
using System ; class GFG { public class Student { public string name ; public int marks , prev_rank ; public Student ( ) { this . marks = 0 ; this . prev_rank = 0 ; } } static void nameRank ( string [ ] names , int [ ] marks , int [ ] updates , int n ) { Student [ ] x = new Student [ n ] ; for ( int i = 0 ; i < n ; i ++ ) { x [ i ] = new Student ( ) ; x [ i ] . name = names [ i ] ; x [ i ] . marks = marks [ i ] + updates [ i ] ; x [ i ] . prev_rank = i + 1 ; } Student highest = x [ 0 ] ; for ( int j = 1 ; j < n ; j ++ ) { if ( x [ j ] . marks >= highest . marks ) highest = x [ j ] ; } Console . Write ( " Name : ▁ " + highest . name + " , ▁ Jump : ▁ " + Math . Abs ( highest . prev_rank - 1 ) ) ; } public static void Main ( string [ ] args ) { string [ ] names = { " sam " , " ram " , " geek " } ; int [ ] marks = { 80 , 79 , 75 } ; int [ ] updates = { 0 , 5 , - 9 } ; int n = marks . Length ; nameRank ( names , marks , updates , n ) ; } }
Integers from the range that are composed of a single distinct digit | C # implementation of the approach ; Function to return the count of digits of a number ; Function to return a number that contains only digit ' d ' repeated exactly count times ; Function to return the count of integers that are composed of a single distinct digit only ; Count of digits in L and R ; First digits of L and R ; If L has lesser number of digits than R ; If the number that starts with firstDigitL and has number of digits = countDigitsL is within the range include the number ; Exclude the number ; If the number that starts with firstDigitR and has number of digits = countDigitsR is within the range include the number ; Exclude the number ; If both L and R have equal number of digits ; Include the number greater than L upto the maximum number whose digit = coutDigitsL ; Exclude the numbers which are greater than R ; Return the count ; Driver code
using System ; class GFG { static int countDigits ( int n ) { int count = 0 ; while ( n > 0 ) { count += 1 ; n /= 10 ; } return count ; } static int getDistinct ( int d , int count ) { int num = 0 ; count = ( int ) Math . Pow ( 10 , count - 1 ) ; while ( count > 0 ) { num += ( count * d ) ; count /= 10 ; } return num ; } static int findCount ( int L , int R ) { int count = 0 ; int countDigitsL = countDigits ( L ) ; int countDigitsR = countDigits ( R ) ; int firstDigitL = ( L / ( int ) Math . Pow ( 10 , countDigitsL - 1 ) ) ; int firstDigitR = ( R / ( int ) Math . Pow ( 10 , countDigitsR - 1 ) ) ; if ( countDigitsL < countDigitsR ) { count += ( 9 * ( countDigitsR - countDigitsL - 1 ) ) ; if ( getDistinct ( firstDigitL , countDigitsL ) >= L ) count += ( 9 - firstDigitL + 1 ) ; else count += ( 9 - firstDigitL ) ; if ( getDistinct ( firstDigitR , countDigitsR ) <= R ) count += firstDigitR ; else count += ( firstDigitR - 1 ) ; } else { if ( getDistinct ( firstDigitL , countDigitsL ) >= L ) count += ( 9 - firstDigitL + 1 ) ; else count += ( 9 - firstDigitL ) ; if ( getDistinct ( firstDigitR , countDigitsR ) <= R ) count -= ( 9 - firstDigitR ) ; else count -= ( 9 - firstDigitR + 1 ) ; } return count ; } public static void Main ( ) { int L = 10 , R = 50 ; Console . WriteLine ( findCount ( L , R ) ) ; } }
Check if a pair with given absolute difference exists in a Matrix | C # code to check for pair with given difference exists in the matrix or not ; Function to check if a pair with given difference exists in the matrix ; Store elements in a hash ; Loop to iterate over the elements of the matrix ; Driver Code ; Input matrix ; Given difference
using System ; using System . Collections . Generic ; class GFG { static int N = 4 ; static int M = 4 ; static Boolean isPairWithDiff ( int [ , ] mat , int k ) { HashSet < int > s = new HashSet < int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < M ; j ++ ) { if ( mat [ i , j ] > k ) { int m = mat [ i , j ] - k ; if ( s . Contains ( m ) ) { return true ; } } else { int m = k - mat [ i , j ] ; if ( s . Contains ( m ) ) { return true ; } } s . Add ( mat [ i , j ] ) ; } } return false ; } public static void Main ( String [ ] args ) { int [ , ] mat = { { 5 , 2 , 3 , 4 } , { 5 , 6 , 7 , 8 } , { 9 , 10 , 11 , 12 } , { 13 , 14 , 15 , 100 } } ; int k = 85 ; Console . WriteLine ( isPairWithDiff ( mat , k ) == true ? " YES " : " NO " ) ; } }
Next Smaller Element | A Stack based C # program to find next smaller element for all array elements in same order as input . using System ; ; prints element and NSE pair for all elements of arr [ ] of size n ; push the first element to stack ; iterate for rest of the elements ; if stack is not empty , then pop an element from stack . If the popped element is greater than next , then a ) print the pair b ) keep popping while elements are greater and stack is not empty ; push next to stack so that we can find next smaller for it ; After iterating over the loop , the remaining elements in stack do not have the next smaller element , so print - 1 for them ; Driver Code
using System ; using System . Collections . Generic ; class GFG { public static void printNSE ( int [ ] arr , int n ) { Stack < int > s = new Stack < int > ( ) ; Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; s . Push ( arr [ 0 ] ) ; for ( int i = 1 ; i < n ; i ++ ) { if ( s . Count == 0 ) { s . Push ( arr [ i ] ) ; continue ; } while ( s . Count != 0 && s . Peek ( ) > arr [ i ] ) { mp . Add ( s . Peek ( ) , arr [ i ] ) ; s . Pop ( ) ; } s . Push ( arr [ i ] ) ; } while ( s . Count != 0 ) { mp . Add ( s . Peek ( ) , - 1 ) ; s . Pop ( ) ; } for ( int i = 0 ; i < n ; i ++ ) Console . WriteLine ( arr [ i ] + " ▁ - - - > ▁ " + mp [ arr [ i ] ] ) ; } public static void Main ( ) { int [ ] arr = { 11 , 13 , 21 , 3 } ; int n = arr . Length ; printNSE ( arr , n ) ; } }
Deepest left leaf node in a binary tree | iterative approach | C # program to find deepest left leaf node of binary tree ; tree node ; returns a new tree Node ; return the deepest left leaf node of binary tree ; create a queue for level order traversal ; traverse until the queue is empty ; Since we go level by level , the last stored left leaf node is deepest one , ; Driver Code ; construct a tree
using System ; using System . Collections . Generic ; class GFG { class Node { public int data ; public Node left , right ; } ; static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = temp . right = null ; return temp ; } static Node getDeepestLeftLeafNode ( Node root ) { if ( root == null ) return null ; Queue < Node > q = new Queue < Node > ( ) ; q . Enqueue ( root ) ; Node result = null ; while ( q . Count != 0 ) { Node temp = q . Peek ( ) ; q . Dequeue ( ) ; if ( temp . left != null ) { q . Enqueue ( temp . left ) ; if ( temp . left . left == null && temp . left . right == null ) result = temp . left ; } if ( temp . right != null ) q . Enqueue ( temp . right ) ; } return result ; } public static void Main ( String [ ] args ) { Node root = newNode ( 1 ) ; root . left = newNode ( 2 ) ; root . right = newNode ( 3 ) ; root . left . left = newNode ( 4 ) ; root . right . left = newNode ( 5 ) ; root . right . right = newNode ( 6 ) ; root . right . left . right = newNode ( 7 ) ; root . right . right . right = newNode ( 8 ) ; root . right . left . right . left = newNode ( 9 ) ; root . right . right . right . right = newNode ( 10 ) ; Node result = getDeepestLeftLeafNode ( root ) ; if ( result != null ) Console . WriteLine ( " Deepest ▁ Left ▁ Leaf ▁ Node ▁ : : ▁ " + result . data ) ; else Console . WriteLine ( " No ▁ result , ▁ " + " left ▁ leaf ▁ not ▁ found " ) ; } }