codeparrot/xlcost-text-to-code huggingface dataset:
Smallest value in each level of Binary Tree | C # program to print minimum element in each level of binary tree . ; A Binary Tree Node ; return height of tree ; Iterative method to find every level minimum element of Binary Tree ; Base Case ; Create an empty queue for level order traversal ; push the root for Change the level ; for go level by level ; for check the level ; Get top of queue ; if node == null ( Means this is boundary between two levels ) ; here queue is empty represent no element in the actual queue ; increment level ; Reset min for next level minimum value ; get Minimum in every level ; Enqueue left child ; Enqueue right child ; 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 ; using System . Collections . Generic ; class GFG { 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 ) { if ( root == null ) return ; Queue < Node > q = new Queue < Node > ( ) ; q . Enqueue ( root ) ; q . Enqueue ( null ) ; int min = int . MaxValue ; int level = 0 ; while ( q . Count != 0 ) { Node node = q . Peek ( ) ; q . Dequeue ( ) ; if ( node == null ) { Console . Write ( " level ▁ " + level + " ▁ min ▁ is ▁ = ▁ " + min + " STRNEWLINE " ) ; if ( q . Count == 0 ) break ; q . Enqueue ( null ) ; level ++ ; min = int . MaxValue ; continue ; } if ( min > node . data ) min = node . data ; if ( node . left != null ) { q . Enqueue ( node . left ) ; } if ( node . right != null ) { q . Enqueue ( node . right ) ; } } } static Node newNode ( int data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = temp . right = null ; return temp ; } public static void Main ( String [ ] args ) { Node root = newNode ( 7 ) ; root . left = newNode ( 6 ) ; root . right = newNode ( 5 ) ; root . left . left = newNode ( 4 ) ; root . left . right = newNode ( 3 ) ; root . right . left = newNode ( 2 ) ; root . right . right = newNode ( 1 ) ; Console . Write ( " Every ▁ Level ▁ minimum ▁ is " + " STRNEWLINE " ) ; printPerLevelMinimum ( root ) ; } }
Count occurrences of a string that can be constructed from another given string | C # implementation of the above approach ; Function to find the count ; Initialize hash for both strings ; hash the frequency of letters of str1 ; hash the frequency of letters of str2 ; Find the count of str2 constructed from str1 ; Return answer ; Driver code
using System ; class GFG { static int findCount ( string str1 , string str2 ) { int len = str1 . Length ; int len2 = str2 . Length ; int ans = Int32 . MaxValue ; int [ ] hash1 = new int [ 26 ] ; int [ ] hash2 = new int [ 26 ] ; for ( int i = 0 ; i < len ; i ++ ) hash1 [ str1 [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < len2 ; i ++ ) hash2 [ str2 [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < 26 ; i ++ ) if ( hash2 [ i ] != 0 ) ans = Math . Min ( ans , hash1 [ i ] / hash2 [ i ] ) ; return ans ; } public static void Main ( ) { string str1 = " geeksclassesatnoida " ; string str2 = " sea " ; Console . WriteLine ( findCount ( str1 , str2 ) ) ; } }
Check if a string is the typed name of the given name | C # program to implement run length encoding ; Check if the character is vowel or not ; Returns true if ' typed ' is a typed name given str ; Traverse through all characters of str . ; If current characters do not match ; If not vowel , simply move ahead in both ; Count occurrences of current vowel in str ; Count occurrences of current vowel in typed ; Driver Code
using System ; class GFG { public static bool isVowel ( char c ) { string vowel = " aeiou " ; for ( int i = 0 ; i < vowel . Length ; ++ i ) { if ( vowel [ i ] == c ) { return true ; } } return false ; } public static bool printRLE ( string str , string typed ) { int n = str . Length , m = typed . Length ; int j = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] != typed [ j ] ) { return false ; } if ( isVowel ( str [ i ] ) == false ) { j ++ ; continue ; } int count1 = 1 ; while ( i < n - 1 && str [ i ] == str [ i + 1 ] ) { count1 ++ ; i ++ ; } int count2 = 1 ; while ( j < m - 1 && typed [ j ] == str [ i ] ) { count2 ++ ; j ++ ; } if ( count1 > count2 ) { return false ; } } return true ; } public static void Main ( string [ ] args ) { string name = " alex " , typed = " aaalaeex " ; if ( printRLE ( name , typed ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } }
Get Level of a node in a Binary Tree | C # program to Get Level of a node in a Binary Tree ; A tree node structure ; Helper function for getLevel ( ) . It returns level of the data if data is present in tree , otherwise returns 0. ; Returns level of given data value ; Driver code ; Constructing tree given in the above figure
using System ; public class Node { public int data ; public Node left , right ; public Node ( int d ) { data = d ; left = right = null ; } } public class BinaryTree { public Node root ; public virtual int getLevelUtil ( Node node , int data , int level ) { if ( node == null ) { return 0 ; } if ( node . data == data ) { return level ; } int downlevel = getLevelUtil ( node . left , data , level + 1 ) ; if ( downlevel != 0 ) { return downlevel ; } downlevel = getLevelUtil ( node . right , data , level + 1 ) ; return downlevel ; } public virtual int getLevel ( Node node , int data ) { return getLevelUtil ( node , data , 1 ) ; } public static void Main ( string [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; tree . root = new Node ( 3 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 5 ) ; tree . root . left . left = new Node ( 1 ) ; tree . root . left . right = new Node ( 4 ) ; for ( int x = 1 ; x <= 5 ; x ++ ) { int level = tree . getLevel ( tree . root , x ) ; if ( level != 0 ) { Console . WriteLine ( " Level ▁ of ▁ " + x + " ▁ is ▁ " + tree . getLevel ( tree . root , x ) ) ; } else { Console . WriteLine ( x + " ▁ is ▁ not ▁ present ▁ in ▁ tree " ) ; } } } }
Program to replace a word with asterisks in a sentence | C # program to censor a word with asterisks in a sentence ; Function takes two parameter ; Break down sentence by ' ▁ ' spaces and store each individual word in a different list ; A new string to store the result ; Creating the censor which is an asterisks " * " text of the length of censor word ; Iterating through our list of extracted words ; changing the censored word to created asterisks censor ; join the words ; Driver code
using System ; using System . Collections . Generic ; class GFG { static String censor ( String text , String word ) { String [ ] word_list = text . Split ( ' ▁ ' ) ; String result = " " ; String stars = " " ; for ( int i = 0 ; i < word . Length ; i ++ ) stars += ' * ' ; int index = 0 ; foreach ( String i in word_list ) { if ( i . CompareTo ( word ) == 0 ) word_list [ index ] = stars ; index ++ ; } foreach ( String i in word_list ) result += i + " ▁ " ; return result ; } public static void Main ( String [ ] args ) { String extract = " GeeksforGeeks ▁ is ▁ a ▁ computer ▁ science ▁ " + " portal ▁ for ▁ geeks . ▁ I ▁ am ▁ pursuing ▁ my ▁ " + " major ▁ in ▁ computer ▁ science . ▁ " ; String cen = " computer " ; Console . WriteLine ( censor ( extract , cen ) ) ; } }
Finite Automata algorithm for Pattern Searching | C # program for Finite Automata Pattern searching Algorithm ; If the character c is same as next character in pattern , then simply increment state ; ns stores the result which is next state ; Start from the largest possible value and stop when you find a prefix which is also suffix ; This function builds the TF table which represents Finite Automata for a given pattern ; Prints all occurrences of pat in txt ; Process txt over FA . ; Driver code
using System ; class GFG { public static int NO_OF_CHARS = 256 ; public static int getNextState ( char [ ] pat , int M , int state , int x ) { if ( state < M && ( char ) x == pat [ state ] ) { return state + 1 ; } int ns , i ; for ( ns = state ; ns > 0 ; ns -- ) { if ( pat [ ns - 1 ] == ( char ) x ) { for ( i = 0 ; i < ns - 1 ; i ++ ) { if ( pat [ i ] != pat [ state - ns + 1 + i ] ) { break ; } } if ( i == ns - 1 ) { return ns ; } } } return 0 ; } public static void computeTF ( char [ ] pat , int M , int [ ] [ ] TF ) { int state , x ; for ( state = 0 ; state <= M ; ++ state ) { for ( x = 0 ; x < NO_OF_CHARS ; ++ x ) { TF [ state ] [ x ] = getNextState ( pat , M , state , x ) ; } } } public static void search ( char [ ] pat , char [ ] txt ) { int M = pat . Length ; int N = txt . Length ; int [ ] [ ] TF = RectangularArrays . ReturnRectangularIntArray ( M + 1 , NO_OF_CHARS ) ; computeTF ( pat , M , TF ) ; int i , state = 0 ; for ( i = 0 ; i < N ; i ++ ) { state = TF [ state ] [ txt [ i ] ] ; if ( state == M ) { Console . WriteLine ( " Pattern ▁ found ▁ " + " at ▁ index ▁ " + ( i - M + 1 ) ) ; } } } public static class RectangularArrays { public static int [ ] [ ] ReturnRectangularIntArray ( int size1 , int size2 ) { int [ ] [ ] newArray = new int [ size1 ] [ ] ; for ( int array1 = 0 ; array1 < size1 ; array1 ++ ) { newArray [ array1 ] = new int [ size2 ] ; } return newArray ; } } public static void Main ( string [ ] args ) { char [ ] pat = " AABAACAADAABAAABAA " . ToCharArray ( ) ; char [ ] txt = " AABA " . ToCharArray ( ) ; search ( txt , pat ) ; } }
Longest Substring containing '1' | C # program for the above approach ; Function to find length of of longest substring containing '1' ; Count the number of contiguous 1 's ; Driver code
using System ; class GFG { static int maxlength ( String s ) { int n = s . Length , i , j ; int ans = 0 ; for ( i = 0 ; i <= n - 1 ; i ++ ) { if ( s [ i ] == '1' ) { int count = 1 ; for ( j = i + 1 ; j <= n - 1 && s [ j ] == '1' ; j ++ ) count ++ ; ans = Math . Max ( ans , count ) ; } } return ans ; } public static void Main ( String [ ] args ) { String s = "11101110" ; Console . Write ( maxlength ( s ) ) ; } }
Generate all possible strings formed by replacing letters with given respective symbols | C # program for the above approach ; Function to generate all possible string by replacing the characters with mapped symbols ; Base Case ; Function call with the P - th character not replaced ; Replace the P - th character ; Function call with the P - th character replaced ; Driver Code ; Function Call
using System ; using System . Collections . Generic ; class GFG { static void generateLetters ( string S , int P , Dictionary < char , char > M ) { if ( P == S . Length ) { Console . WriteLine ( S ) ; return ; } generateLetters ( S , P + 1 , M ) ; S = S . Substring ( 0 , P ) + M [ S [ P ] ] + S . Substring ( P + 1 ) ; generateLetters ( S , P + 1 , M ) ; return ; } public static void Main ( ) { string S = " aBc " ; Dictionary < char , char > M = new Dictionary < char , char > ( ) ; M . Add ( ' a ' , ' $ ' ) ; M . Add ( ' B ' , ' # ' ) ; M . Add ( ' c ' , ' ^ ' ) ; M . Add ( ' d ' , ' & ' ) ; M . Add ( '1' , ' * ' ) ; M . Add ( '2' , ' ! ' ) ; M . Add ( ' E ' , ' @ ' ) ; generateLetters ( S , 0 , M ) ; } }
Minimize swaps of pairs of characters required such that no two adjacent characters in the string are same | C # program for the above approach ; Function to check if S contains any pair of adjacent characters that are same ; Traverse the String S ; If current pair of adjacent characters are the same ; Return true ; Utility function to find the minimum number of swaps of pair of characters required to make all pairs of adjacent characters different ; Check if the required String is formed already ; Traverse the String S ; Swap the characters at i and j position ; Swap for Backtracking Step ; Function to find the minimum number of swaps of pair of characters required to make all pairs of adjacent characters different ; Stores the resultant minimum number of swaps required ; Function call to find the minimum swaps required ; Print the result ; Driver Code
using System ; public class GFG { static int ansSwaps ; static bool check ( char [ ] S ) { for ( int i = 1 ; i < S . Length ; i ++ ) { if ( S [ i - 1 ] == S [ i ] ) { return false ; } } return true ; } static void minimumSwaps ( char [ ] S , int swaps , int idx ) { if ( check ( S ) ) { ansSwaps = Math . Min ( ansSwaps , swaps ) ; } for ( int i = idx ; i < S . Length ; i ++ ) { for ( int j = i + 1 ; j < S . Length ; j ++ ) { swap ( S , i , j ) ; minimumSwaps ( S , swaps + 1 , i + 1 ) ; S = swap ( S , i , j ) ; } } } static char [ ] swap ( char [ ] arr , int i , int j ) { char temp = arr [ i ] ; arr [ i ] = arr [ j ] ; arr [ j ] = temp ; return arr ; } static void findMinimumSwaps ( char [ ] S ) { ansSwaps = int . MaxValue ; minimumSwaps ( S , 0 , 0 ) ; if ( ansSwaps == int . MaxValue ) Console . Write ( " - 1" ) ; else Console . Write ( ansSwaps ) ; } public static void Main ( String [ ] args ) { String S = " ABAACD " ; findMinimumSwaps ( S . ToCharArray ( ) ) ; } }
Maximum count of 0 s between two 1 s in given range for Q queries | C # program for the above approach ; Function to count the number of 0 s lying between the two 1 s for each query ; Stores count of 0 ' s ▁ that ▁ are ▁ ▁ right ▁ to ▁ the ▁ most ▁ recent ▁ 1' s ; Stores count of 0 ' s ▁ that ▁ are ▁ ▁ left ▁ to ▁ the ▁ most ▁ recent ▁ 1' s ; Stores the count of zeros in a prefix / suffix of array ; Stores the count of total 0 s ; Traverse the string S ; If current character is '1' ; Otherwise ; Update the rightBound [ i ] ; Update count and total to 0 ; Traverse the string S in reverse manner ; If current character is '1' ; Otherwise ; Update the leftBound [ i ] ; Traverse given query array ; Update the value of count ; Print the count as the result to the current query [ L , R ] ; Driver Code
using System ; public class GFG { static void countOsBetween1s ( String S , int N , int [ , ] Q ) { int [ ] leftBound = new int [ N ] ; int [ ] rightBound = new int [ N ] ; int count = 0 ; int total = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( S [ i ] == '1' ) { count = total ; } else if ( S [ i ] == '0' ) { total ++ ; } rightBound [ i ] = count ; } count = 0 ; total = 0 ; for ( int i = N - 1 ; i >= 0 ; i -- ) { if ( S [ i ] == '1' ) { count = total ; } else if ( S [ i ] == '0' ) { total ++ ; } leftBound [ i ] = count ; } for ( int q = 0 ; q < Q . GetLength ( 0 ) ; q ++ ) { int L = Q [ q , 0 ] ; int R = Q [ q , 1 ] ; count = leftBound [ L ] + rightBound [ R ] - total ; Console . Write ( count + " ▁ " ) ; } } public static void Main ( String [ ] args ) { String S = "1001010" ; int [ , ] Q = { { 0 , 4 } , { 0 , 5 } } ; int N = S . Length ; countOsBetween1s ( S , N , Q ) ; } }
Get level of a node in binary tree | iterative approach | C # program to print level of given node in binary tree iterative approach ; node of binary tree ; utility function to return level of given node ; extra NULL is pushed to keep track of all the nodes to be pushed before level is incremented by 1 ; Driver Code ; create a binary tree ; return level of node
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { public class node { public int data ; public node left , right ; public node ( int data ) { this . data = data ; this . left = this . right = null ; } } static int getLevel ( node root , int data ) { Queue < node > q = new Queue < node > ( ) ; int level = 1 ; q . Enqueue ( root ) ; q . Enqueue ( null ) ; while ( q . Count > 0 ) { node temp = q . Dequeue ( ) ; if ( temp == null ) { if ( q . Count > 0 ) { q . Enqueue ( null ) ; } level += 1 ; } else { if ( temp . data == data ) { return level ; } if ( temp . left != null ) { q . Enqueue ( temp . left ) ; } if ( temp . right != null ) { q . Enqueue ( temp . right ) ; } } } return 0 ; } public static void Main ( String [ ] args ) { node root = new node ( 20 ) ; root . left = new node ( 10 ) ; root . right = new node ( 30 ) ; root . left . left = new node ( 5 ) ; root . left . right = new node ( 15 ) ; root . left . right . left = new node ( 12 ) ; root . right . left = new node ( 25 ) ; root . right . right = new node ( 40 ) ; int level = getLevel ( root , 30 ) ; if ( level != 0 ) Console . WriteLine ( " level ▁ of ▁ node ▁ 30 ▁ is ▁ " + level ) ; else Console . WriteLine ( " node ▁ 30 ▁ not ▁ found " ) ; level = getLevel ( root , 12 ) ; if ( level != 0 ) Console . WriteLine ( " level ▁ of ▁ node ▁ 12 ▁ is ▁ " + level ) ; else Console . WriteLine ( " node ▁ 12 ▁ not ▁ found " ) ; level = getLevel ( root , 25 ) ; if ( level != 0 ) Console . WriteLine ( " level ▁ of ▁ node ▁ 25 ▁ is ▁ " + level ) ; else Console . WriteLine ( " node ▁ 25 ▁ not ▁ found " ) ; level = getLevel ( root , 27 ) ; if ( level != 0 ) Console . WriteLine ( " level ▁ of ▁ node ▁ 27 ▁ is ▁ " + level ) ; else Console . WriteLine ( " node ▁ 27 ▁ not ▁ found " ) ; } }
Lexicographically smallest Palindromic Path in a Binary Tree | C # program for the above approach ; Struct binary tree node ; Function to create a new node ; Function to check if the String is palindrome or not ; Function to find the lexicographically smallest palindromic path in the Binary Tree ; Base case ; Append current node 's  data to the String ; Check if a node is leaf or not ; Check for the 1 st Palindromic Path ; Store lexicographically the smallest palindromic path ; Recursively traverse left subtree ; Recursively traverse right subtree ; Function to get smallest lexographical palindromic path ; Variable which stores the readonly result ; Function call to compute lexicographically smallest palindromic Path ; Driver Code ; Conbinary tree
using System ; public class GFG { static String finalAns = " " ; class Node { public char data ; public Node left , right ; } ; static Node newNode ( char data ) { Node temp = new Node ( ) ; temp . data = data ; temp . left = temp . right = null ; return temp ; } static bool checkPalindrome ( String s ) { int low = 0 , high = ( int ) s . Length - 1 ; while ( low < high ) { if ( s [ low ] != s [ high ] ) return false ; low ++ ; high -- ; } return true ; } static void lexicographicallySmall ( Node root , String s ) { if ( root == null ) return ; s += root . data ; if ( root . left == null && root . right == null ) { if ( checkPalindrome ( s ) ) { if ( finalAns == " $ " ) finalAns = s ; else finalAns = finalAns . CompareTo ( s ) <= 0 ? finalAns : s ; } return ; } lexicographicallySmall ( root . left , s ) ; lexicographicallySmall ( root . right , s ) ; } static void getPalindromePath ( Node root ) { finalAns = " $ " ; lexicographicallySmall ( root , " " ) ; if ( finalAns == " $ " ) Console . Write ( " No ▁ Palindromic ▁ Path ▁ exists " ) ; else Console . Write ( finalAns ) ; } public static void Main ( String [ ] args ) { Node root = newNode ( ' a ' ) ; root . left = newNode ( ' c ' ) ; root . left . left = newNode ( ' a ' ) ; root . left . right = newNode ( ' g ' ) ; root . right = newNode ( ' b ' ) ; root . right . left = newNode ( ' b ' ) ; root . right . right = newNode ( ' x ' ) ; root . right . left . right = newNode ( ' a ' ) ; getPalindromePath ( root ) ; } }
Find mirror of a given node in Binary tree | C # program to find the mirror Node in Binary tree ; A binary tree Node has data , pointer to left child and a pointer to right child ; create new Node and initialize it ; recursive function to find mirror of Node ; if any of the Node is none then Node itself and decendent have no mirror , so return none , no need to further explore ! ; if left Node is target Node , then return right 's key (that is mirror) and vice   versa  ; first recur external Nodes ; if no mirror found , recur internal Nodes ; interface for mirror search ; Driver code ; target Node whose mirror have to be searched
using System ; class GfG { class Node { public int key ; public 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 ) Console . WriteLine ( " Mirror ▁ of ▁ Node ▁ " + target + " ▁ is ▁ Node ▁ " + mirror ) ; else Console . WriteLine ( " Mirror ▁ of ▁ Node ▁ " + target + " ▁ is ▁ null ▁ " ) ; } }
Pair of strings having longest common prefix of maximum length in given array | C # program for the above approach ; class of Trie ; Function to insert a string into Trie ; Stores length of the string ; Traverse the string str ; If str [ i ] is not present in current path of Trie ; Create a new node of Trie ; Update root ; Function to find the maximum length of longest common prefix in Trie with str ; Stores length of str ; Stores length of longest common prefix in Trie with str ; Traverse the string str ; If str [ i ] is present in the current path of Trie ; Update len ; Update root ; Function to print the pair having maximum length of the longest common prefix ; Stores index of the string having maximum length of longest common prefix ; Stores maximum length of longest common prefix . ; Create root node of Trie ; Insert arr [ 0 ] into Trie ; Traverse the array . ; Stores maximum length of longest common prefix in Trie with arr [ i ] ; If temp is greater than len ; Update len ; Update idx ; Traverse array arr [ ] ; Stores length of arr [ i ] ; Check if maximum length of longest common prefix > M ; Traverse string arr [ i ] and arr [ j ] ; If current character of both string does not match . ; Print pairs having maximum length of the longest common prefix ; Driver Code
using System ; using System . Collections . Generic ; public class GFG { public class TrieNode { public TrieNode [ ] child = new TrieNode [ 256 ] ; public TrieNode ( ) { } } ; public static void insertTrie ( TrieNode root , String str ) { int M = str . Length ; for ( int i = 0 ; i < M ; i ++ ) { if ( root . child [ str [ i ] ] == null ) { root . child [ str [ i ] ] = new TrieNode ( ) ; } root = root . child [ str [ i ] ] ; } } public 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 [ i ] ] != null ) { len ++ ; root = root . child [ str [ i ] ] ; } else { return len ; } } return len ; } public static void findMaxLenPair ( List < string > arr , int N ) { int idx = - 1 ; int len = 0 ; TrieNode root = new TrieNode ( ) ; insertTrie ( root , arr [ 0 ] ) ; for ( int i = 1 ; i < N ; i ++ ) { int temp = findStrLen ( root , arr [ i ] ) ; if ( temp > len ) { len = temp ; idx = i ; } insertTrie ( root , arr [ i ] ) ; } for ( int i = 0 ; i < N ; i ++ ) { int M = arr [ i ] . Length ; if ( i != idx && M >= len ) { bool found = true ; for ( int j = 0 ; j < len ; j ++ ) { if ( arr [ i ] [ j ] != arr [ idx ] [ j ] ) { found = false ; break ; } } if ( found ) { Console . WriteLine ( " ( " + arr [ i ] + " , ▁ " + arr [ idx ] + " ) " ) ; return ; } } } } public static void Main ( ) { List < string > arr = new List < string > ( ) { " geeksforgeeks " , " geeks " , " geeksforcse " } ; int N = arr . Count ; findMaxLenPair ( arr , N ) ; } }