codeparrot/xlcost-text-to-code huggingface dataset:
Number with maximum number of prime factors | C # program to find integer having maximum number of prime factor in first N natural numbers ; Return smallest number having maximum prime factors . ; default value of boolean is false ; Sieve of eratosthenes ; Storing prime numbers . ; Generating number having maximum prime factors . ; Driver code
using System ; using System . Collections ; class GFG { static int maxPrimefactorNum ( int N ) { bool [ ] arr = new bool [ N + 5 ] ; int i ; for ( i = 3 ; i * i <= N ; i += 2 ) { if ( ! arr [ i ] ) { for ( int j = i * i ; j <= N ; j += i ) { arr [ j ] = true ; } } } ArrayList prime = new ArrayList ( ) ; prime . Add ( 2 ) ; for ( i = 3 ; i <= N ; i += 2 ) { if ( ! arr [ i ] ) { prime . Add ( i ) ; } } int ans = 1 ; i = 0 ; while ( ans * ( int ) prime [ i ] <= N && i < prime . Count ) { ans *= ( int ) prime [ i ] ; i ++ ; } return ans ; } public static void Main ( ) { int N = 40 ; Console . Write ( maxPrimefactorNum ( N ) ) ; } }
Highest power of 2 less than or equal to given number | C # program to find highest power of 2 smaller than or equal to n . ; check for the set bits ; Then we remove all but the top bit by xor ' ing ▁ the ▁ ▁ string ▁ of ▁ 1' s with that string of 1 ' s ▁ shifted ▁ one ▁ to ▁ ▁ the ▁ left , ▁ and ▁ we ▁ end ▁ up ▁ with ▁ just ▁ the ▁ one ▁ top ▁ bit ▁ ▁ followed ▁ by ▁ 0' s . ; Driver code
using System ; public class GFG { static int highestPowerof2 ( int x ) { x |= x >> 1 ; x |= x >> 2 ; x |= x >> 4 ; x |= x >> 8 ; x |= x >> 16 ; return x ^ ( x >> 1 ) ; } public static void Main ( String [ ] args ) { int n = 10 ; Console . WriteLine ( highestPowerof2 ( n ) ) ; } }
Sum of all proper divisors of a natural number | C # program to find sum of all divisorsof a natural number ; Function to calculate sum of all proper divisors num -- > given natural number ; Final result of summation of divisors ; find all divisors which divides ' num ' ; if ' i ' is divisor of ' num ' ; if both divisors are same then add it only once else add both ; Add 1 to the result as 1 is also a divisor ; Driver Code
using System ; class GFG { static int divSum ( int num ) { int result = 0 ; for ( int i = 2 ; i <= Math . Sqrt ( num ) ; i ++ ) { if ( num % i == 0 ) { if ( i == ( num / i ) ) result += i ; else result += ( i + num / i ) ; } } return ( result + 1 ) ; } public static void Main ( ) { int num = 36 ; Console . Write ( divSum ( num ) ) ; } }
Find Square Root under Modulo p | Set 1 ( When p is in form of 4 * i + 3 ) | An efficient C # program to find square root under modulo p when p is 7 , 11 , 19 , 23 , 31 , ... etc . ; Utility function to do modular exponentiation . It returns ( x ^ y ) % p . ; int res = 1 ; Initialize result x = x % p ; Update x if it is more than or equal to p ; If y is odd , multiply x with result ; y must be even now y = y >> 1 ; y = y / 2 ; Returns true if square root of n under modulo p exists Assumption : p is of the form 3 * i + 4 where i >= 1 ; Try " + ( n ^ ( ( p ▁ + ▁ 1 ) / 4 ) ) " ; Try " - ( n ▁ ^ ▁ ( ( p ▁ + ▁ 1 ) / 4 ) ) " ; If none of the above two work , then square root doesn 't exist ; Driver program to test
using System ; public class GFG { static int power ( int x , int y , int p ) { while ( y > 0 ) { if ( y % 2 == 1 ) res = ( res * x ) % p ; x = ( x * x ) % p ; } return res ; } static void squareRoot ( int n , int p ) { if ( p % 4 != 3 ) { Console . Write ( " Invalid ▁ Input " ) ; return ; } n = n % p ; int x = power ( n , ( p + 1 ) / 4 , p ) ; if ( ( x * x ) % p == n ) { Console . Write ( " Square ▁ root ▁ is ▁ " + x ) ; return ; } x = p - x ; if ( ( x * x ) % p == n ) { Console . Write ( " Square ▁ root ▁ is ▁ " + x ) ; return ; } Console . Write ( " Square ▁ root ▁ doesn ' t ▁ exist ▁ " ) ; } static public void Main ( ) { int p = 7 ; int n = 2 ; squareRoot ( n , p ) ; } }
Primality Test | Set 3 ( Millerâ €“ Rabin ) | C # program Miller - Rabin primality test ; Utility function to do modular exponentiation . It returns ( x ^ y ) % p ; Initialize result ; Update x if it is more than or equal to p ; If y is odd , multiply x with result ; y must be even now y = y >> 1 ; y = y / 2 ; This function is called for all k trials . It returns false if n is composite and returns false if n is probably prime . d is an odd number such that d * 2 < sup > r < / sup > = n - 1 for some r >= 1 ; Pick a random number in [ 2. . n - 2 ] Corner cases make sure that n > 4 ; Compute a ^ d % n ; Keep squaring x while one of the following doesn 't happen  (i) d does not reach n-1  (ii) (x^2) % n is not 1  (iii) (x^2) % n is not n-1 ; Return composite ; It returns false if n is composite and returns true if n is probably prime . k is an input parameter that determines accuracy level . Higher value of k indicates more accuracy . ; Corner cases ; Find r such that n = 2 ^ d * r + 1 for some r >= 1 ; Iterate given nber of ' k ' times ; Driver Code
using System ; class GFG { static int power ( int x , int y , int p ) { int res = 1 ; x = x % p ; while ( y > 0 ) { if ( ( y & 1 ) == 1 ) res = ( res * x ) % p ; x = ( x * x ) % p ; } return res ; } static bool miillerTest ( int d , int n ) { Random r = new Random ( ) ; int a = 2 + ( int ) ( r . Next ( ) % ( n - 4 ) ) ; int x = power ( a , d , n ) ; if ( x == 1 x == n - 1 ) return true ; while ( d != n - 1 ) { x = ( x * x ) % n ; d *= 2 ; if ( x == 1 ) return false ; if ( x == n - 1 ) return true ; } return false ; } static bool isPrime ( int n , int k ) { if ( n <= 1 n == 4 ) return false ; if ( n <= 3 ) return true ; int d = n - 1 ; while ( d % 2 == 0 ) d /= 2 ; for ( int i = 0 ; i < k ; i ++ ) if ( miillerTest ( d , n ) == false ) return false ; return true ; } static void Main ( ) { int k = 4 ; Console . WriteLine ( " All ▁ primes ▁ smaller ▁ " + " than ▁ 100 : ▁ " ) ; for ( int n = 1 ; n < 100 ; n ++ ) if ( isPrime ( n , k ) ) Console . Write ( n + " ▁ " ) ; } }
Length of the Longest Consecutive 1 s in Binary Representation | C # program to find length of the longest consecutive 1 s in binary representation of a number . ; Function to find length of the longest consecutive 1 s in binary representation of a number ; Initialize result ; Count the number of iterations to reach x = 0. ; This operation reduces length of every sequence of 1 s by one . ; Driver code
using System ; class GFG { private static int maxConsecutiveOnes ( int x ) { int count = 0 ; while ( x != 0 ) { x = ( x & ( x << 1 ) ) ; count ++ ; } return count ; } public static void Main ( ) { Console . WriteLine ( maxConsecutiveOnes ( 14 ) ) ; Console . Write ( maxConsecutiveOnes ( 222 ) ) ; } }
Subtract two numbers without using arithmetic operators | C # Program to subtract two Number without using arithmetic operator ; Iterate till there is no carry ; borrow contains common set bits of y and unset bits of x ; Subtraction of bits of x and y where at least one of the bits is not set ; Borrow is shifted by one so that subtracting it from x gives the required sum ; Driver Code
using System ; class GFG { static int subtract ( int x , int y ) { while ( y != 0 ) { int borrow = ( ~ x ) & y ; x = x ^ y ; y = borrow << 1 ; } return x ; } public static void Main ( ) { int x = 29 , y = 13 ; Console . WriteLine ( " x ▁ - ▁ y ▁ is ▁ " + subtract ( x , y ) ) ; } }
Subtract two numbers without using arithmetic operators | C # Program to subtract two Number without using arithmetic operator Recursive implementation . ; Driver program
using System ; class GFG { static int subtract ( int x , int y ) { if ( y == 0 ) return x ; return subtract ( x ^ y , ( ~ x & y ) << 1 ) ; } public static void Main ( ) { int x = 29 , y = 13 ; Console . WriteLine ( " x ▁ - ▁ y ▁ is ▁ " + subtract ( x , y ) ) ; } }
Kth ancestor of all nodes in an N | C # implementation of the above approach ; Function to add an edge in the tree ; DFS to find the Kth ancestor of every node ; Pushing current node in the vector ; Traverse its neighbors ; If K ancestors are not found for current node ; Add the Kth ancestor for the node ; Function to find Kth ancestor of each node ; Building the tree ; Stores all parents of a node ; Store Kth ancestor of all nodes ; Print the ancestors ; Driver code ; Given N and K ; Given edges of n - ary tree ; Function call
using System ; using System . Collections . Generic ; class GFG { static void addEdge ( List < int > [ ] v , int x , int y ) { v [ x ] . Add ( y ) ; v [ y ] . Add ( x ) ; } static void dfs ( List < int > [ ] tree , List < int > temp , int [ ] ancestor , int u , int parent , int k ) { temp . Add ( u ) ; foreach ( int i in tree [ u ] ) { if ( i == parent ) continue ; dfs ( tree , temp , ancestor , i , u , k ) ; } temp . RemoveAt ( temp . Count - 1 ) ; if ( temp . Count < k ) { ancestor [ u ] = - 1 ; } else { ancestor [ u ] = temp [ temp . Count - k ] ; } } static void KthAncestor ( int N , int K , int E , int [ , ] edges ) { List < int > [ ] tree = new List < int > [ N + 1 ] ; for ( int i = 0 ; i < tree . Length ; i ++ ) tree [ i ] = new List < int > ( ) ; for ( int i = 0 ; i < E ; i ++ ) { addEdge ( tree , edges [ i , 0 ] , edges [ i , 1 ] ) ; } List < int > temp = new List < int > ( ) ; int [ ] ancestor = new int [ N + 1 ] ; dfs ( tree , temp , ancestor , 1 , 0 , K ) ; for ( int i = 1 ; i <= N ; i ++ ) { Console . Write ( ancestor [ i ] + " ▁ " ) ; } } public static void Main ( String [ ] args ) { int N = 9 ; int K = 2 ; int E = 8 ; int [ , ] edges = { { 1 , 2 } , { 1 , 3 } , { 2 , 4 } , { 2 , 5 } , { 2 , 6 } , { 3 , 7 } , { 3 , 8 } , { 3 , 9 } } ; KthAncestor ( N , K , E , edges ) ; } }
Minimize Array length by repeatedly replacing co | C # Program for the above approach ; Recursive function to return gcd of a and b ; Function to find the readonly array length by replacing coprime pair with 1 ; Iterate over all pairs of element ; Check if gcd is 1 ; If no coprime pair found return false ; Driver code ; Check if atleast one coprime pair exists in the array ; If no such pair exists
using System ; class GFG { static int __gcd ( int a , int b ) { return b == 0 ? a : __gcd ( b , a % b ) ; } static bool hasCoprimePair ( int [ ] arr , int n ) { for ( int i = 0 ; i < n - 1 ; i ++ ) { for ( int j = i + 1 ; j < n ; j ++ ) { if ( ( __gcd ( arr [ i ] , arr [ j ] ) ) == 1 ) { return true ; } } } return false ; } public static void Main ( String [ ] args ) { int n = 3 ; int [ ] arr = { 6 , 9 , 15 } ; if ( hasCoprimePair ( arr , n ) ) { Console . Write ( 1 + " STRNEWLINE " ) ; } else { Console . Write ( n + " STRNEWLINE " ) ; } } }
Count of ways to split N into Triplets forming a Triangle | C # Program to implement the above approach ; Function to return the required number of ways ; Check if a , b , c can form a triangle or not ; Return number of ways ; Driver Code
using System ; class GFG { static int Numberofways ( int n ) { int count = 0 ; for ( int a = 1 ; a < n ; a ++ ) { for ( int b = 1 ; b < n ; b ++ ) { int c = n - ( a + b ) ; if ( a + b > c && a + c > b && b + c > a ) { count ++ ; } } } return count ; } static public void Main ( ) { int n = 15 ; Console . WriteLine ( Numberofways ( n ) ) ; } }
Count of pairs having each element equal to index of the other from an Array | C # Program to implement the above approach ; Function to print the count of pair ; Iterate over all the elements of the array ; Increment the count ; Print the result ; Driver Code
using System ; class GFG { static void countPairs ( int N , int [ ] arr ) { int count = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( i == arr [ arr [ i ] - 1 ] - 1 ) { count ++ ; } } Console . Write ( count / 2 ) ; } public static void Main ( string [ ] args ) { int [ ] arr = { 2 , 1 , 4 , 3 } ; int N = arr . Length ; countPairs ( N , arr ) ; } }
Find length of longest Fibonacci like subsequence | C # implementation of above approach ; Function to return the max Length of Fibonacci subsequence ; Store all array elements in a hash table ; check until next fib element is found ; next element of fib subseq ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static int LongestFibSubseq ( int [ ] A , int n ) { SortedSet < int > S = new SortedSet < int > ( ) ; foreach ( int t in A ) { S . Add ( t ) ; } int maxLen = 0 , x , y ; for ( int i = 0 ; i < n ; ++ i ) { for ( int j = i + 1 ; j < n ; ++ j ) { x = A [ j ] ; y = A [ i ] + A [ j ] ; int length = 3 ; while ( S . Contains ( y ) && y != last ( S ) ) { int z = x + y ; x = y ; y = z ; maxLen = Math . Max ( maxLen , ++ length ) ; } } } return maxLen >= 3 ? maxLen : 0 ; } static int last ( SortedSet < int > S ) { int ans = 0 ; foreach ( int a in S ) ans = a ; return ans ; } public static void Main ( String [ ] args ) { int [ ] A = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 } ; int n = A . Length ; Console . Write ( LongestFibSubseq ( A , n ) ) ; } }
Maximum types of candies a person can eat if only N / 2 of them can be eaten | C # program for the above approach ; Function to find number of candy types ; Declare a hashset to store candies ; Traverse the given array and inserts element into set ; Return the result ; Function to find maximum number of types of candies a person can eat ; Store the number of candies allowed to eat ; Store the number of candy types ; Return the result ; Driver code ; Given Input ; Function Call
using System ; using System . Collections . Generic ; public class GFG { public static int num_candyTypes ( int [ ] candies ) { Dictionary < int , int > s = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < candies . Length ; i ++ ) { if ( ! s . ContainsKey ( candies [ i ] ) ) s . Add ( candies [ i ] , 1 ) ; } return s . Count ; } public static void distribute_candies ( int [ ] candies ) { int allowed = candies . Length / 2 ; int types = num_candyTypes ( candies ) ; if ( types < allowed ) Console . WriteLine ( types ) ; else Console . WriteLine ( allowed ) ; } static public void Main ( ) { int [ ] candies = { 4 , 4 , 5 , 5 , 3 , 3 } ; distribute_candies ( candies ) ; } }
Length of diagonals of a Rhombus using length of Side and vertex Angle | C # program to implement the above approach ; Function to calculate the length of diagonals of a rhombus using length of sides and vertex angle ; Driver Code
using System ; class GFG { static double [ ] Length_Diagonals ( int a , double theta ) { double p = a * Math . Sqrt ( 2 + ( 2 * Math . Cos ( theta * ( Math . PI / 180 ) ) ) ) ; double q = a * Math . Sqrt ( 2 - ( 2 * Math . Cos ( theta * ( Math . PI / 180 ) ) ) ) ; return new double [ ] { p , q } ; } public static void Main ( String [ ] args ) { int A = 6 ; double theta = 45 ; double [ ] ans = Length_Diagonals ( A , theta ) ; Console . Write ( " { 0 : F2 } " + " ▁ " + " { 1 : F2 } " , ans [ 0 ] , ans [ 1 ] ) ; } }
Count of even and odd set bit with array element after XOR with K | C # program to count the set bits after taking XOR with a number K ; Function to get no of set bits in binary representation of positive integer n ; Function to store EVEN and odd variable ; Store the count of even and odd set bit ; Count the set bit using in built function ; Count of set - bit of K ; If y is odd then , count of even and odd set bit will be interchanged ; Else it will remain same as the original array ; Driver 's Code ; Function call to count even and odd
using System ; public class GFG { static int __builtin_popcount ( int n ) { int count = 0 ; while ( n > 0 ) { count += n & 1 ; n >>= 1 ; } return count ; } static void countEvenOdd ( int [ ] arr , int n , int K ) { int even = 0 , odd = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int x = __builtin_popcount ( arr [ i ] ) ; if ( x % 2 == 0 ) even ++ ; else odd ++ ; } int y ; y = __builtin_popcount ( K ) ; if ( ( y & 1 ) != 0 ) { Console . WriteLine ( " Even ▁ = ▁ " + odd + " , ▁ Odd ▁ = ▁ " + even ) ; } else { Console . WriteLine ( " Even ▁ = ▁ " + even + " , ▁ Odd ▁ = ▁ " + odd ) ; } } public static void Main ( string [ ] args ) { int [ ] arr = { 4 , 2 , 15 , 9 , 8 , 8 } ; int K = 3 ; int n = arr . Length ; countEvenOdd ( arr , n , K ) ; } }
Number of ways to choose a pair containing an even and an odd number from 1 to N | C # implementation of the above approach ; Driver code
using System ; class GFG { public static void Main ( ) { int N = 6 ; int Even = N / 2 ; int Odd = N - Even ; Console . WriteLine ( Even * Odd ) ; } }
Longest subsequence from an array of pairs having first element increasing and second element decreasing . | C # program for the above approach ; Recursive function to find the length of the longest subsequence of pairs whose first element is increasing and second is decreasing ; Base case ; Not include the current pair in the longest subsequence ; Including the current pair in the longest subsequence ; Driver Code ; Given Input ; Function Call
using System ; class GFG { public static int longestSubSequence ( int [ , ] A , int N , int ind , int lastf , int lasts ) { ind = ( ind > 0 ? ind : 0 ) ; lastf = ( lastf > 0 ? lastf : Int32 . MinValue ) ; lasts = ( lasts > 0 ? lasts : Int32 . MaxValue ) ; if ( ind == N ) return 0 ; int ans = longestSubSequence ( A , N , ind + 1 , lastf , lasts ) ; if ( A [ ind , 0 ] > lastf && A [ ind , 1 ] < lasts ) ans = Math . Max ( ans , longestSubSequence ( A , N , ind + 1 , A [ ind , 0 ] , A [ ind , 1 ] ) + 1 ) ; return ans ; } public static void Main ( ) { int [ , ] A = { { 1 , 2 } , { 2 , 2 } , { 3 , 1 } } ; int N = A . GetLength ( 0 ) ; Console . Write ( longestSubSequence ( A , N ) ) ; } }
Count triples with Bitwise AND equal to Zero | C # program for the above approach ; Function to find the number of triplets whose Bitwise AND is 0. ; Stores the count of triplets having bitwise AND equal to 0 ; Stores frequencies of all possible A [ i ] & A [ j ] ; Traverse the array ; Update frequency of Bitwise AND of all array elements with a ; Traverse the array ; Iterate the map ; If bitwise AND of triplet is zero , increment cnt ; Return the number of triplets whose Bitwise AND is 0. ; Driver Code ; Input Array ; Function Call
using System ; using System . Collections . Generic ; class GFG { static int countTriplets ( int [ ] A ) { int cnt = 0 ; Dictionary < int , int > tuples = new Dictionary < int , int > ( ) ; foreach ( int a in A ) foreach ( int b in A ) { if ( tuples . ContainsKey ( a & b ) ) tuples [ a & b ] = tuples [ a & b ] + 1 ; else tuples . Add ( a & b , 1 ) ; } foreach ( int a in A ) foreach ( KeyValuePair < int , int > t in tuples ) if ( ( t . Key & a ) == 0 ) cnt += t . Value ; return cnt ; } public static void Main ( String [ ] args ) { int [ ] A = { 2 , 1 , 3 } ; Console . Write ( countTriplets ( A ) ) ; } }
Program to print Spiral Pattern | C # implementation of the approach ; Create row and col to traverse rows and columns ; Variable to determine the movement r = right , l = left , d = down , u = upper ; Array for matrix ; Assign the value ; switch - case to determine the next index ; If right , go right ; if left , go left ; if up , go up ; if down , go down ; Check if the matrix has reached array boundary ; Add the left size for the next boundary ; If 2 rotations has been made , decrease the size left by 1 ; switch - case to rotate the movement ; if right , rotate to down ; if down , rotate to left ; if left , rotate to up ; if up , rotate to right ; Print the matrix ; Driver Code ; Get the size of size ; Print the Spiral Pattern
using System ; class GFG { public static void printSpiral ( int size ) { int row = 0 , col = 0 ; int boundary = size - 1 ; int sizeLeft = size - 1 ; int flag = 1 ; char move = ' r ' ; int [ , ] matrix = new int [ size , size ] ; for ( int i = 1 ; i < size * size + 1 ; i ++ ) { matrix [ row , col ] = i ; switch ( move ) { case ' r ' : col += 1 ; break ; case ' l ' : col -= 1 ; break ; case ' u ' : row -= 1 ; break ; case ' d ' : row += 1 ; break ; } if ( i == boundary ) { boundary += sizeLeft ; if ( flag != 2 ) { flag = 2 ; } else { flag = 1 ; sizeLeft -= 1 ; } switch ( move ) { case ' r ' : move = ' d ' ; break ; case ' d ' : move = ' l ' ; break ; case ' l ' : move = ' u ' ; break ; case ' u ' : move = ' r ' ; break ; } } } for ( row = 0 ; row < size ; row ++ ) { for ( col = 0 ; col < size ; col ++ ) { int n = matrix [ row , col ] ; Console . Write ( ( n < 10 ) ? ( n + " ▁ " ) : ( n + " ▁ " ) ) ; } Console . WriteLine ( ) ; } } public static void Main ( String [ ] args ) { int size = 5 ; printSpiral ( size ) ; } }
Find the last player to be able to flip a character in a Binary String | C # program to implement the above approach ; Function to check if player A wins the game or not ; Stores size of the groups of 0 s ; Stores size of the group of 0 s ; Traverse the array ; Increment c by 1 if a [ i ] is 0 ; Otherwise , push the size in array and reset c to 0 ; If there is no substring of odd length consisting only of 0 s ; If there is only 1 substring of odd length consisting only of 0 s ; Otherwise ; Stores the size of the largest and second largest substrings of 0 s ; Traverse the array v [ ] ; If current element is greater than first , then update both first and second ; If arr [ i ] is in between first and second , then update second ; If the condition is satisfied ; Driver Code
using System ; using System . Collections . Generic ; using System . Linq ; class GFG { static void findWinner ( string a , int n ) { List < int > v = new List < int > ( ) ; int c = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] == '0' ) { c ++ ; } else { if ( c != 0 ) v . Add ( c ) ; c = 0 ; } } if ( c != 0 ) v . Add ( c ) ; if ( v . Count == 0 ) { Console . Write ( " Player ▁ B " ) ; return ; } if ( v . Count == 1 ) { if ( ( v [ 0 ] & 1 ) != 0 ) Console . Write ( " Player ▁ A " ) ; else Console . Write ( " Player ▁ B " ) ; return ; } int first = Int32 . MinValue ; int second = Int32 . MinValue ; for ( int i = 0 ; i < v . Count ; i ++ ) { if ( a [ i ] > first ) { second = first ; first = a [ i ] ; } else if ( a [ i ] > second && a [ i ] != first ) second = a [ i ] ; } if ( ( first & 1 ) != 0 && ( first + 1 ) / 2 > second ) Console . Write ( " Player ▁ A " ) ; else Console . Write ( " Player ▁ B " ) ; } public static void Main ( String [ ] args ) { string S = "1100011" ; int N = S . Length ; findWinner ( S , N ) ; } }
Check if K palindromic strings can be formed from a given string | C # program to check whether the string is K palindrome or not ; Function to check whether the string is K palindrome or not ; Map to frequency of character ; Check when k is given as same as length of string ; Storing the frequency of every character in map ; If K is greater than size of then return false ; Check that number of character having the odd frequency ; If k is less than number of odd frequency character then it is again false otherwise true ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static bool can_Construct ( String S , int K ) { Dictionary < char , int > m = new Dictionary < char , int > ( ) ; int p = 0 ; if ( S . Length == K ) return true ; for ( int i = 0 ; i < S . Length ; i ++ ) if ( ! m . ContainsKey ( S [ i ] ) ) m . Add ( S [ i ] , 1 ) ; else m [ S [ i ] ] = m [ S [ i ] ] + 1 ; if ( K > S . Length ) return false ; else { foreach ( int h in m . Values ) { if ( h % 2 != 0 ) p = p + 1 ; } } if ( K < p ) return false ; return true ; } public static void Main ( String [ ] args ) { String S = " annabelle " ; int K = 4 ; if ( can_Construct ( S , K ) ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } }
Check if two strings are same ignoring their cases |  ; Function to compare two Strings ignoring their cases ; Convert to lowercase using toUpperCase function ; Comparing both using inbuilt function ; if Strings are equal , return true otherwise false ; Function to print the same or not same if Strings are equal or not equal ; Driver Code
using System ; class GFG { static bool equalIgnoreCase ( String str1 , String str2 ) { str1 = str1 . ToUpper ( ) ; str2 = str2 . ToUpper ( ) ; int x = str1 . CompareTo ( str2 ) ; if ( x != 0 ) { return false ; } else { return true ; } } static void equalIgnoreCaseUtil ( String str1 , String str2 ) { bool res = equalIgnoreCase ( str1 , str2 ) ; if ( res == true ) { Console . WriteLine ( " Same " ) ; } else { Console . WriteLine ( " Not ▁ Same " ) ; } } public static void Main ( ) { String str1 , str2 ; str1 = " Geeks " ; str2 = " geeks " ; equalIgnoreCaseUtil ( str1 , str2 ) ; str1 = " Geek " ; str2 = " geeksforgeeks " ; equalIgnoreCaseUtil ( str1 , str2 ) ; } }