codeparrot/xlcost-text-to-code huggingface dataset:
Find all strings that match specific pattern in a dictionary | C # program to print all the strings that match the given pattern where every character in the pattern is uniquely mapped to a character in the dictionary ; Function to print all the strings that match the given pattern where every character in the pattern is uniquely mapped to a character in the dictionary ; len is length of the pattern ; For each word in the dictionary ; Driver Code
using System ; using System . Collections ; using System . Collections . Generic ; class GFG { static bool check ( string pattern , string word ) { if ( pattern . Length != word . Length ) return false ; int [ ] ch = new int [ 128 ] ; int Len = word . Length ; for ( int i = 0 ; i < Len ; i ++ ) { if ( ch [ ( int ) pattern [ i ] ] == 0 ) { ch [ ( int ) pattern [ i ] ] = word [ i ] ; } else if ( ch [ ( int ) pattern [ i ] ] != word [ i ] ) { return false ; } } return true ; } static void findMatchedWords ( HashSet < string > dict , string pattern ) { int Len = pattern . Length ; string result = " ▁ " ; foreach ( string word in dict ) { if ( check ( pattern , word ) ) { result = word + " ▁ " + result ; } } Console . Write ( result ) ; } static void Main ( ) { HashSet < string > dict = new HashSet < string > ( new string [ ] { " abb " , " abc " , " xyz " , " xyy " } ) ; string pattern = " foo " ; findMatchedWords ( dict , pattern ) ; } }
Count words in a given string | C # program to count total number of words in the string ; Function to count total number of words in the string ; Check if the string is null or empty then return zero ; Converting the given string into a character array ; Check if the character is a letter and index of character array doesn 't  equal to end of line that means, it is  a word and set isWord by true ; Check if the character is not a letter that means there is a space , then we increment the wordCount by one and set the isWord by false ; Check for the last word of the sentence and increment the wordCount by one ; Return the total number of words in the string ; Driver Code ; Given String str ; Print the result
using System ; public class GFG { static int countWords ( String str ) { if ( str == null ) { return 0 ; } int wordCount = 0 ; bool isWord = false ; int endOfLine = str . Length - 1 ; char [ ] ch = str . ToCharArray ( ) ; for ( int i = 0 ; i < ch . Length ; i ++ ) { if ( Char . IsLetter ( ch [ i ] ) && i != endOfLine ) { isWord = true ; } else if ( ! Char . IsLetter ( ch [ i ] ) && isWord ) { wordCount ++ ; isWord = false ; } else if ( Char . IsLetter ( ch [ i ] ) && i == endOfLine ) { wordCount ++ ; } } return wordCount ; } static public void Main ( ) { string str = " One ▁ two TABSYMBOL three STRNEWLINE ▁ four TABSYMBOL five ▁ " ; Console . WriteLine ( " No ▁ of ▁ words ▁ : ▁ " + countWords ( str ) ) ; } }
Reverse words in a given string | C # code to reverse a string ; Reverse the string ; Check if number of words is even ; Find the middle word ; Starting from the middle start swapping words at jth position and l - 1 - j position ; Check if number of words is odd ; Find the middle word ; Starting from the middle start swapping the words at jth position and l - 1 - j position ; Return the reversed sentence ; Driver Code
using System ; class GFG { public static String [ ] RevString ( String [ ] s , int l ) { if ( l % 2 == 0 ) { int j = l / 2 ; while ( j <= l - 1 ) { String temp ; temp = s [ l - j - 1 ] ; s [ l - j - 1 ] = s [ j ] ; s [ j ] = temp ; j += 1 ; } } else { int j = ( l / 2 ) + 1 ; while ( j <= l - 1 ) { String temp ; temp = s [ l - j - 1 ] ; s [ l - j - 1 ] = s [ j ] ; s [ j ] = temp ; j += 1 ; } } return s ; } public static void Main ( String [ ] args ) { String s = " getting ▁ good ▁ at ▁ coding ▁ " + " needs ▁ a ▁ lot ▁ of ▁ practice " ; String [ ] words = s . Split ( " \\ s " ) ; words = RevString ( words , words . Length ) ; s = String . Join ( " ▁ " , words ) ; Console . WriteLine ( s ) ; } }
Print path from root to all nodes in a Complete Binary Tree | C # program to print path from root to all nodes in a complete binary tree . ; Function to print path of all the nodes nth node represent as given node kth node represents as left and right node ; base condition if kth node value is greater then nth node then its means kth node is not valid so we not store it into the res simply we just return ; Storing node into res ; Print the path from root to node ; store left path of a tree So for left we will go node ( kThNode * 2 ) ; right path of a tree and for right we will go node ( kThNode * 2 + 1 ) ; Function to print path from root to all of the nodes ; res is for store the path from root to particulate node ; Print path from root to all node . third argument 1 because of we have to consider root node is 1 ; Driver Code ; Given Node ; Print path from root to all node .
using System ; using System . Collections . Generic ; class GFG { static void printPath ( List < int > res , int nThNode , int kThNode ) { if ( kThNode > nThNode ) return ; res . Add ( kThNode ) ; for ( int i = 0 ; i < res . Count ; i ++ ) Console . Write ( res [ i ] + " ▁ " ) ; Console . Write ( " STRNEWLINE " ) ; printPath ( res , nThNode , kThNode * 2 ) ; printPath ( res , nThNode , kThNode * 2 + 1 ) ; res . RemoveAt ( res . Count - 1 ) ; } static void printPathToCoverAllNodeUtil ( int nThNode ) { List < int > res = new List < int > ( ) ; printPath ( res , nThNode , 1 ) ; } public static void Main ( String [ ] args ) { int nThNode = 7 ; printPathToCoverAllNodeUtil ( nThNode ) ; } }
Maximum number of region in which N non | C # program to implement the above problem ; Function to find the maximum number of regions on a plane ; print the maximum number of regions ; Driver code
using System ; class GFG { static void maxRegions ( int n ) { int num ; num = n * ( n + 1 ) / 2 + 1 ; Console . WriteLine ( num ) ; } public static void Main ( String [ ] args ) { int n = 10 ; maxRegions ( n ) ; } }
Check whether jigsaw puzzle solveable or not | C # program for the above approach ; Function to check if the jigsaw Puzzle is solveable or not ; Base Case ; By placing the blank tabs as a chain ; Driver Code
using System ; class GFG { static void checkSolveable ( int n , int m ) { if ( n == 1 m == 1 ) Console . WriteLine ( " YES " ) ; else if ( m == 2 && n == 2 ) Console . WriteLine ( " YES " ) ; else Console . WriteLine ( " NO " ) ; } public static void Main ( ) { int n = 1 , m = 3 ; checkSolveable ( n , m ) ; } }
Check if it is possible to reach ( X , Y ) from ( 1 , 0 ) by given steps | C # program for the above approach ; Function to find the GCD of two numbers a and b ; Base Case ; Recursively find the GCD ; Function to check if ( x , y ) can be reached from ( 1 , 0 ) from given moves ; If GCD is 1 , then print " Yes " ; Driver Code ; Given X and Y ; Function call
using System ; class GFG { static int GCD ( int a , int b ) { if ( b == 0 ) return a ; else return GCD ( b , a % b ) ; } static void check ( int x , int y ) { if ( GCD ( x , y ) == 1 ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } public static void Main ( ) { int X = 2 , Y = 7 ; check ( X , Y ) ; } }
Probability of Euler 's Totient Function in a range [L, R] to be divisible by M | C # Program to implement the above approach ; Seieve of Erotosthenes to compute all primes ; If prime ; Mark all its multiples as non - prime ; Function to find the probability of Euler 's Totient Function in a given range ; Initializing two arrays with values from L to R for Euler 's totient ; Indexing from 0 ; If the current number is prime ; Checking if i is prime factor of numbers in range L to R ; Update all the numbers which has prime factor i ; If number in range has a prime factor > Math . Sqrt ( number ) ; Count those which are divisible by M ; Return the result ; Driver Code
using System ; class GFG { static readonly int size = 1000001 ; static void seiveOfEratosthenes ( int [ ] prime ) { prime [ 0 ] = 1 ; prime [ 1 ] = 0 ; for ( int i = 2 ; i * i < 1000001 ; i ++ ) { if ( prime [ i ] == 0 ) { for ( int j = i * i ; j < 1000001 ; j += i ) { prime [ j ] = 1 ; } } } } static float probabiltyEuler ( int [ ] prime , int L , int R , int M ) { int [ ] arr = new int [ size ] ; int [ ] eulerTotient = new int [ size ] ; int count = 0 ; for ( int i = L ; i <= R ; i ++ ) { eulerTotient [ i - L ] = i ; arr [ i - L ] = i ; } for ( int i = 2 ; i < 1000001 ; i ++ ) { if ( prime [ i ] == 0 ) { for ( int j = ( L / i ) * i ; j <= R ; j += i ) { if ( j - L >= 0 ) { eulerTotient [ j - L ] = eulerTotient [ j - L ] / i * ( i - 1 ) ; while ( arr [ j - L ] % i == 0 ) { arr [ j - L ] /= i ; } } } } } for ( int i = L ; i <= R ; i ++ ) { if ( arr [ i - L ] > 1 ) { eulerTotient [ i - L ] = ( eulerTotient [ i - L ] / arr [ i - L ] ) * ( arr [ i - L ] - 1 ) ; } } for ( int i = L ; i <= R ; i ++ ) { if ( ( eulerTotient [ i - L ] % M ) == 0 ) { count ++ ; } } return ( float ) ( 1.0 * count / ( R + 1 - L ) ) ; } public static void Main ( String [ ] args ) { int [ ] prime = new int [ size ] ; seiveOfEratosthenes ( prime ) ; int L = 1 , R = 7 , M = 3 ; Console . Write ( probabiltyEuler ( prime , L , R , M ) ) ; } }
Largest odd divisor Game to check which player wins | C # implementation to find the Largest Odd Divisior Game to check which player wins ; Function to find the Largest Odd Divisior Game to check which player wins ; Check if n == 1 then player 2 will win ; Check if n == 2 or n is odd ; While n is greater than k and divisible by 2 keep incrementing tha val ; Loop to find greatest odd divisor ; Check if n is a power of 2 ; Check if cnt is not one then player 1 wins ; Driver code
using System ; class GFG { public static void findWinner ( int n , int k ) { int cnt = 0 ; if ( n == 1 ) Console . Write ( " No " ) ; else if ( ( n & 1 ) != 0 n == 2 ) Console . Write ( " Yes " ) ; else { int tmp = n ; int val = 1 ; while ( tmp > k && tmp % 2 == 0 ) { tmp /= 2 ; val *= 2 ; } for ( int i = 3 ; i <= Math . Sqrt ( tmp ) ; i ++ ) { while ( tmp % i == 0 ) { cnt ++ ; tmp /= i ; } } if ( tmp > 1 ) cnt ++ ; if ( val == n ) Console . Write ( " No " ) ; else if ( n / tmp == 2 && cnt == 1 ) Console . Write ( " No " ) ; else Console . Write ( " Yes " ) ; } } public static void Main ( string [ ] args ) { int n = 1 , k = 1 ; findWinner ( n , k ) ; } }
Find all numbers up to N which are both Pentagonal and Hexagonal | C # program of the above approach ; Function to print numbers upto N which are both pentagonal as well as hexagonal numbers ; Calculate i - th pentagonal number ; Check if the pentagonal number pn is hexagonal or not ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static void pen_hex ( long n ) { long pn = 1 ; for ( long i = 1 ; ; i ++ ) { pn = i * ( 3 * i - 1 ) / 2 ; if ( pn > n ) break ; double seqNum = ( 1 + Math . Sqrt ( 8 * pn + 1 ) ) / 4 ; if ( seqNum == ( long ) ( seqNum ) ) { Console . Write ( pn + " , ▁ " ) ; } } } public static void Main ( string [ ] args ) { long N = 1000000 ; pen_hex ( N ) ; } }
Check if row | C # implementation to check if row - major order traversal of matrix is palindrome or not ; Function to check if row - major order traversal of the matrix is is palindrome ; Loop to check if the matrix is matrix is palindrome or not ; Driver Code
using System ; class GFG { static bool isPal ( int [ , ] a , int n , int m ) { for ( int i = 0 ; i < n / 2 ; i ++ ) { for ( int j = 0 ; j < m - 1 ; j ++ ) { if ( a [ i , j ] != a [ n - 1 - i , m - 1 - j ] ) return false ; } } return true ; } public static void Main ( String [ ] args ) { int n = 3 , m = 3 ; int [ , ] a = { { 1 , 2 , 3 } , { 4 , 5 , 4 } , { 3 , 2 , 1 } } ; if ( isPal ( a , n , m ) ) { Console . Write ( " YES " + " STRNEWLINE " ) ; } else { Console . Write ( " NO " + " STRNEWLINE " ) ; } } }
Find the smallest number whose sum of digits is N | C # program to find the smallest number whose sum of digits is also N ; Function to get sum of digits ; Function to find the smallest number whose sum of digits is also N ; Checking if number has sum of digits = N ; Driver code
using System ; class GFG { static int getSum ( int n ) { int sum = 0 ; while ( n != 0 ) { sum = sum + n % 10 ; n = n / 10 ; } return sum ; } static void smallestNumber ( int N ) { int i = 1 ; while ( 1 != 0 ) { if ( getSum ( i ) == N ) { Console . Write ( i ) ; break ; } i ++ ; } } public static void Main ( String [ ] args ) { int N = 10 ; smallestNumber ( N ) ; } }
Rare Numbers | C # implementation to check if N is a Rare number ; Iterative function to reverse digits of num ; Function to check if N is perfect square ; Find floating point value of square root of x . ; If square root is an integer ; Function to check if N is an Rare number ; Find reverse of N ; Number should be non - palindromic ; Driver code
using System ; class GFG { static int reversDigits ( int num ) { int rev_num = 0 ; while ( num > 0 ) { rev_num = rev_num * 10 + num % 10 ; num = num / 10 ; } return rev_num ; } static bool isPerfectSquare ( double x ) { double sr = Math . Sqrt ( x ) ; return ( ( sr - Math . Floor ( sr ) ) == 0 ) ; } static bool isRare ( int N ) { int reverseN = reversDigits ( N ) ; if ( reverseN == N ) return false ; return isPerfectSquare ( N + reverseN ) && isPerfectSquare ( N - reverseN ) ; } public static void Main ( String [ ] args ) { int n = 65 ; if ( isRare ( n ) ) { Console . WriteLine ( " Yes " ) ; } else { Console . WriteLine ( " No " ) ; } } }
Count numbers from range whose prime factors are only 2 and 3 using Arrays | Set 2 | C # program to count the elements in the range [ L , R ] whose prime factors are only 2 and 3. ; Function which will calculate the elements in the given range ; Store the current power of 2 ; Store the current power of 3 ; power23 [ ] will store pairwise product of elements of power2 and power3 that are <= r ; Insert in power23 , ] only if mul <= r ; Store the required answer ; Print the result ; Driver code
using System ; using System . Collections . Generic ; class GFG { static void calc_ans ( int l , int r ) { List < int > power2 = new List < int > ( ) , power3 = new List < int > ( ) ; int mul2 = 1 ; while ( mul2 <= r ) { power2 . Add ( mul2 ) ; mul2 *= 2 ; } int mul3 = 1 ; while ( mul3 <= r ) { power3 . Add ( mul3 ) ; mul3 *= 3 ; } List < int > power23 = new List < int > ( ) ; for ( int x = 0 ; x < power2 . Count ; x ++ ) { for ( int y = 0 ; y < power3 . Count ; y ++ ) { int mul = power2 [ x ] * power3 [ y ] ; if ( mul == 1 ) continue ; if ( mul <= r ) power23 . Add ( mul ) ; } } int ans = 0 ; foreach ( int x in power23 ) { if ( x >= l && x <= r ) ans ++ ; } Console . Write ( ans + " STRNEWLINE " ) ; } public static void Main ( String [ ] args ) { int l = 1 , r = 10 ; calc_ans ( l , r ) ; } }
Count of K length subsequence whose product is even | C # implementation to count of K length subsequence whose product is even ; Function to calculate nCr ; Returns factorial of n ; Function for finding number of K length subsequences whose product is even number ; Counting odd numbers in the array ; Driver code
using System ; class GFG { static int nCr ( int n , int r ) { if ( r > n ) return 0 ; return fact ( n ) / ( fact ( r ) * fact ( n - r ) ) ; } static int fact ( int n ) { int res = 1 ; for ( int i = 2 ; i <= n ; i ++ ) res = res * i ; return res ; } static int countSubsequences ( int [ ] arr , int n , int k ) { int countOdd = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % 2 == 1 ) countOdd ++ ; } int ans = nCr ( n , k ) - nCr ( countOdd , k ) ; return ans ; } public static void Main ( String [ ] args ) { int [ ] arr = { 2 , 4 } ; int K = 1 ; int N = arr . Length ; Console . WriteLine ( countSubsequences ( arr , N , K ) ) ; } }
Find most significant bit of a number X in base Y | C # Program to find the first digit of X in base Y ; Function to find the first digit of X in base Y ; calculating number of digits of x in base y ; finding first digit of x in base y ; Driver code
using System ; class GFG { static void first_digit ( int x , int y ) { int length = ( int ) ( Math . Log ( x ) / Math . Log ( y ) + 1 ) ; int first_digit = ( int ) ( x / Math . Pow ( y , length - 1 ) ) ; Console . Write ( first_digit ) ; } public static void Main ( ) { int X = 55 , Y = 3 ; first_digit ( X , Y ) ; } }
Curzon Numbers | C # implementation of the approach ; Function to check if a number is a curzon number or not ; Find 2 ^ N + 1 ; Find 2 * N + 1 ; Check for divisibility ; Driver code
using System ; class GFG { static void checkIfCurzonNumber ( long N ) { double powerTerm , productTerm ; powerTerm = Math . Pow ( 2 , N ) + 1 ; productTerm = 2 * N + 1 ; if ( powerTerm % productTerm == 0 ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } static public void Main ( ) { long N = 5 ; checkIfCurzonNumber ( N ) ; N = 10 ; checkIfCurzonNumber ( N ) ; } }
Minimum count of numbers required ending with 7 to sum as a given number | C # implementation of the above approach ; Function to return the count of minimum numbers ending with 7 required such that the sum of these numbers is n ; hasharr [ i ] will store the minimum numbers ending with 7 so that it sums to number ending with digit i ; Its always possible to write numbers > 69 to write as numbers ending with 7 ; If the number is atleast equal to the sum of minimum numbers ending with 7 ; Driver code
using System ; class GFG { static int minCount ( int n ) { int [ ] hasharr = { 10 , 3 , 6 , 9 , 2 , 5 , 8 , 1 , 4 , 7 } ; if ( n > 69 ) return hasharr [ n % 10 ] ; else { if ( n >= hasharr [ n % 10 ] * 7 ) return ( hasharr [ n % 10 ] ) ; else return - 1 ; } } public static void Main ( String [ ] args ) { int n = 38 ; Console . WriteLine ( minCount ( n ) ) ; } }
Program to print modified Binary triangle pattern | C # implementation to print the modified binary triangle pattern ; Function to print the modified binary pattern ; Loop to traverse the rows ; Loop to traverse the numbers in each row ; Check if j is 1 or i In either case print 1 ; Else print 0 ; Change the cursor to next line after each row ; Driver Code ; Function call
using System ; class GFG { static void modifiedBinaryPattern ( int n ) { for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= i ; j ++ ) { if ( j == 1 j == i ) Console . Write ( 1 ) ; else Console . Write ( 0 ) ; } Console . WriteLine ( ) ; } } public static void Main ( ) { int n = 7 ; modifiedBinaryPattern ( n ) ; } }
Find the real and imaginary part of a Complex number | C # program to find the real and imaginary parts of a Complex Number ; Function to find real and imaginary parts of a complex number ; string length stored in variable l ; variable for the index of the separator ; Storing the index of ' + ' ; else storing the index of ' - ' ; Finding the real part of the complex number ; Finding the imaginary part of the complex number ; Driver code
using System ; class GFG { static void findRealAndImag ( String s ) { int l = s . Length ; int i ; if ( s . IndexOf ( ' + ' ) != - 1 ) { i = s . IndexOf ( ' + ' ) ; } else { i = s . IndexOf ( ' - ' ) ; } String real = s . Substring ( 0 , i ) ; String imaginary = s . Substring ( i + 1 , l - i - 2 ) ; Console . WriteLine ( " Real ▁ part : ▁ " + real ) ; Console . WriteLine ( " Imaginary ▁ part : ▁ " + imaginary ) ; } public static void Main ( String [ ] args ) { String s = "3 + 4i " ; findRealAndImag ( s ) ; } }
Distinct powers of a number N such that the sum is equal to K | C # implementation to find distinct powers of N that add up to K ; Function to return the highest power of N not exceeding K ; Loop to find the highest power less than K ; Initializing the PowerArray with all 0 's. ; Function to print the distinct powers of N that add upto K ; Getting the highest power of n before k ; To check if the power is being used twice or not ; Print - 1 if power is being used twice ; If the power is not visited , then mark the power as visited ; Decrementing the value of K ; Printing the powers of N that sum up to K ; Driver code
using System ; public class GFG { static int highestPower ( int n , int k ) { int i = 0 ; int a = ( int ) Math . Pow ( n , i ) ; while ( a <= k ) { i += 1 ; a = ( int ) Math . Pow ( n , i ) ; } return i - 1 ; } static int [ ] b = new int [ 50 ] ; static int PowerArray ( int n , int k ) { while ( k > 0 ) { int t = highestPower ( n , k ) ; if ( b [ t ] > 0 ) { Console . Write ( - 1 ) ; return 0 ; } else b [ t ] = 1 ; k -= ( int ) Math . Pow ( n , t ) ; } for ( int i = 0 ; i < 50 ; i ++ ) { if ( b [ i ] > 0 ) { Console . Write ( i + " , ▁ " ) ; } } return 0 ; } public static void Main ( String [ ] args ) { int N = 3 ; int K = 40 ; PowerArray ( N , K ) ; } }
Sum of elements in an array having composite frequency | C # program to find sum of elements in an array having composite frequency ; Function to create Sieve to check primes ; If composite [ p ] is not changed , then it is a prime ; Update all multiples of p , set them to composite ; Function to return the sum of elements in an array having composite frequency ; Map is used to store element frequencies ; To store sum ; Traverse the map using iterators ; Count the number of elements having composite frequencies ; Driver code ; Function call
using System ; using System . Collections . Generic ; class GFG { static readonly int N = 10005 ; static void SieveOfEratosthenes ( List < Boolean > composite ) { for ( int i = 0 ; i < N ; i ++ ) { composite . Insert ( i , false ) ; } for ( int p = 2 ; p * p < N ; p ++ ) { if ( ! composite [ p ] ) { for ( int i = p * 2 ; i < N ; i += p ) { composite . Insert ( i , true ) ; } } } } static int sumOfElements ( int [ ] arr , int n ) { List < Boolean > composite = new List < Boolean > ( ) ; for ( int i = 0 ; i < N ; i ++ ) composite . Add ( false ) ; SieveOfEratosthenes ( composite ) ; Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) if ( mp . ContainsKey ( arr [ i ] ) ) { mp [ arr [ i ] ] = mp [ arr [ i ] ] + 1 ; } else { mp . Add ( arr [ i ] , 1 ) ; } int sum = 0 ; foreach ( KeyValuePair < int , int > it in mp ) { if ( composite [ it . Value ] ) { sum += ( it . Key ) ; } } return sum ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 1 , 1 , 1 , 3 , 3 , 2 , 4 } ; int n = arr . Length ; Console . Write ( sumOfElements ( arr , n ) ) ; } }
Delete all odd frequency elements from an Array | C # program to removes all odd frequency elements from an Array ; Function that removes the elements which have odd frequencies in the array ; Create a map to store the frequency of each element ; Remove the elements which have odd frequencies ; If the element has odd frequency then skip ; Driver code ; Function call
using System ; using System . Collections . Generic ; class GFG { static void remove ( int [ ] arr , int n ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mp . ContainsKey ( arr [ i ] ) ) { mp [ arr [ i ] ] = mp [ arr [ i ] ] + 1 ; } else { mp . Add ( arr [ i ] , 1 ) ; } } for ( int i = 0 ; i < n ; i ++ ) { if ( ( mp . ContainsKey ( arr [ i ] ) && mp [ arr [ i ] ] % 2 == 1 ) ) continue ; Console . Write ( arr [ i ] + " , ▁ " ) ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 3 , 3 , 3 , 2 , 2 , 4 , 7 , 7 } ; int n = arr . Length ; remove ( arr , n ) ; } }
Maximize the first element of the array such that average remains constant | C # implementation of to maximize the first element of the array such that average of the array remains constant ; Maximum value of the first array element that can be attained ; Variable to store the sum ; Loop to find the sum of array ; Desired maximum value ; Driver code
using System ; class GFG { static void getmax ( int [ ] arr , int n , int x ) { int s = 0 ; for ( int i = 0 ; i < n ; i ++ ) { s = s + arr [ i ] ; } Console . WriteLine ( Math . Min ( s , x ) ) ; } static void Main ( ) { int [ ] arr = new int [ ] { 1 , 2 , 3 , 4 } ; int x = 5 ; int arr_size = arr . Length ; getmax ( arr , arr_size , x ) ; } }