codeparrot/xlcost-text-to-code huggingface dataset:
Maximum distinct lowercase alphabets between two uppercase | C # Program to find maximum lowercase alphabets present between two uppercase alphabets ; Function which computes the maximum number of distinct lowercase alphabets between two uppercase alphabets ; Ignoring lowercase characters in the beginning . ; We start from next of first capital letter and traverse through remaining character . ; If character is in uppercase , ; Count all distinct lower case characters ; Update maximum count ; Reset count array ; If character is in lowercase ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int MAX_CHAR = 26 ; static int maxLower ( String str ) { int n = str . Length ; int i = 0 ; for ( ; i < n ; i ++ ) { if ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) { i ++ ; break ; } } int maxCount = 0 ; int [ ] count = new int [ MAX_CHAR ] ; for ( ; i < n ; i ++ ) { if ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) { int currCount = 0 ; for ( int j = 0 ; j < MAX_CHAR ; j ++ ) { if ( count [ j ] > 0 ) { currCount ++ ; } } maxCount = Math . Max ( maxCount , currCount ) ; Array . Fill ( count , 0 ) ; } if ( str [ i ] >= ' a ' && str [ i ] <= ' z ' ) { count [ str [ i ] - ' a ' ] ++ ; } } return maxCount ; } public static void Main ( String [ ] args ) { String str = " zACaAbbaazzC " ; Console . WriteLine ( maxLower ( str ) ) ; } }
Maximum distinct lowercase alphabets between two uppercase | C # Program to find maximum lowercase alphabets present between two uppercase alphabets ; Function which computes the maximum number of distinct lowercase alphabets between two uppercase alphabets ; Ignoring lowercase characters in the beginning . ; We start from next of first capital letter and traverse through remaining character . ; If character is in uppercase , ; Update maximum count if lowercase character before this is more . ; clear the set ; If character is in lowercase ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int maxLower ( char [ ] str ) { int n = str . Length ; int i = 0 ; for ( ; i < n ; i ++ ) { if ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) { i ++ ; break ; } } int maxCount = 0 ; HashSet < int > s = new HashSet < int > ( ) ; for ( ; i < n ; i ++ ) { if ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) { maxCount = Math . Max ( maxCount , ( int ) s . Count ) ; s . Clear ( ) ; } if ( str [ i ] >= ' a ' && str [ i ] <= ' z ' ) s . Add ( ( int ) str [ i ] ) ; } return maxCount ; } public static void Main ( String [ ] args ) { String str = " zACaAbbaazzC " ; Console . WriteLine ( maxLower ( str . ToCharArray ( ) ) ) ; } }
First uppercase letter in a string ( Iterative and Recursive ) | C # program to find the first uppercase letter using linear search ; Function to find string which has first character of each word . ; Driver function
using System ; class GFG { static char first ( string str ) { for ( int i = 0 ; i < str . Length ; i ++ ) if ( char . IsUpper ( str [ i ] ) ) return str [ i ] ; return '0' ; } public static void Main ( ) { string str = " geeksforGeeKS " ; char res = first ( str ) ; if ( res == '0' ) Console . WriteLine ( " No ▁ uppercase " + " ▁ letter " ) ; else Console . WriteLine ( res ) ; } }
Count maximum | C # implementation for counting maximum length palindromes ; factorial of a number ; function to count maximum length palindromes . ; Count number of occurrence of a charterer in the string ; int k = 0 ; Count of singles int num = 0 ; numerator of result int den = 1 ; denominator of result ; if frequency is even fi = ci / 2 ; if frequency is odd fi = ci - 1 / 2. ; sum of all frequencies ; product of factorial of every frequency ; if all character are unique so there will be no pallindrome , so if num != 0 then only we are finding the factorial ; k are the single elements that can be placed in middle ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int fact ( int n ) { int ans = 1 ; for ( int i = 1 ; i <= n ; i ++ ) ans = ans * i ; return ( ans ) ; } static int numberOfPossiblePallindrome ( String str , int n ) { Dictionary < char , int > mp = new Dictionary < char , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mp . ContainsKey ( str [ i ] ) ) { var val = mp [ str [ i ] ] ; mp . Remove ( str [ i ] ) ; mp . Add ( str [ i ] , val + 1 ) ; } else { mp . Add ( str [ i ] , 1 ) ; } } int fi ; foreach ( KeyValuePair < char , int > it in mp ) { if ( it . Value % 2 == 0 ) fi = it . Value / 2 ; else { fi = ( it . Value - 1 ) / 2 ; k ++ ; } num = num + fi ; den = den * fact ( fi ) ; } if ( num != 0 ) num = fact ( num ) ; int ans = num / den ; if ( k != 0 ) { ans = ans * k ; } return ( ans ) ; } public static void Main ( String [ ] args ) { String str = " ababab " ; int n = str . Length ; Console . WriteLine ( numberOfPossiblePallindrome ( str , n ) ) ; } }
Counting even decimal value substrings in a binary string | C # Program to count all even decimal value substring . ; generate all substring in arr [ 0. . n - 1 ] ; store the count ; Pick starting point ; Pick ending point ; substring between current starting and ending points ; increment power of 2 by one ; Driver code
using System ; class GFG { static int evenDecimalValue ( string str , int n ) { int result = 0 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = i ; j < n ; j ++ ) { int decimalValue = 0 ; int powerOf2 = 1 ; for ( int k = i ; k <= j ; k ++ ) { decimalValue += ( ( str [ k ] - '0' ) * powerOf2 ) ; powerOf2 *= 2 ; } if ( decimalValue % 2 == 0 ) result ++ ; } } return result ; } public static void Main ( ) { String str = "10010" ; int n = 5 ; Console . WriteLine ( evenDecimalValue ( str , n ) ) ; } }
Create a new string by alternately combining the characters of two halves of the string in reverse | C # program for creating a string by alternately combining the characters of two halves in reverse ; Function performing calculations ; Calculating the two halves of string s as first and second The final string p ; It joins the characters to final string in reverse order ; It joins the characters to final string in reverse order ; Driver method ; Calling function
using System ; class GFG { public static void solve ( string s ) { int l = s . Length ; int x = l / 2 ; int y = l ; string p = " " ; while ( x > 0 && y > l / 2 ) { char ch = s [ x - 1 ] ; p += ch ; x -- ; ch = s [ y - 1 ] ; p += ch ; y -- ; } if ( y > l / 2 ) { char ch = s [ x - 1 ] ; p += ch ; y -- ; } Console . WriteLine ( p ) ; } public static void Main ( ) { string s = " sunshine " ; solve ( s ) ; } }
Program for length of a string using recursion | C # program to calculate length of a string using recursion ; Function to calculate length ; if we reach at the end of the string ; Driver program to test above function
using System ; public class GFG { private static int recLen ( string str ) { if ( str . Equals ( " " ) ) return 0 ; else return recLen ( str . Substring ( 1 ) ) + 1 ; } public static void Main ( ) { string str = " GeeksforGeeks " ; Console . WriteLine ( recLen ( str ) ) ; } }
Count consonants in a string ( Iterative and recursive methods ) | Iterative C # program to count total number of consonants ; Function to check for consonant ; To handle lower case ; To check is character is Consonant ; Driver code
using System ; class GFG { static bool isConsonant ( char ch ) { ch = Char . ToUpper ( ch ) ; return ! ( ch == ' A ' ch == ' E ' ch == ' I ' ch == ' O ' ch == ' U ' ) && ch >= 65 && ch <= 90 ; } static int totalConsonants ( String str ) { int count = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) if ( isConsonant ( str [ i ] ) ) ++ count ; return count ; } public static void Main ( ) { String str = " abc ▁ de " ; Console . Write ( totalConsonants ( str ) ) ; } }
Count consonants in a string ( Iterative and recursive methods ) | Recursive C # program to count total number of consonants ; Function to check for consonant ; To handle lower case ; to count total number of consonants from 0 to n - 1 ; Driver code
using System ; class GFG { static Boolean isConsonant ( char ch ) { ch = char . ToUpper ( ch ) ; return ( ch == ' A ' ch == ' E ' ch == ' I ' ch == ' O ' ch == ' U ' ) == false && ch >= 65 && ch <= 90 ; } static int totalConsonants ( String str , int n ) { if ( n == 1 ) { if ( isConsonant ( str [ 0 ] ) ) return 1 ; else return 0 ; } if ( isConsonant ( str [ n - 1 ] ) ) return totalConsonants ( str , n - 1 ) + 1 ; else return totalConsonants ( str , n - 1 ) ; } public static void Main ( String [ ] args ) { String str = " abc ▁ de " ; Console . WriteLine ( totalConsonants ( str , str . Length ) ) ; } }
Check if actual binary representation of a number is palindrome | C # code to check whether binary representation of a number is palindrome or not ; function to reverse bits of a number ; traversing bits of ' n ' from the right ; bitwise left shift ' rev ' by 1 ; if current bit is '1' ; bitwise right shift ' n ' by 1 ; required number ; function to check a number is palindrome or not ; get the number by reversing bits in the binary representation of ' n ' ; Driver function
using System ; public class GfG { public static long reverseBits ( long n ) { long rev = 0 ; while ( n > 0 ) { rev <<= 1 ; if ( ( n & 1 ) == 1 ) rev ^= 1 ; n >>= 1 ; } return rev ; } public static bool isPalindrome ( long n ) { long rev = reverseBits ( n ) ; return ( n == rev ) ; } public static void Main ( ) { long n = 9 ; if ( isPalindrome ( n ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Reduce Hamming distance by swapping two characters | C # code to decrease hamming distance using swap . ; Function to return the swapped indexes to get minimum hamming distance . ; Find the initial hamming distance ; Case - I : To decrease distance by two ; ASCII values of present character . ; If two same letters appear in different positions print their indexes ; Store the index of letters which is in wrong position ; Case : II ; If misplaced letter is found , print its original index and its new index ; Store the index of letters in wrong position ; Case - III ; Driver code
using System ; class GFG { static readonly int MAX = 26 ; static void Swap ( string s , string t , int n ) { int [ , ] dp = new int [ MAX , MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) { for ( int j = 0 ; j < MAX ; j ++ ) { dp [ i , j ] = - 1 ; } } int tot = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( s [ i ] != t [ i ] ) tot ++ ; for ( int i = 0 ; i < n ; i ++ ) { int a = s [ i ] - ' a ' ; int b = t [ i ] - ' a ' ; if ( a == b ) continue ; if ( dp [ a , b ] != - 1 ) { Console . WriteLine ( i + 1 + " ▁ " + ( dp [ a , b ] + 1 ) ) ; return ; } dp [ b , a ] = i ; } int [ ] A = new int [ MAX ] ; int [ ] B = new int [ MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) { A [ i ] = - 1 ; B [ i ] = - 1 ; } for ( int i = 0 ; i < n ; i ++ ) { int a = s [ i ] - ' a ' ; int b = t [ i ] - ' a ' ; if ( a == b ) continue ; if ( A [ b ] != - 1 ) { Console . WriteLine ( i + 1 + " ▁ " + ( A [ b ] + 1 ) ) ; return ; } if ( B [ a ] != - 1 ) { Console . WriteLine ( i + 1 + " ▁ " + ( B [ a ] + 1 ) ) ; return ; } A [ a ] = i ; B [ b ] = i ; } Console . WriteLine ( - 1 ) ; } public static int Main ( ) { string S = " permanent " ; string T = " pergament " ; int n = S . Length ; if ( S == " " T == " " ) Console . WriteLine ( " Required ▁ string ▁ is ▁ empty . " ) ; else Swap ( S , T , n ) ; return 0 ; } }
Convert string X to an anagram of string Y with minimum replacements | C # program to convert string X to string Y which minimum number of changes . ; Function that converts string X into lexicographically smallest anagram of string Y with minimal changes ; Counting frequency of characters in each string . ; We maintain two more counter arrays ctrx [ ] and ctry [ ] Ctrx [ ] maintains the count of extra elements present in string X than string Y Ctry [ ] maintains the count of characters missing from string X which should be present in string Y . ; This means that we cannot edit the current character as it 's frequency  in string X is equal to or less  than the frequency in string Y.  Thus, we go to the next position ; Here , we try to find that character , which has more frequency in string Y and less in string X . We try to find this character in lexicographical order so that we get lexicographically smaller string ; This portion deals with the lexicographical property . Now , we put a character in string X when either this character has smaller value than the character present there right now or if this is the last position for it to exchange , else we fix the character already present here in this position . ; Driver code
using System ; class GFG { static readonly int MAX = 26 ; static void printAnagramAndChanges ( char [ ] X , char [ ] Y ) { int [ ] countx = new int [ MAX ] ; int [ ] county = new int [ MAX ] ; int [ ] ctrx = new int [ MAX ] ; int [ ] ctry = new int [ MAX ] ; int change = 0 ; int l = X . Length ; for ( int i = 0 ; i < l ; i ++ ) { countx [ X [ i ] - ' A ' ] ++ ; county [ Y [ i ] - ' A ' ] ++ ; } for ( int i = 0 ; i < MAX ; i ++ ) { if ( countx [ i ] > county [ i ] ) { ctrx [ i ] += ( countx [ i ] - county [ i ] ) ; } else if ( countx [ i ] < county [ i ] ) { ctry [ i ] += ( county [ i ] - countx [ i ] ) ; } change += Math . Abs ( county [ i ] - countx [ i ] ) ; } for ( int i = 0 ; i < l ; i ++ ) { if ( ctrx [ X [ i ] - ' A ' ] == 0 ) { continue ; } int j ; for ( j = 0 ; j < MAX ; j ++ ) { if ( ( ctry [ j ] ) > 0 ) { break ; } } if ( countx [ X [ i ] - ' A ' ] == ctrx [ X [ i ] - ' A ' ] X [ i ] - ' A ' > j ) { countx [ X [ i ] - ' A ' ] -- ; ctrx [ X [ i ] - ' A ' ] -- ; ctry [ j ] -- ; X [ i ] = ( char ) ( ' A ' + j ) ; } else { countx [ X [ i ] - ' A ' ] -- ; } } Console . WriteLine ( " Anagram ▁ : ▁ " + String . Join ( " " , X ) ) ; Console . WriteLine ( " Number ▁ of ▁ changes ▁ made ▁ : ▁ " + change / 2 ) ; } public static void Main ( String [ ] args ) { String x = " CDBABC " , y = " ADCABD " ; printAnagramAndChanges ( x . ToCharArray ( ) , y . ToCharArray ( ) ) ; } }
Count number of equal pairs in a string | C # program to count the number of pairs ; Function to count the number of equal pairs ; Hash table ; Traverse the string and count occurrence ; Stores the answer ; Traverse and check the occurrence of every character ; Driver Code
using System ; class GFG { static int MAX = 256 ; static int countPairs ( string s ) { int [ ] cnt = new int [ MAX ] ; for ( int i = 0 ; i < s . Length ; i ++ ) cnt [ s [ i ] ] ++ ; int ans = 0 ; for ( int i = 0 ; i < MAX ; i ++ ) ans += cnt [ i ] * cnt [ i ] ; return ans ; } public static void Main ( ) { string s = " geeksforgeeks " ; Console . WriteLine ( countPairs ( s ) ) ; } }
Find a string in lexicographic order which is in between given two strings | C # program to find the string in lexicographic order which is in between given two strings ; Function to find the lexicographically next string ; Iterate from last character ; If not ' z ' , increase by one ; if ' z ' , change it to ' a ' ; Driver Code ; If not equal , print the resultant string
using System ; public class GFG { static String lexNext ( String str , int n ) { char [ ] s = str . ToCharArray ( ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( s [ i ] != ' z ' ) { s [ i ] ++ ; return new String ( s ) ; } s [ i ] = ' a ' ; } return null ; } static public void Main ( ) { String S = " abcdeg " , T = " abcfgh " ; int n = S . Length ; String res = lexNext ( S , n ) ; if ( res != T ) { Console . Write ( res ) ; } else { Console . Write ( " - 1" ) ; } } }
Find the arrangement of queue at given time | C # program to find the arrangement of queue at time = t ; prints the arrangement at time = t ; Checking the entire queue for every moment from time = 1 to time = t . ; If current index contains ' B ' and next index contains ' G ' then swap . ; Driver function
using System ; class Geek { static void solve ( int n , int t , char [ ] s ) { for ( int i = 0 ; i < t ; i ++ ) for ( int j = 0 ; j < n - 1 ; j ++ ) if ( s [ j ] == ' B ' && s [ j + 1 ] == ' G ' ) { char temp = s [ j ] ; s [ j ] = s [ j + 1 ] ; s [ j + 1 ] = temp ; j ++ ; } Console . Write ( s ) ; } public static void Main ( String [ ] args ) { int n = 6 , t = 2 ; String s = " BBGBBG " ; char [ ] str = s . ToCharArray ( ) ; solve ( n , t , str ) ; } }
Add two numbers represented by two arrays | C # program to sum two numbers represented two arrays . ; Return sum of two number represented by the arrays . Size of a [ ] is greater than b [ ] . It is made sure be the wrapper function ; array to store sum . ; Until we reach beginning of array . we are comparing only for second array because we have already compare the size of array in wrapper function . ; find sum of corresponding element of both array . ; Finding carry for next sum . ; If second array size is less the first array size . ; Add carry to first array elements . ; If there is carry on adding 0 index elements append 1 to total sum . ; Converting array into number . ; Wrapper Function ; Making first array which have greater number of element ; Driver program
using System ; class GFG { static int calSumUtil ( int [ ] a , int [ ] b , int n , int m ) { int [ ] sum = new int [ n ] ; int i = n - 1 , j = m - 1 , k = n - 1 ; int carry = 0 , s = 0 ; while ( j >= 0 ) { s = a [ i ] + b [ j ] + carry ; sum [ k ] = ( s % 10 ) ; carry = s / 10 ; k -- ; i -- ; j -- ; } while ( i >= 0 ) { s = a [ i ] + carry ; sum [ k ] = ( s % 10 ) ; carry = s / 10 ; i -- ; k -- ; } int ans = 0 ; if ( carry == 1 ) ans = 10 ; for ( i = 0 ; i <= n - 1 ; i ++ ) { ans += sum [ i ] ; ans *= 10 ; } return ans / 10 ; } static int calSum ( int [ ] a , int [ ] b , int n , int m ) { if ( n >= m ) return calSumUtil ( a , b , n , m ) ; else return calSumUtil ( b , a , m , n ) ; } public static void Main ( ) { int [ ] a = { 9 , 3 , 9 } ; int [ ] b = { 6 , 1 } ; int n = a . Length ; int m = b . Length ; Console . WriteLine ( calSum ( a , b , n , m ) ) ; } }
Longest Common Anagram Subsequence | C # implementation to find the length of the longest common anagram subsequence ; function to find the length of the longest common anagram subsequence ; hash tables for storing frequencies of each character ; calculate frequency of each character of ' str1 [ ] ' ; calculate frequency of each character of ' str2 [ ] ' ; for each character add its minimum frequency out of the two strings in ' len ' ; required length ; Driver Code
using System ; class GFG { static int SIZE = 26 ; static int longCommomAnagramSubseq ( string str1 , string str2 , int n1 , int n2 ) { int [ ] freq1 = new int [ SIZE ] ; int [ ] freq2 = new int [ SIZE ] ; for ( int i = 0 ; i < SIZE ; i ++ ) { freq1 [ i ] = 0 ; freq2 [ i ] = 0 ; } int len = 0 ; for ( int i = 0 ; i < n1 ; i ++ ) freq1 [ str1 [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < n2 ; i ++ ) freq2 [ str2 [ i ] - ' a ' ] ++ ; for ( int i = 0 ; i < SIZE ; i ++ ) len += Math . Min ( freq1 [ i ] , freq2 [ i ] ) ; return len ; } static void Main ( ) { string str1 = " abdacp " ; string str2 = " ckamb " ; int n1 = str1 . Length ; int n2 = str2 . Length ; Console . Write ( " Length ▁ = ▁ " + longCommomAnagramSubseq ( str1 , str2 , n1 , n2 ) ) ; } }
Panalphabetic window in a string | C # Program to check whether given string contain panalphabetic window or not ; Return if given string contain panalphabetic window . ; traversing the string ; if character of string is equal to ch , increment ch . ; if all characters are found , return true . ; Driver code
using System ; class GFG { static bool isPanalphabeticWindow ( string s , int n ) { char ch = ' a ' ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ch ) ch ++ ; if ( ch == ' z ' + 1 ) return true ; } return false ; } public static void Main ( ) { string s = " abujm ▁ zvcd ▁ acefc ▁ deghf " + " ▁ gijklem ▁ n ▁ o ▁ p ▁ pafqrstuvwxyzfap " ; int n = s . Length ; if ( isPanalphabeticWindow ( s , n ) ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } }
Program to print characters present at prime indexes in a given string | C # Program to print Characters at Prime index in a given String ; Corner case ; Check from 2 to n - 1 ; Function to print character at prime index ; Loop to check if index prime or not ; Driver code
using System ; class GFG { static bool isPrime ( int n ) { if ( n <= 1 ) return false ; for ( int i = 2 ; i < n ; i ++ ) if ( n % i == 0 ) return false ; return true ; } static void prime_index ( string input ) { int n = input . Length ; for ( int i = 2 ; i <= n ; i ++ ) if ( isPrime ( i ) ) Console . Write ( input [ i - 1 ] ) ; } public static void Main ( ) { string input = " GeeksforGeeks " ; prime_index ( input ) ; } }
Check whether a given string is Heterogram or not | C # Program to check whether the given string is Heterogram or not . ; traversing the string . ; ignore the space ; if already encountered ; else return false . ; Driver code
using System ; class GFG { static bool isHeterogram ( string s , int n ) { int [ ] hash = new int [ 26 ] ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] != ' ▁ ' ) { if ( hash [ s [ i ] - ' a ' ] == 0 ) hash [ s [ i ] - ' a ' ] = 1 ; else return false ; } } return true ; } public static void Main ( ) { string s = " the ▁ big ▁ dwarf ▁ only ▁ jumps " ; int n = s . Length ; if ( isHeterogram ( s , n ) ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } }
Print given sentence into its equivalent ASCII form | C # implementation for converting a string into it 's ASCII equivalent sentence ; Function to compute the ASCII value of each character one by one ; Driver function
using System ; class GeeksforGeeks { static void ASCIISentence ( string str ) { int l = str . Length ; int convert ; for ( int i = 0 ; i < l ; i ++ ) { convert = str [ i ] ; Console . Write ( convert ) ; } } public static void Main ( ) { string str = " GeeksforGeeks " ; Console . WriteLine ( " ASCII ▁ Sentence : " ) ; ASCIISentence ( str ) ; } }
Snake case of a given sentence | C # program to convert given sentence to snake case ; Function to replace spaces and convert into snake case ; Converting space to underscor ; If not space , convert into lower character ; Driver Code ; Calling function
using System ; class GFG { static void convert ( string str ) { int n = str . Length ; string str1 = " " ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] == ' ▁ ' ) str1 = str1 + ' _ ' ; else str1 = str1 + Char . ToLower ( str [ i ] ) ; } Console . Write ( str1 ) ; } static void Main ( ) { string str = " I ▁ got ▁ intern ▁ at ▁ geeksforgeeks " ; convert ( str ) ; } }
Find the size of largest subset of anagram words | C # Program to find the size of largest subset of anagram ; Utility function to find size of largest subset of anagram ; sort the String ; Increment the count of String ; Compute the maximum size of String ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int largestAnagramSet ( String [ ] arr , int n ) { int maxSize = 0 ; Dictionary < String , int > count = new Dictionary < String , int > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { char [ ] temp = arr [ i ] . ToCharArray ( ) ; Array . Sort ( temp ) ; arr [ i ] = new String ( temp ) ; if ( count . ContainsKey ( arr [ i ] ) ) { count [ arr [ i ] ] = count [ arr [ i ] ] + 1 ; } else { count . Add ( arr [ i ] , 1 ) ; } maxSize = Math . Max ( maxSize , count [ arr [ i ] ] ) ; } return maxSize ; } public static void Main ( String [ ] args ) { String [ ] arr = { " ant " , " magenta " , " magnate " , " tan " , " gnamate " } ; int n = arr . Length ; Console . WriteLine ( largestAnagramSet ( arr , n ) ) ; String [ ] arr1 = { " cars " , " bikes " , " arcs " , " steer " } ; n = arr1 . Length ; Console . WriteLine ( largestAnagramSet ( arr1 , n ) ) ; } }