"Remove all the Even Digit Sum Nodes from a Circular Singly Linked List | C # program to remove all the Even Digit Sum Nodes from a circular singly linked list ; Structure for a node ; Function to insert a node at the beginning of a Circular linked list ; Create a new node and make head as next of it . ; If linked list is not null then set the next of last node ; Find the node before head and update next of it . ; Point for the first node ; Function to delete the node from a Circular Linked list ; If node to be deleted is head node ; Traverse list till not found delete node ; Copy the address of the node ; Finally , free the memory occupied by del ; Function to find the digit sum for a number ; Function to delete all the Even Digit Sum Nodes from the singly circular linked list ; Traverse the list till the end ; If the node ' s ▁ data ▁ is ▁ Fibonacci , ▁ ▁ delete ▁ node ▁ ' ptr ' ; Point to the next node ; Function to print nodes in a given Circular linked list ; Driver code ; Initialize lists as empty ; Created linked list will be 9.11 .34 .6 .13 .21"
Solution in C#:

using System ; class GFG { class Node { public int data ; public Node next ; } ; static Node push ( Node head_ref , int data ) { Node ptr1 = new Node ( ) ; Node temp = head_ref ; ptr1 . data = data ; ptr1 . next = head_ref ; if ( head_ref != null ) { while ( temp . next != head_ref ) temp = temp . next ; temp . next = ptr1 ; } else ptr1 . next = ptr1 ; head_ref = ptr1 ; return head_ref ; } static void deleteNode ( Node head_ref , Node del ) { Node temp = head_ref ; if ( head_ref == del ) head_ref = del . next ; while ( temp . next != del ) { temp = temp . next ; } temp . next = del . next ; del = null ; return ; } static int digitSum ( int num ) { int sum = 0 ; while ( num > 0 ) { sum += ( num % 10 ) ; num /= 10 ; } return sum ; } static void deleteEvenDigitSumNodes ( Node head ) { Node ptr = head ; Node next ; do { if ( ! ( digitSum ( ptr . data ) % 2 == 1 ) ) deleteNode ( head , ptr ) ; next = ptr . next ; ptr = next ; } while ( ptr != head ) ; } static void printList ( Node head ) { Node temp = head ; if ( head != null ) { do { Console . Write ( " { 0 } ▁ " , temp . data ) ; temp = temp . next ; } while ( temp != head ) ; } } public static void Main ( String [ ] args ) { Node head = null ; head = push ( head , 21 ) ; head = push ( head , 13 ) ; head = push ( head , 6 ) ; head = push ( head , 34 ) ; head = push ( head , 11 ) ; head = push ( head , 9 ) ; deleteEvenDigitSumNodes ( head ) ; printList ( head ) ; } }


"Remove all the prime numbers from the given array | C # implementation of the approach ; Function for Sieve of Eratosthenes ; Function to print the elements of the array ; Function to remove all the prime numbers ; Generate primes ; Traverse the array ; If the current element is prime ; Shift all the elements on the right of it to the left ; Decrease the loop counter by 1 to check the shifted element ; Decrease the length ; Print the updated array ; Driver code"
Solution in C#:

using System ; class GFG { static int sz = ( int ) 1e5 ; static bool [ ] isPrime = new bool [ sz + 1 ] ; static void sieve ( ) { for ( int i = 0 ; i < sz + 1 ; i ++ ) isPrime [ i ] = true ; isPrime [ 0 ] = isPrime [ 1 ] = false ; for ( int i = 2 ; i * i <= sz ; i ++ ) { if ( isPrime [ i ] ) { for ( int j = i * i ; j < sz ; j += i ) { isPrime [ j ] = false ; } } } } static void printArray ( int [ ] arr , int len ) { for ( int i = 0 ; i < len ; i ++ ) { Console . Write ( arr [ i ] + " ▁ " ) ; } } static void removePrimes ( int [ ] arr , int len ) { sieve ( ) ; for ( int i = 0 ; i < len ; i ++ ) { if ( isPrime [ arr [ i ] ] ) { for ( int j = i ; j < len - 1 ; j ++ ) { arr [ j ] = arr [ j + 1 ] ; } i -- ; len -- ; } } printArray ( arr , len ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 4 , 6 , 5 , 3 , 8 , 7 , 10 , 11 , 14 , 15 } ; int len = arr . Length ; removePrimes ( arr , len ) ; } }


"Remove all zero | C # program for the above approach ; Function to remove the rows or columns from the matrix which contains all 0 s elements ; Stores count of rows ; col [ i ] : Stores count of 0 s in current column ; row [ i ] : Stores count of 0 s in current row ; Traverse the matrix ; Stores count of 0 s in current row ; Update col [ j ] ; Update count ; Update row [ i ] ; Traverse the matrix ; If all elements of current row is 0 ; If all elements of current column is 0 ; Driver Code ; Function Call"
Solution in C#:

using System ; class GFG { static void removeZeroRowCol ( int [ , ] arr ) { int n = arr . GetLength ( 0 ) ; int [ ] col = new int [ n + 1 ] ; int [ ] row = new int [ n + 1 ] ; for ( int i = 0 ; i < n ; ++ i ) { int count = 0 ; for ( int j = 0 ; j < n ; ++ j ) { if ( arr [ i , j ] == 1 ) col [ j ] += 1 ; else col [ j ] += 0 ; if ( arr [ i , j ] == 1 ) count += 1 ; else count += 0 ; } row [ i ] = count ; } for ( int i = 0 ; i < n ; ++ i ) { if ( row [ i ] == 0 ) { continue ; } for ( int j = 0 ; j < n ; ++ j ) { if ( col [ j ] != 0 ) Console . Write ( arr [ i , j ] ) ; } Console . WriteLine ( ) ; } } public static void Main ( String [ ] args ) { int [ , ] arr = { { 1 , 1 , 0 , 1 } , { 0 , 0 , 0 , 0 } , { 1 , 1 , 0 , 1 } , { 0 , 1 , 0 , 1 } } ; removeZeroRowCol ( arr ) ; } }


"Remove an occurrence of most frequent array element exactly K times | C # program for the above approach ; Function to print the most frequent array element exactly K times ; Stores frequency array element ; Count frequency of array element ; Maximum array element ; Traverse the Map ; Find the element with maximum frequency ; If the frequency is maximum , store that number in element ; Print element as it contains the element having highest frequency ; Decrease the frequency of the maximum array element ; Reduce the number of operations ; Driver Code ; Given array ; Size of the array ; Given K"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { static void maxFreqElements ( int [ ] arr , int N , int K ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( mp . ContainsKey ( arr [ i ] ) ) { mp [ arr [ i ] ] ++ ; } else { mp [ arr [ i ] ] = 1 ; } } while ( K > 0 ) { int max = 0 ; int element = 0 ; foreach ( KeyValuePair < int , int > i in mp ) { if ( i . Value > max ) { max = i . Value ; element = i . Key ; } } Console . Write ( element + " ▁ " ) ; if ( mp . ContainsKey ( element ) ) { mp [ element ] -- ; } else { mp [ element ] = - 1 ; } K -- ; } } static void Main ( ) { int [ ] arr = { 1 , 3 , 2 , 1 , 4 , 1 } ; int N = arr . Length ; int K = 2 ; maxFreqElements ( arr , N , K ) ; } }


"Remove array elements to reduce frequency of each array element to at most K | C # program to implement the above approach ; Function to remove array elements such that frequency of each distinct array element is at most K ; Base Case ; Stores index of array element by removing the array element such that the frequency of array elements is at most K ; Traverse the array ; If j < k or arr [ i ] > arr [ j - k ] ; Update arr [ j ] ; Remove array elements ; Function to print the array ; Traverse the array ; Utility Function to remove array elements such that frequency of each distinct array element is at most K ; Print updated array ; Driver code"
Solution in C#:

using System ; using System . Linq ; class GFG { static int [ ] RemoveElemArr ( int [ ] arr , int n , int k ) { if ( n == 0 n == 1 ) return arr ; int j = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( j < k arr [ i ] > arr [ j - k ] ) { arr [ j ++ ] = arr [ i ] ; } } while ( arr . Length > j ) { arr = arr . Take ( arr . Length - 1 ) . ToArray ( ) ; } return arr ; } static void printArray ( int [ ] arr ) { for ( int i = 0 ; i < arr . Length ; i ++ ) { Console . Write ( arr [ i ] + " ▁ " ) ; } } static void UtilRemov ( int [ ] arr , int n , int k ) { arr = RemoveElemArr ( arr , n , k ) ; printArray ( arr ) ; } public static void Main ( ) { int [ ] arr = { 1 , 2 , 2 , 3 , 4 , 4 , 4 , 5 , 5 } ; int k = 2 ; int n = arr . Length ; UtilRemov ( arr , n , k ) ; } }


"Remove array end element to maximize the sum of product | C # program to find maximum score we can get by removing elements from either end . ; If only one element left . ; If already calculated , return the value . ; Computing Maximum value when element at index i and index j is to be choosed . ; Driven code"
Solution in C#:

using System ; class GFG { static int MAX = 50 ; static int solve ( int [ , ] dp , int [ ] a , int low , int high , int turn ) { if ( low == high ) return a [ low ] * turn ; if ( dp [ low , high ] != 0 ) return dp [ low , high ] ; dp [ low , high ] = Math . Max ( a [ low ] * turn + solve ( dp , a , low + 1 , high , turn + 1 ) , a [ high ] * turn + solve ( dp , a , low , high - 1 , turn + 1 ) ) ; return dp [ low , high ] ; } static void Main ( ) { int [ ] arr = new int [ ] { 1 , 3 , 1 , 5 , 2 } ; int n = arr . Length ; int [ , ] dp = new int [ MAX , MAX ] ; for ( int i = 0 ; i < MAX ; i ++ ) for ( int j = 0 ; j < MAX ; j ++ ) dp [ i , j ] = 0 ; Console . Write ( solve ( dp , arr , 0 , n - 1 , 1 ) ) ; } }


"Remove brackets from an algebraic string containing + and | C # program to simplify algebraic string ; Function to simplify the string ; resultant string of max length equal to length of input string ; create empty stack ; If top is 1 , flip the operator ; If top is 0 , append the same operator ; x is opposite to the top of stack ; push value equal to top of the stack ; If closing parentheses pop the stack once ; copy the character to the result ; Driver code"
Solution in C#:

using System ; using System . Collections . Generic ; class GfG { static String simplify ( String str ) { int len = str . Length ; char [ ] res = new char [ len ] ; int index = 0 , i = 0 ; Stack < int > s = new Stack < int > ( ) ; s . Push ( 0 ) ; while ( i < len ) { if ( str [ i ] == ' + ' ) { if ( s . Peek ( ) == 1 ) res [ index ++ ] = ' - ' ; if ( s . Peek ( ) == 0 ) res [ index ++ ] = ' + ' ; } else if ( str [ i ] == ' - ' ) { if ( s . Peek ( ) == 1 ) res [ index ++ ] = ' + ' ; else if ( s . Peek ( ) == 0 ) res [ index ++ ] = ' - ' ; } else if ( str [ i ] == ' ( ' && i > 0 ) { if ( str [ i - 1 ] == ' - ' ) { int x = ( s . Peek ( ) == 1 ) ? 0 : 1 ; s . Push ( x ) ; } else if ( str [ i - 1 ] == ' + ' ) s . Push ( s . Peek ( ) ) ; } else if ( str [ i ] == ' ) ' ) s . Pop ( ) ; else res [ index ++ ] = str [ i ] ; i ++ ; } return new String ( res ) ; } public static void Main ( String [ ] args ) { String s1 = " a - ( b + c ) " ; String s2 = " a - ( b - c - ( d + e ) ) - f " ; Console . WriteLine ( simplify ( s1 ) ) ; Console . WriteLine ( simplify ( s2 ) ) ; } }


"Remove characters from a numeric string such that string becomes divisible by 8 | C # program to remove digits from a numeric string such that the number becomes divisible by 8 ; Function that return true if sub is a sub - sequence in s ; Function to return a multiple of 8 formed after removing 0 or more characters from the given string ; Iterate over all multiples of 8 ; If current multiple exists as a subsequence in the given string ; Driver Code"
Solution in C#:

using System ; class GFG { static bool checkSub ( string sub , string s ) { int j = 0 ; for ( int i = 0 ; i < s . Length ; i ++ ) if ( sub [ j ] == s [ i ] ) j ++ ; return j == sub . Length ; } static int getMultiple ( string s ) { for ( int i = 0 ; i < 1e3 ; i += 8 ) { if ( checkSub ( i . ToString ( ) , s ) ) return i ; } return - 1 ; } static void Main ( ) { string s = "3454" ; Console . WriteLine ( getMultiple ( s ) ) ; } }


"Remove characters from given string whose frequencies are a Prime Number | C # program for the above approach ; Function to perform the seive of eratosthenes algorithm ; Initialize all entries in prime [ ] as true ; Initialize 0 and 1 as non prime ; Traversing the prime array ; If i is prime ; All multiples of i must be marked false as they are non prime ; Function to remove characters which have prime frequency in the String ; Length of the String ; Create a bool array prime ; Sieve of Eratosthenes ; Stores the frequency of character ; Storing the frequencies ; New String that will be formed ; Removing the characters which have prime frequencies ; If the character has prime frequency then skip ; Else concatenate the character to the new String ; Print the modified String ; Driver Code ; Function Call"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { static void SieveOfEratosthenes ( bool [ ] prime , int n ) { for ( int i = 0 ; i <= n ; i ++ ) { prime [ i ] = true ; } prime [ 0 ] = prime [ 1 ] = false ; for ( int i = 2 ; i * i <= n ; i ++ ) { if ( prime [ i ] == true ) { for ( int j = 2 ; i * j <= n ; j ++ ) { prime [ i * j ] = false ; } } } } static void removePrimeFrequencies ( char [ ] s ) { int n = s . Length ; bool [ ] prime = new bool [ n + 1 ] ; SieveOfEratosthenes ( prime , n ) ; Dictionary < char , int > m = new Dictionary < char , int > ( ) ; for ( int i = 0 ; i < s . Length ; i ++ ) { if ( m . ContainsKey ( s [ i ] ) ) { m [ s [ i ] ] ++ ; } else { m . Add ( s [ i ] , 1 ) ; } } String new_String = " " ; for ( int i = 0 ; i < s . Length ; i ++ ) { if ( prime [ m [ s [ i ] ] ] ) continue ; new_String += s [ i ] ; } Console . Write ( new_String ) ; } public static void Main ( String [ ] args ) { String str = " geeksforgeeks " ; removePrimeFrequencies ( str . ToCharArray ( ) ) ; } }


"Remove characters from string that appears strictly less than K times | C # program to reduce the string by removing the characters which appears less than k times ; Function to reduce the string by removing the characters which appears less than k times ; Hash table initialised to 0 ; Increment the frequency of the character ; create a new empty string ; Append the characters which appears more than equal to k times ; Driver Code"
Solution in C#:

using System ; class GFG { readonly static int MAX_CHAR = 26 ; static String removeChars ( String str , int k ) { int [ ] hash = new int [ MAX_CHAR ] ; int n = str . Length ; for ( int i = 0 ; i < n ; ++ i ) { hash [ str [ i ] - ' a ' ] ++ ; } String res = " " ; for ( int i = 0 ; i < n ; ++ i ) { if ( hash [ str [ i ] - ' a ' ] >= k ) { res += str [ i ] ; } } return res ; } static public void Main ( ) { String str = " geeksforgeeks " ; int k = 2 ; Console . WriteLine ( removeChars ( str , k ) ) ; } }


"Remove consecutive alphabets which are in same case | C # program to remove the consecutive characters from a string that are in same case ; Function to return the modified string ; Traverse through the remaining characters in the string ; If the current and the previous characters are not in the same case then take the character ; Driver code"
Solution in C#:

using System ; class GFG { static string removeChars ( string s ) { string modifiedStr = " " ; modifiedStr += s [ 0 ] ; for ( int i = 1 ; i < s . Length ; i ++ ) { if ( char . IsUpper ( s [ i ] ) && char . IsLower ( s [ i - 1 ] ) || char . IsLower ( s [ i ] ) && char . IsUpper ( s [ i - 1 ] ) ) modifiedStr += s [ i ] ; } return modifiedStr ; } public static void Main ( ) { string s = " GeeksForGeeks " ; Console . Write ( removeChars ( s ) ) ; } }


"Remove consecutive vowels from string | C # program for printing sentence without repetitive vowels ; function which returns True or False for occurrence of a vowel ; this compares vowel with character ' c ' ; function to print resultant string ; print 1 st character ; loop to check for each character ; comparison of consecutive characters ; Driver Code"
Solution in C#:

using System ; class GFG { static bool is_vow ( char c ) { return ( c == ' a ' ) || ( c == ' e ' ) || ( c == ' i ' ) || ( c == ' o ' ) || ( c == ' u ' ) ; } static void removeVowels ( string str ) { Console . Write ( str [ 0 ] ) ; for ( int i = 1 ; i < str . Length ; i ++ ) if ( ( ! is_vow ( str [ i - 1 ] ) ) || ( ! is_vow ( str [ i ] ) ) ) Console . Write ( str [ i ] ) ; } static void Main ( ) { string str = " geeks ▁ for ▁ geeks " ; removeVowels ( str ) ; } }


"Remove duplicates from a given string | C # program to create a unique string ; Function to make the string unique ; loop to traverse the string and check for repeating chars using IndexOf ( ) method in Java ; character at i 'th index of s ; if c is present in str , it returns the index of c , else it returns - 1 ; adding c to str if - 1 is returned ; Driver code ; Input string with repeating chars"
Solution in C#:

using System ; public class IndexOf { public static String unique ( String s ) { String str = " " ; int len = s . Length ; for ( int i = 0 ; i < len ; i ++ ) { char c = s [ i ] ; if ( str . IndexOf ( c ) < 0 ) { str += c ; } } return str ; } public static void Main ( String [ ] args ) { String s = " geeksforgeeks " ; Console . WriteLine ( unique ( s ) ) ; } }


"Remove duplicates from a given string | C # program to remove duplicate character from character array and print in sorted order ; Create a set using String characters excluding ' \0' ; Print content of the set ; Driver code"
Solution in C#:

using System ; using System . Collections . Generic ; public class GFG { static char [ ] removeDuplicate ( char [ ] str , int n ) { HashSet < char > s = new HashSet < char > ( n - 1 ) ; foreach ( char x in str ) s . Add ( x ) ; char [ ] st = new char [ s . Count ] ; int i = 0 ; foreach ( char x in s ) st [ i ++ ] = x ; return st ; } public static void Main ( String [ ] args ) { char [ ] str = " geeksforgeeks " . ToCharArray ( ) ; int n = str . Length ; Console . Write ( removeDuplicate ( str , n ) ) ; } }


"Remove duplicates from a given string | C # program to remove duplicate character from character array and print in sorted order ; Used as index in the modified string ; Traverse through all characters ; Check if str [ i ] is present before it ; If not present , then add it to result . ; Driver code"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { static String removeDuplicate ( char [ ] str , int n ) { int index = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int j ; for ( j = 0 ; j < i ; j ++ ) { if ( str [ i ] == str [ j ] ) { break ; } } if ( j == i ) { str [ index ++ ] = str [ i ] ; } } char [ ] ans = new char [ index ] ; Array . Copy ( str , ans , index ) ; return String . Join ( " " , ans ) ; } public static void Main ( String [ ] args ) { char [ ] str = " geeksforgeeks " . ToCharArray ( ) ; int n = str . Length ; Console . WriteLine ( removeDuplicate ( str , n ) ) ; } }


"Remove duplicates from a sorted linked list | C # program for the above approach ; Function to insert a node at the beginging of the linked * list ; allocate node ; put in the data ; link the old list off the new node ; move the head to point to the new node ; Function to print nodes in a given linked list ; Function to remove duplicates ; Driver Code ; Created linked list will be 11 -> 11 -> 11 -> 13 -> 13 -> 20"
Solution in C#:

 using System ; using System . Collections . Generic ; public class Node { public int data ; public Node next ; public Node ( ) { data = 0 ; next = null ; } } public class GFG { static Node push ( Node head_ref , int new_data ) { Node new_node = new Node ( ) ; new_node . data = new_data ; new_node . next = ( head_ref ) ; head_ref = new_node ; return head_ref ; } static void printList ( Node node ) { while ( node != null ) { Console . Write ( node . data + " ▁ " ) ; node = node . next ; } } static void removeDuplicates ( Node head ) { Dictionary < int , bool > track = new Dictionary < int , bool > ( ) ; Node temp = head ; while ( temp != null ) { if ( ! track . ContainsKey ( temp . data ) ) { Console . Write ( temp . data + " ▁ " ) ; track . Add ( temp . data , true ) ; } temp = temp . next ; } } static public void Main ( ) { Node head = null ; head = push ( head , 20 ) ; head = push ( head , 13 ) ; head = push ( head , 13 ) ; head = push ( head , 11 ) ; head = push ( head , 11 ) ; head = push ( head , 11 ) ; Console . Write ( " Linked ▁ list ▁ before ▁ duplicate ▁ removal ▁ " ) ; printList ( head ) ; Console . Write ( "
 Linked ▁ list ▁ after ▁ duplicate ▁ removal ▁ " ) ; removeDuplicates ( head ) ; } }


"Remove duplicates from a string in O ( 1 ) extra space | C # implementation of above approach ; Function to remove duplicates ; keeps track of visited characters ; gets character value ; keeps track of length of resultant String ; check if Xth bit of counter is unset ; mark current character as visited ; Driver code"
Solution in C#:

using System ; class GFG { static string removeDuplicatesFromString ( string string1 ) { int counter = 0 ; char [ ] str = string1 . ToCharArray ( ) ; int i = 0 ; int size = str . Length ; int x ; int length = 0 ; while ( i < size ) { x = str [ i ] - 97 ; if ( ( counter & ( 1 << x ) ) == 0 ) { str [ length ] = ( char ) ( ' a ' + x ) ; counter = counter | ( 1 << x ) ; length ++ ; } i ++ ; } return ( new string ( str ) ) . Substring ( 0 , length ) ; } static void Main ( ) { string str = " geeksforgeeks " ; Console . WriteLine ( removeDuplicatesFromString ( str ) ) ; } }


"Remove duplicates from a string in O ( 1 ) extra space | C # implementation of above approach ; Method to remove duplicates ; table to keep track of visited characters ; to keep track of end index of resultant string ; Driver code"
Solution in C#:

using System ; class GFG { static char [ ] removeDuplicatesFromString ( String str ) { int [ ] table = new int [ 256 ] ; char [ ] chars = str . ToCharArray ( ) ; int endIndex = 0 ; for ( int i = 0 ; i < chars . Length ; i ++ ) { if ( table [ chars [ i ] ] == 0 ) { table [ chars [ i ] ] = - 1 ; chars [ endIndex ++ ] = chars [ i ] ; } } char [ ] newStr = new char [ endIndex ] ; Array . Copy ( chars , newStr , endIndex ) ; return newStr ; } public static void Main ( String [ ] args ) { String str = " geeksforgeeks " ; Console . WriteLine ( removeDuplicatesFromString ( str ) ) ; } }


"Remove duplicates from an unsorted doubly linked list | C # implementation to remove duplicates from an unsorted doubly linked list ; a node of the doubly linked list ; Function to delete a node in a Doubly Linked List . head_ref - . pointer to head node pointer . del - . pointer to node to be deleted . ; base case ; If node to be deleted is head node ; Change next only if node to be deleted is NOT the last node ; Change prev only if node to be deleted is NOT the first node ; function to remove duplicates from an unsorted doubly linked list ; if DLL is empty or if it contains only a single node ; pick elements one by one ; Compare the picked element with the rest of the elements ; if duplicate , then delete it ; store pointer to the node next to ' ptr2' ; delete node pointed to by ' ptr2' ; update ' ptr2' ; else simply move to the next node ; Function to insert a node at the beginning of the Doubly Linked List ; allocate node ; put in the data ; since we are adding at the beginning , prev is always null ; link the old list off the new node ; change prev of head node to new node ; move the head to point to the new node ; Function to print nodes in a given doubly linked list ; if list is empty ; Driver Code ; Create the doubly linked list : 8 < -> 4 < -> 4 < -> 6 < -> 4 < -> 8 < -> 4 < -> 10 < -> 12 < -> 12 ; remove duplicate nodes"
Solution in C#:

 using System ; class GFG { public class Node { public int data ; public Node next ; public Node prev ; } static Node deleteNode ( Node head_ref , Node del ) { if ( head_ref == null del == null ) return head_ref ; if ( head_ref == del ) head_ref = del . next ; if ( del . next != null ) del . next . prev = del . prev ; if ( del . prev != null ) del . prev . next = del . next ; return head_ref ; } static Node removeDuplicates ( Node head_ref ) { if ( ( head_ref ) == null || ( head_ref ) . next == null ) return head_ref ; ; Node ptr1 , ptr2 ; for ( ptr1 = head_ref ; ptr1 != null ; ptr1 = ptr1 . next ) { ptr2 = ptr1 . next ; while ( ptr2 != null ) { if ( ptr1 . data == ptr2 . data ) { Node next = ptr2 . next ; head_ref = deleteNode ( head_ref , ptr2 ) ; ptr2 = next ; } else ptr2 = ptr2 . next ; } } return head_ref ; } static Node push ( Node head_ref , int new_data ) { Node new_node = new Node ( ) ; new_node . data = new_data ; new_node . prev = null ; new_node . next = ( head_ref ) ; if ( ( head_ref ) != null ) ( head_ref ) . prev = new_node ; ( head_ref ) = new_node ; return head_ref ; } static void printList ( Node head ) { if ( head == null ) Console . Write ( " Doubly ▁ Linked ▁ list ▁ empty " ) ; while ( head != null ) { Console . Write ( head . data + " ▁ " ) ; head = head . next ; } } public static void Main ( String [ ] args ) { Node head = null ; head = push ( head , 12 ) ; head = push ( head , 12 ) ; head = push ( head , 10 ) ; head = push ( head , 4 ) ; head = push ( head , 8 ) ; head = push ( head , 4 ) ; head = push ( head , 6 ) ; head = push ( head , 4 ) ; head = push ( head , 4 ) ; head = push ( head , 8 ) ; Console . Write ( " Original ▁ Doubly ▁ linked ▁ list :
 " ) ; printList ( head ) ; head = removeDuplicates ( head ) ; Console . Write ( "
 Doubly ▁ linked ▁ list ▁ after " + " ▁ removing ▁ duplicates :
 " ) ; printList ( head ) ; } }


"Remove duplicates from an unsorted doubly linked list | C # mplementation to remove duplicates from an unsorted doubly linked list ; a node of the doubly linked list ; Function to delete a node in a Doubly Linked List . head_ref -- > pointer to head node pointer . del -- > pointer to node to be deleted . ; base case ; If node to be deleted is head node ; Change next only if node to be deleted is NOT the last node ; Change prev only if node to be deleted is NOT the first node ; function to remove duplicates from an unsorted doubly linked list ; if doubly linked list is empty ; unordered_set ' us ' implemented as hash table ; traverse up to the end of the list ; if current data is seen before ; store pointer to the node next to ' current ' node ; delete the node pointed to by ' current ' ; update ' current ' ; insert the current data in ' us ' ; move to the next node ; Function to insert a node at the beginning of the Doubly Linked List ; allocate node ; put in the data ; since we are adding at the beginning , prev is always null ; link the old list off the new node ; change prev of head node to new node ; move the head to point to the new node ; Function to print nodes in a given doubly linked list ; if list is empty ; Driver Code ; Create the doubly linked list : 8 < -> 4 < -> 4 < -> 6 < -> 4 < -> 8 < -> 4 < -> 10 < -> 12 < -> 12 ; remove duplicate nodes"
Solution in C#:

 using System ; using System . Collections . Generic ; class GFG { public class Node { public int data ; public Node next ; public Node prev ; } ; static Node deleteNode ( Node head_ref , Node del ) { if ( head_ref == null del == null ) return null ; if ( head_ref == del ) head_ref = del . next ; if ( del . next != null ) del . next . prev = del . prev ; if ( del . prev != null ) del . prev . next = del . next ; return head_ref ; } static Node removeDuplicates ( Node head_ref ) { if ( ( head_ref ) == null ) return null ; HashSet < int > us = new HashSet < int > ( ) ; Node current = head_ref , next ; while ( current != null ) { if ( us . Contains ( current . data ) ) { next = current . next ; head_ref = deleteNode ( head_ref , current ) ; current = next ; } else { us . Add ( current . data ) ; current = current . next ; } } return head_ref ; } static Node push ( Node head_ref , int new_data ) { Node new_node = new Node ( ) ; new_node . data = new_data ; new_node . prev = null ; new_node . next = ( head_ref ) ; if ( ( head_ref ) != null ) ( head_ref ) . prev = new_node ; ( head_ref ) = new_node ; return head_ref ; } static void printList ( Node head ) { if ( head == null ) Console . Write ( " Doubly ▁ Linked ▁ list ▁ empty " ) ; while ( head != null ) { Console . Write ( head . data + " ▁ " ) ; head = head . next ; } } public static void Main ( String [ ] args ) { Node head = null ; head = push ( head , 12 ) ; head = push ( head , 12 ) ; head = push ( head , 10 ) ; head = push ( head , 4 ) ; head = push ( head , 8 ) ; head = push ( head , 4 ) ; head = push ( head , 6 ) ; head = push ( head , 4 ) ; head = push ( head , 4 ) ; head = push ( head , 8 ) ; Console . WriteLine ( " Original ▁ Doubly ▁ linked ▁ list : " ) ; printList ( head ) ; head = removeDuplicates ( head ) ; Console . WriteLine ( "
 Doubly ▁ linked ▁ list ▁ after ▁ " + " removing ▁ duplicates : " ) ; printList ( head ) ; } }


"Remove duplicates from string keeping the order according to last occurrences | C # program to remove duplicate character from character array and print in sorted order ; Used as index in the modified String ; Create an empty hash table ; Traverse through all characters from right to left ; If current character is not in ; Reverse the result String ; Driver code"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { static String removeDuplicates ( String str ) { int n = str . Length ; HashSet < char > s = new HashSet < char > ( ) ; String res = " " ; for ( int i = n - 1 ; i >= 0 ; i -- ) { if ( ! s . Contains ( str [ i ] ) ) { res = res + str [ i ] ; s . Add ( str [ i ] ) ; } } res = reverse ( res ) ; return res ; } static String reverse ( String input ) { char [ ] a = input . ToCharArray ( ) ; int l , r = a . Length - 1 ; for ( l = 0 ; l < r ; l ++ , r -- ) { char temp = a [ l ] ; a [ l ] = a [ r ] ; a [ r ] = temp ; } return String . Join ( " " , a ) ; } public static void Main ( String [ ] args ) { String str = " geeksforgeeks " ; Console . Write ( removeDuplicates ( str ) ) ; } }


"Remove duplicates from string keeping the order according to last occurrences | C # program to remove duplicate character from character array and print in sorted order ; Used as index in the modified String ; Traverse through all characters ; Check if str [ i ] is present before it ; If not present , then add it to result . ; Driver code"
Solution in C#:

using System ; class GFG { static String removeDuplicates ( String str ) { int n = str . Length ; String res = " " ; for ( int i = 0 ; i < n ; i ++ ) { int j ; for ( j = i + 1 ; j < n ; j ++ ) if ( str [ i ] == str [ j ] ) break ; if ( j == n ) res = res + str [ i ] ; } return res ; } public static void Main ( String [ ] args ) { String str = " geeksforgeeks " ; Console . Write ( removeDuplicates ( str ) ) ; } }


"Remove elements from the array which appear more than k times | C # program to remove the elements which appear more than k times from the array . ; Hash map which will store the frequency of the elements of the array . ; Incrementing the frequency of the element by 1. ; Print the element which appear less than or equal to k times . ; Driver code"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { static void RemoveElements ( int [ ] arr , int n , int k ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { if ( mp . ContainsKey ( arr [ i ] ) ) mp [ arr [ i ] ] ++ ; else mp [ arr [ i ] ] = 1 ; } for ( int i = 0 ; i < n ; ++ i ) { if ( mp . ContainsKey ( arr [ i ] ) && mp [ arr [ i ] ] <= k ) { Console . Write ( arr [ i ] + " ▁ " ) ; } } } static public void Main ( ) { int [ ] arr = { 1 , 2 , 2 , 3 , 2 , 3 , 4 } ; int n = arr . Length ; int k = 2 ; RemoveElements ( arr , n , k ) ; } }


"Remove elements that appear strictly less than k times | C # program to remove the elements which appear strictly less than k times from the array . ; Hash map which will store the frequency of the elements of the array . ; Incrementing the frequency of the element by 1. ; Print the element which appear more than or equal to k times . ; Driver code"
Solution in C#:

using System ; using System . Collections . Generic ; class geeks { public static void removeElements ( int [ ] arr , int n , int k ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; ++ i ) { if ( ! mp . ContainsKey ( arr [ i ] ) ) mp . Add ( arr [ i ] , 1 ) ; else { int x = mp [ arr [ i ] ] ; mp [ arr [ i ] ] = mp [ arr [ i ] ] + ++ x ; } } for ( int i = 0 ; i < n ; ++ i ) { if ( mp [ arr [ i ] ] >= k ) Console . Write ( arr [ i ] + " ▁ " ) ; } } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 2 , 3 , 2 , 3 , 4 } ; int n = arr . Length ; int k = 2 ; removeElements ( arr , n , k ) ; } }


"Remove elements to make array sorted | C # implementation of the approach ; Function to sort the array by removing misplaced elements ; brr [ ] is used to store the sorted array elements ; Print the sorted array ; Driver code"
Solution in C#:

using System ; class GFG { static void removeElements ( int [ ] arr , int n ) { int [ ] brr = new int [ n ] ; int l = 1 ; brr [ 0 ] = arr [ 0 ] ; for ( int i = 1 ; i < n ; i ++ ) { if ( brr [ l - 1 ] <= arr [ i ] ) { brr [ l ] = arr [ i ] ; l ++ ; } } for ( int i = 0 ; i < l ; i ++ ) Console . Write ( brr [ i ] + " ▁ " ) ; } static public void Main ( ) { int [ ] arr = { 10 , 12 , 9 , 10 , 2 , 13 , 14 } ; int n = arr . Length ; removeElements ( arr , n ) ; } }


"Remove elements to make array sorted | C # implementation of the approach ; Function to sort the array by removing misplaced elements ; l stores the index ; Print the sorted array ; Driver code"
Solution in C#:

using System ; class GFG { public static void removeElements ( int [ ] arr , int n ) { int l = 1 ; for ( int i = 1 ; i < n ; i ++ ) { if ( arr [ l - 1 ] <= arr [ i ] ) { arr [ l ] = arr [ i ] ; l ++ ; } } for ( int i = 0 ; i < l ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; } public static void Main ( string [ ] args ) { int [ ] arr = { 10 , 12 , 9 , 10 , 2 , 13 , 14 } ; int n = arr . Length ; removeElements ( arr , n ) ; } }


"Remove every k | C # program to delete every k - th Node of a singly linked list . ; Linked list Node ; To remove complete list ( Needed forcase when k is 1 ) ; Deletes every k - th node and returns head of modified list . ; If linked list is empty ; Initialize ptr and prev before starting traversal . ; Traverse list and delete every k - th node ; increment Node count ; check if count is equal to k if yes , then delete current Node ; put the next of current Node in the next of previous Node ; set count = 0 to reach further k - th Node ; update prev if count is not 0 ; Function to print linked list ; Utility function to create a new node . ; Driver Code ; Start with the empty list"
Solution in C#:

using System ; class GFG { public class Node { public int data ; public Node next ; } static Node freeList ( Node node ) { while ( node != null ) { Node next = node . next ; node = next ; } return node ; } static Node deleteKthNode ( Node head , int k ) { if ( head == null ) return null ; if ( k == 1 ) { head = freeList ( head ) ; return null ; } Node ptr = head , prev = null ; int count = 0 ; while ( ptr != null ) { count ++ ; if ( k == count ) { prev . next = ptr . next ; count = 0 ; } if ( count != 0 ) prev = ptr ; ptr = prev . next ; } return head ; } static void displayList ( Node head ) { Node temp = head ; while ( temp != null ) { Console . Write ( temp . data + " ▁ " ) ; temp = temp . next ; } } static Node newNode ( int x ) { Node temp = new Node ( ) ; temp . data = x ; temp . next = null ; return temp ; } public static void Main ( String [ ] args ) { Node head = newNode ( 1 ) ; head . next = newNode ( 2 ) ; head . next . next = newNode ( 3 ) ; head . next . next . next = newNode ( 4 ) ; head . next . next . next . next = newNode ( 5 ) ; head . next . next . next . next . next = newNode ( 6 ) ; head . next . next . next . next . next . next = newNode ( 7 ) ; head . next . next . next . next . next . next . next = newNode ( 8 ) ; int k = 3 ; head = deleteKthNode ( head , k ) ; displayList ( head ) ; } }


"Remove exactly one element from the array such that max | C # implementation of the above approach ; function to calculate max - min ; Driver code"
Solution in C#:

using System ; class GFG { static int max_min ( int [ ] a , int n ) { Array . Sort ( a ) ; return Math . Min ( a [ n - 2 ] - a [ 0 ] , a [ n - 1 ] - a [ 1 ] ) ; } public static void Main ( ) { int [ ] a = { 1 , 3 , 3 , 7 } ; int n = a . Length ; Console . WriteLine ( max_min ( a , n ) ) ; } }


"Remove exactly one element from the array such that max | C # implementation of the above approach ; function to calculate max - min ; There should be at - least two elements ; To store first and second minimums ; To store first and second maximums ; Driver code"
Solution in C#:

using System ; class GFG { static int max_min ( int [ ] a , int n ) { if ( n <= 1 ) return Int32 . MaxValue ; int f_min = a [ 0 ] , s_min = Int32 . MaxValue ; int f_max = a [ 0 ] , s_max = Int32 . MinValue ; for ( int i = 1 ; i < n ; i ++ ) { if ( a [ i ] <= f_min ) { s_min = f_min ; f_min = a [ i ] ; } else if ( a [ i ] < s_min ) { s_min = a [ i ] ; } if ( a [ i ] >= f_max ) { s_max = f_max ; f_max = a [ i ] ; } else if ( a [ i ] > s_max ) { s_max = a [ i ] ; } } return Math . Min ( ( f_max - s_min ) , ( s_max - f_min ) ) ; } public static void Main ( ) { int [ ] a = { 1 , 3 , 3 , 7 } ; int n = a . Length ; Console . WriteLine ( max_min ( a , n ) ) ; } }


"Remove first adjacent pairs of similar characters until possible | C # implementation of the above approach ; Function to remove adjacent duplicates ; Iterate for every character in the string ; If ans string is empty or its last character does not match with the current character then append this character to the string ; Matches with the previous one ; Return the answer ; Driver Code"
Solution in C#:

using System ; class GFG { static String removeDuplicates ( String S ) { String ans = " " ; for ( int i = 0 ; i < S . Length ; i ++ ) { if ( ans == " " ans [ ans . Length - 1 ] != S [ i ] ) ans += S [ i ] ; else if ( ans [ ans . Length - 1 ] == S [ i ] ) ans = ans . Substring ( 0 , ans . Length - 1 ) ; } return ans ; } public static void Main ( String [ ] args ) { String str = " keexxllx " ; Console . WriteLine ( removeDuplicates ( str ) ) ; } }


"Remove last occurrence of a word from a given sentence string | C # program for the above approach ; Function to remove last occurrence of W from S ; If M is greater than N ; Iterate while i is greater than or equal to 0 ; Stores if occurrence of W has been found or not ; Iterate over the range [ 0 , M ] ; If S [ j + 1 ] is not equal to W [ j ] ; Mark flag true and break ; If occurrence has been found ; Delete the substring over the range [ i , i + M ] ; Resize the string S ; Return S ; Driver Code ; Input ; Function call"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { static string removeLastOccurrence ( string S , string W , int N , int M ) { char [ ] ch = S . ToCharArray ( ) ; if ( M > N ) return S ; for ( int i = N - M ; i >= 0 ; i -- ) { int flag = 0 ; for ( int j = 0 ; j < M ; j ++ ) { if ( ch [ j + i ] != W [ j ] ) { flag = 1 ; break ; } } if ( flag == 0 ) { for ( int j = i ; j < N - M ; j ++ ) ch [ j ] = ch [ j + M ] ; Array . Resize ( ref ch , N - M ) ; break ; } } S = string . Concat ( ch ) ; return S ; } public static void Main ( ) { string S = " This ▁ is ▁ GeeksForGeeks " ; string W = " Geeks " ; int N = S . Length ; int M = W . Length ; Console . Write ( removeLastOccurrence ( S , W , N , M ) ) ; } }


"Remove leading zeros from a Number given as a string | C # program to implement the above approach ; Function to remove all leading zeros from a a given string ; Regex to remove leading zeros from a string ; Replaces the matched value with given string ; Driver Code"
Solution in C#:

using System ; using System . Text . RegularExpressions ; class GFG { public static void removeLeadingZeros ( string str ) { string regex = " ^ 0 + ( ? ! $ ) " ; str = Regex . Replace ( str , regex , " " ) ; Console . WriteLine ( str ) ; } public static void Main ( string [ ] args ) { string str = "0001234" ; removeLeadingZeros ( str ) ; } }


"Remove minimum characters from string to split it into three substrings under given constraints | C # program for the above approach ; Function that counts minimum character that must be removed ; Length of string ; Create prefix array ; Initialize first position ; Fill prefix array ; Initialise maxi ; Check all the possibilities by putting i and j at different position & find maximum among them ; Print the characters to be removed ; Driver Code ; Given String ; Function call"
Solution in C#:

using System ; class GFG { static void min_remove ( string str ) { int N = str . Length ; int [ ] prefix_a = new int [ N + 1 ] ; int [ ] prefix_b = new int [ N + 1 ] ; int [ ] prefix_c = new int [ N + 1 ] ; prefix_a [ 0 ] = 0 ; prefix_b [ 0 ] = 0 ; prefix_c [ 0 ] = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { prefix_a [ i ] = prefix_a [ i - 1 ] + ( int ) ( ( str [ i - 1 ] == ' a ' ) ? 1 : 0 ) ; prefix_b [ i ] = prefix_b [ i - 1 ] + ( int ) ( ( str [ i - 1 ] == ' b ' ) ? 1 : 0 ) ; prefix_c [ i ] = prefix_c [ i - 1 ] + ( int ) ( ( str [ i - 1 ] == ' c ' ) ? 1 : 0 ) ; } int maxi = Int32 . MinValue ; for ( int i = 0 ; i <= N ; i ++ ) { for ( int j = i ; j <= N ; j ++ ) { maxi = Math . Max ( maxi , ( prefix_a [ i ] + ( prefix_b [ j ] - prefix_b [ i ] ) + ( prefix_c [ N ] - prefix_c [ j ] ) ) ) ; } } Console . WriteLine ( ( N - maxi ) ) ; } public static void Main ( ) { string str = " aaaabaaxccac " ; min_remove ( str ) ; } }


"Remove minimum elements from either side such that 2 * min becomes more than max | A O ( n * n ) solution to find the minimum of elements to be removed ; Returns the minimum number of removals from either end in arr [ l . . h ] so that 2 * min becomes greater than max . ; Initialize starting and ending indexes of the maximum sized subarray with property 2 * min > max ; Choose different elements as starting point ; Initialize min and max for the current start ; Choose different ending points for current start ; Update min and max if necessary ; If the property is violated , then no point to continue for a bigger array ; Update longest_start and longest_end if needed ; If not even a single element follow the property , then return n ; Return the number of elements to be removed ; Driver program to test above functions"
Solution in C#:

using System ; public class GFG { static int minRemovalsDP ( int [ ] arr , int n ) { int longest_start = - 1 , longest_end = 0 ; for ( int start = 0 ; start < n ; start ++ ) { int min = int . MaxValue , max = int . MinValue ; for ( int end = start ; end < n ; end ++ ) { int val = arr [ end ] ; if ( val < min ) { min = val ; } if ( val > max ) { max = val ; } if ( 2 * min <= max ) { break ; } if ( end - start > longest_end - longest_start longest_start == - 1 ) { longest_start = start ; longest_end = end ; } } } if ( longest_start == - 1 ) { return n ; } return ( n - ( longest_end - longest_start + 1 ) ) ; } public static void Main ( ) { int [ ] arr = { 4 , 5 , 100 , 9 , 10 , 11 , 12 , 15 , 200 } ; int n = arr . Length ; Console . WriteLine ( minRemovalsDP ( arr , n ) ) ; } }


"Remove minimum elements from either side such that 2 * min becomes more than max | C # implementation of above approach ; A utility function to find minimum of two numbers ; A utility function to find minimum in arr [ l . . h ] ; A utility function to find maximum in arr [ l . . h ] ; Returns the minimum number of removals from either end in arr [ l . . h ] so that 2 * min becomes greater than max . ; If there is 1 or less elements , return 0 For a single element , 2 * min > max ( Assumption : All elements are positive in arr [ ] ) ; 1 ) Find minimum and maximum in arr [ l . . h ] ; If the property is followed , no removals needed ; Otherwise remove a character from left end and recur , then remove a character from right end and recur , take the minimum of two is returned ; Driver Code"
Solution in C#:

using System ; class GFG { static int min ( int a , int b ) { return ( a < b ) ? a : b ; } static int min ( int [ ] arr , int l , int h ) { int mn = arr [ l ] ; for ( int i = l + 1 ; i <= h ; i ++ ) if ( mn > arr [ i ] ) mn = arr [ i ] ; return mn ; } static int max ( int [ ] arr , int l , int h ) { int mx = arr [ l ] ; for ( int i = l + 1 ; i <= h ; i ++ ) if ( mx < arr [ i ] ) mx = arr [ i ] ; return mx ; } static int minRemovals ( int [ ] arr , int l , int h ) { if ( l >= h ) return 0 ; int mn = min ( arr , l , h ) ; int mx = max ( arr , l , h ) ; if ( 2 * mn > mx ) return 0 ; return min ( minRemovals ( arr , l + 1 , h ) , minRemovals ( arr , l , h - 1 ) ) + 1 ; } public static void Main ( ) { int [ ] arr = { 4 , 5 , 100 , 9 , 10 , 11 , 12 , 15 , 200 } ; int n = arr . Length ; Console . Write ( minRemovals ( arr , 0 , n - 1 ) ) ; } }


"Remove minimum elements from either side such that 2 * min becomes more than max | C # program of above approach ; A utility function to find minimum of two numbers ; A utility function to find minimum in arr [ l . . h ] ; A utility function to find maximum in arr [ l . . h ] ; Returns the minimum number of removals from either end in arr [ l . . h ] so that 2 * min becomes greater than max . ; Create a table to store solutions of subproblems ; Fill table using above recursive formula . Note that the table is filled in diagonal fashion ( similar to http : goo . gl / PQqoS ) , from diagonal elements to table [ 0 ] [ n - 1 ] which is the result . ; Driver program to test above functions"
Solution in C#:

using System ; public class GFG { static int min ( int a , int b ) { return ( a < b ) ? a : b ; } static int min ( int [ ] arr , int l , int h ) { int mn = arr [ l ] ; for ( int i = l + 1 ; i <= h ; i ++ ) { if ( mn > arr [ i ] ) { mn = arr [ i ] ; } } return mn ; } static int max ( int [ ] arr , int l , int h ) { int mx = arr [ l ] ; for ( int i = l + 1 ; i <= h ; i ++ ) { if ( mx < arr [ i ] ) { mx = arr [ i ] ; } } return mx ; } static int minRemovalsDP ( int [ ] arr , int n ) { int [ , ] table = new int [ n , n ] ; int gap , i , j , mn , mx ; for ( gap = 0 ; gap < n ; ++ gap ) { for ( i = 0 , j = gap ; j < n ; ++ i , ++ j ) { mn = min ( arr , i , j ) ; mx = max ( arr , i , j ) ; table [ i , j ] = ( 2 * mn > mx ) ? 0 : min ( table [ i , j - 1 ] + 1 , table [ i + 1 , j ] + 1 ) ; } } return table [ 0 , n - 1 ] ; } public static void Main ( ) { int [ ] arr = { 20 , 4 , 1 , 3 } ; int n = arr . Length ; Console . WriteLine ( minRemovalsDP ( arr , n ) ) ; } }


"Remove minimum elements from ends of array so that sum decreases by at least K | O ( N ) | C # implementation of the approach ; Function to return the count of minimum elements to be removed from the ends of the array such that the sum of the array decrease by at least K ; To store the final answer ; Maximum possible sum required ; Left point ; Right pointer ; Total current sum ; Two pointer loop ; If the sum fits ; Update the answer ; Update the total sum ; Increment the left pointer ; Driver code"
Solution in C#:

using System ; class GFG { static int minCount ( int [ ] arr , int n , int k ) { int ans = 0 ; int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; sum -= k ; int l = 0 ; int r = 0 ; int tot = 0 ; while ( l < n ) { if ( tot <= sum ) { ans = Math . Max ( ans , r - l ) ; if ( r == n ) break ; tot += arr [ r ++ ] ; } else { tot -= arr [ l ++ ] ; } } return ( n - ans ) ; } public static void Main ( ) { int [ ] arr = { 1 , 11 , 5 , 5 } ; int n = arr . Length ; int k = 11 ; Console . WriteLine ( minCount ( arr , n , k ) ) ; } }


"Remove minimum elements from the array such that 2 * min becomes more than max | C # program to remove minimum elements from the array such that 2 * min becomes more than max ; Function to calculate upper bound ; Function to remove minimum elements from the array such that 2 * min becomes more than max ; Sort the array ; To store the required answer ; Traverse from left to right ; Update the answer ; Return the required answer ; Driver code ; Function call"
Solution in C#:

using System ; class GFG { public static int upperBound ( int [ ] array , int value ) { int low = 0 ; int high = array . Length ; while ( low < high ) { int mid = ( low + high ) / 2 ; if ( value >= array [ mid ] ) { low = mid + 1 ; } else { high = mid ; } } return low ; } public static int Removal ( int [ ] v , int n ) { Array . Sort ( v ) ; int ans = int . MaxValue ; int k = 0 ; foreach ( int i in v ) { int j = upperBound ( v , ( 2 * i ) ) ; ans = Math . Min ( ans , n - ( j - k ) ) ; k ++ ; } return ans ; } public static void Main ( String [ ] args ) { int [ ] a = { 4 , 5 , 100 , 9 , 10 , 11 , 12 , 15 , 200 } ; int n = a . Length ; Console . WriteLine ( Removal ( a , n ) ) ; } }


"Remove minimum number of elements such that no common element exist in both array | C # Code to Remove minimum number of elements such that no common element exist in both array ; To find no elements to remove so no common element exist ; To store count of array element ; Count elements of a ; Count elements of b ; Traverse through all common element , and pick minimum occurrence from two arrays ; To return count of minimum elements ; Driver code"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { public static int minRemove ( int [ ] a , int [ ] b , int n , int m ) { Dictionary < int , int > countA = new Dictionary < int , int > ( ) ; Dictionary < int , int > countB = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( countA . ContainsKey ( a [ i ] ) ) { var v = countA [ a [ i ] ] ; countA . Remove ( countA [ a [ i ] ] ) ; countA . Add ( a [ i ] , v + 1 ) ; } else countA . Add ( a [ i ] , 1 ) ; } for ( int i = 0 ; i < m ; i ++ ) { if ( countB . ContainsKey ( b [ i ] ) ) { var v = countB [ b [ i ] ] ; countB . Remove ( countB [ b [ i ] ] ) ; countB . Add ( b [ i ] , v + 1 ) ; } else countB . Add ( b [ i ] , 1 ) ; } int res = 0 ; foreach ( int x in countA . Keys ) if ( countB . ContainsKey ( x ) ) res += Math . Min ( countB [ x ] , countA [ x ] ) ; return res ; } public static void Main ( String [ ] args ) { int [ ] a = { 1 , 2 , 3 , 4 } ; int [ ] b = { 2 , 3 , 4 , 5 , 8 } ; int n = a . Length ; int m = b . Length ; Console . WriteLine ( minRemove ( a , b , n , m ) ) ; } }


"Remove nodes on root to leaf paths of length < K | C # program to remove nodes on root to leaf paths of length < k ; Class containing left and right child of current node and key value ; Utility method that actually removes the nodes which are not on the pathLen >= k . This method can change the root as well . ; Base condition ; Traverse the tree in postorder fashion so that if a leaf node path length is shorter than k , then that node and all of its descendants till the node which are not on some other path are removed . ; If root is a leaf node and it 's level is less than k then   remove this node.   This goes up and check for the ancestor nodes also for the   same condition till it finds a node which is a part of other   path(s) too.  ; Return root ; ; Method which calls the utitlity method to remove the short path nodes . ; Method to print the tree in inorder fashion . ; Driver program to test for samples"
Solution in C#:

using System ; public class Node { public int data ; public Node left , right ; public Node ( int item ) { data = item ; left = right = null ; } } public class BinaryTree { public Node root ; public virtual Node removeShortPathNodesUtil ( Node node , int level , int k ) { if ( node == null ) { return null ; } node . left = removeShortPathNodesUtil ( node . left , level + 1 , k ) ; node . right = removeShortPathNodesUtil ( node . right , level + 1 , k ) ; if ( node . left == null && node . right == null && level < k ) { return null ; } return node ; } public virtual Node removeShortPathNodes ( Node node , int k ) { int pathLen = 0 ; return removeShortPathNodesUtil ( node , 1 , k ) ; } public virtual void printInorder ( Node node ) { if ( node != null ) { printInorder ( node . left ) ; Console . Write ( node . data + " ▁ " ) ; printInorder ( node . right ) ; } } public static void Main ( string [ ] args ) { BinaryTree tree = new BinaryTree ( ) ; int k = 4 ; tree . root = new Node ( 1 ) ; tree . root . left = new Node ( 2 ) ; tree . root . right = new Node ( 3 ) ; tree . root . left . left = new Node ( 4 ) ; tree . root . left . right = new Node ( 5 ) ; tree . root . left . left . left = new Node ( 7 ) ; tree . root . right . right = new Node ( 6 ) ; tree . root . right . right . left = new Node ( 8 ) ; Console . WriteLine ( " The ▁ inorder ▁ traversal ▁ of ▁ original ▁ tree ▁ is ▁ : ▁ " ) ; tree . printInorder ( tree . root ) ; Node res = tree . removeShortPathNodes ( tree . root , k ) ; Console . WriteLine ( " " ) ; Console . WriteLine ( " The ▁ inorder ▁ traversal ▁ of ▁ modified ▁ tree ▁ is ▁ : ▁ " ) ; tree . printInorder ( res ) ; } }


"Remove odd indexed characters from a given string | C # program to implement the above approach ; Function to remove odd indexed characters from a given string ; Stores the resultant string ; If the current index is odd ; Skip the character ; Otherwise , append the character ; Return the modified string ; Driver Code ; Remove the characters which have odd index"
Solution in C#:

using System ; class GFG { static string removeOddIndexCharacters ( string s ) { string new_string = " " ; for ( int i = 0 ; i < s . Length ; i ++ ) { if ( i % 2 == 1 ) continue ; new_string += s [ i ] ; } return new_string ; } public static void Main ( ) { string str = " abcdef " ; str = removeOddIndexCharacters ( str ) ; Console . Write ( str ) ; } }


"Remove one bit from a binary number to get maximum value | C # program to find next maximum binary number with one bit removed ; Function to find the maximum binary number ; Traverse the binary number ; Try finding a 0 and skip it ; Driver Code ; Get the binary number ; Find the maximum binary number"
Solution in C#:

using System ; class GFG { static int printMaxAfterRemoval ( String s ) { bool flag = false ; int n = s . Length ; for ( int i = 0 ; i < n ; i ++ ) { if ( s [ i ] == '0' && flag == false ) { flag = true ; continue ; } else Console . Write ( s [ i ] ) ; } return 0 ; } static void Main ( ) { String s = "1001" ; printMaxAfterRemoval ( s ) ; } }


"Remove one element to get minimum OR value | C # implementation of the approach ; Function to return the minimized OR after removing an element from the array ; Base case ; Prefix and suffix OR array ; Computing prefix / suffix OR arrays ; To store the final answer ; Finding the final answer ; Returning the final answer ; Driver code"
Solution in C#:

using System ; class GFG { static int minOR ( int [ ] arr , int n ) { if ( n == 1 ) return 0 ; int [ ] pre = new int [ n ] ; int [ ] suf = new int [ n ] ; pre [ 0 ] = arr [ 0 ] ; suf [ n - 1 ] = arr [ n - 1 ] ; for ( int i = 1 ; i < n ; i ++ ) pre [ i ] = ( pre [ i - 1 ] arr [ i ] ) ; for ( int i = n - 2 ; i >= 0 ; i -- ) suf [ i ] = ( suf [ i + 1 ] arr [ i ] ) ; int ans = Math . Min ( pre [ n - 2 ] , suf [ 1 ] ) ; for ( int i = 1 ; i < n - 1 ; i ++ ) ans = Math . Min ( ans , ( pre [ i - 1 ] suf [ i + 1 ] ) ) ; return ans ; } static public void Main ( ) { int [ ] arr = { 1 , 2 , 3 } ; int n = arr . Length ; Console . WriteLine ( minOR ( arr , n ) ) ; } }


"Remove recurring digits in a given number | C # program to remove recurring digits from a given number ; Removes recurring digits in num [ ] ; int j = 0 ; Index in modified string ; Traverse digits of given number one by one ; Copy the first occurrence of new digit ; Remove repeating occurrences of digit ; Driver code"
Solution in C#:

using System ; class GFG { static String removeRecurringDigits ( char [ ] num ) { int len = num . Length ; String s = " " ; for ( int i = 0 ; i < len ; i ++ ) { s += String . Join ( " " , num [ i ] ) ; while ( i + 1 < len && num [ i ] == num [ i + 1 ] ) { i ++ ; } } return s ; } public static void Main ( ) { char [ ] num = "1299888833" . ToCharArray ( ) ; Console . Write ( " Modified ▁ number ▁ is ▁ " + removeRecurringDigits ( num ) ) ; } }


"Remove repeated digits in a given number | C # program to remove repeated digits ; Store first digits as previous digit ; Initialize power ; Iterate through all digits of n , note that the digits are processed from least significant digit to most significant digit . ; Store current digit ; Add the current digit to the beginning of result ; Update previous result and power ; Remove last digit from n ; Driver program"
Solution in C#:

using System ; class GFG { static long removeRecur ( long n ) { long prev_digit = n % 10 ; long pow = 10 ; long res = prev_digit ; while ( n > 0 ) { long curr_digit = n % 10 ; if ( curr_digit != prev_digit ) { res += curr_digit * pow ; prev_digit = curr_digit ; pow *= 10 ; } n = n / 10 ; } return res ; } public static void Main ( ) { long n = 12224 ; Console . WriteLine ( removeRecur ( n ) ) ; } }


"Remove spaces from a given string | An efficient C # program to remove all spaces from a string ; Function to remove all spaces from a given string ; To keep track of non - space character count ; Traverse the given string . If current character is not space , then place it at index ' count + + ' ; str [ count ++ ] = str [ i ] ; here count is incremented ; Driver code"
Solution in C#:

using System ; class GFG { static int removeSpaces ( char [ ] str ) { int count = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) if ( str [ i ] != ' ▁ ' ) return count ; } public static void Main ( String [ ] args ) { char [ ] str = " g ▁ eeks ▁ for ▁ ge ▁ eeks ▁ " . ToCharArray ( ) ; int i = removeSpaces ( str ) ; Console . WriteLine ( String . Join ( " " , str ) . Substring ( 0 , i ) ) ; } }


"Remove spaces from a given string | C # program to remove all spaces from a string ; Function to remove all spaces from a given string ; Driver Code"
Solution in C#:

using System ; class GFG { static String removeSpace ( String str ) { str = str . Replace ( " ▁ " , " " ) ; return str ; } public static void Main ( ) { String str = " g ▁ eeks ▁ for ▁ ge ▁ eeks ▁ " ; Console . WriteLine ( removeSpace ( str ) ) ; } }


"Remove the forbidden strings | C # program to remove forbidden strings ; number of forbidden strings ; original string ; forbidden strings ; to store original string as character array ; letter to replace and occur max number of times ; pre [ ] keeps record of the characters of w that need to be changed ; Function to check if the particular substring is present in w at position ; If length of substring from this position is greater than length of w then return ; n and n1 are used to check for substring without considering the case of the letters in w by comparing the difference of ASCII values ; If same == true then it means a substring was found starting at position therefore all characters from position to length of substring found need to be changed therefore they need to be marked ; Function performing calculations . ; To verify if any substring is starting from index i ; Modifying the string w according to th rules ; This condition checks if w [ i ] = upper ( letter ) ; This condition checks if w [ i ] is any lowercase letter apart from letter . If true replace it with letter ; This condition checks if w [ i ] is any uppercase letter apart from letter . If true then replace it with upper ( letter ) . ; Driver Code"
Solution in C#:

using System ; class GFG { public static int n ; public static string z ; public static string [ ] s = new string [ 100 ] ; public static char [ ] w ; public static char letter ; public static bool [ ] pre = new bool [ 100 ] ; public static void verify ( int position , int index ) { int l = z . Length ; int k = s [ index ] . Length ; if ( position + k > l ) { return ; } bool same = true ; for ( int i = position ; i < position + k ; i ++ ) { int n , n1 ; char ch = w [ i ] ; char ch1 = s [ index ] [ i - position ] ; if ( ch >= ' a ' && ch <= ' z ' ) { n = ch - ' a ' ; } else { n = ch - ' A ' ; } if ( ch1 >= ' a ' && ch1 <= ' z ' ) { n1 = ch1 - ' a ' ; } else { n1 = ch1 - ' A ' ; } if ( n != n1 ) { same = false ; } } if ( same == true ) { for ( int i = position ; i < position + k ; i ++ ) { pre [ i ] = true ; } return ; } } public static void solve ( ) { w = z . ToCharArray ( ) ; letter = ' d ' ; int l = z . Length ; int p = letter - ' a ' ; for ( int i = 0 ; i < 100 ; i ++ ) { pre [ i ] = false ; } for ( int i = 0 ; i < l ; i ++ ) { for ( int j = 0 ; j < n ; j ++ ) { verify ( i , j ) ; } } for ( int i = 0 ; i < l ; i ++ ) { if ( pre [ i ] == true ) { if ( w [ i ] == letter ) { w [ i ] = ( letter == ' a ' ) ? ' b ' : ' a ' ; } else if ( w [ i ] == ( char ) ( ( int ) ' A ' + p ) ) { w [ i ] = ( letter == ' a ' ) ? ' B ' : ' A ' ; } else if ( w [ i ] >= ' a ' && w [ i ] <= ' z ' ) { w [ i ] = letter ; } else if ( w [ i ] >= ' A ' && w [ i ] <= ' Z ' ) { w [ i ] = ( char ) ( ( int ) ' A ' + p ) ; } } } Console . WriteLine ( w ) ; } public static void Main ( string [ ] args ) { n = 3 ; s [ 0 ] = " etr " ; s [ 1 ] = " ed " ; s [ 2 ] = " ied " ; z = " PEtrUnited " ; solve ( ) ; } }


"Remove trailing zeros from the sum of two numbers ( Using Stack ) | C # program for the above approach ; Function to remove trailing zeros from the sum of two numbers ; Stores the sum of A and B ; Stores the digits ; Stores the equivalent string of integer N ; Traverse the string ; Push the digit at i in the stack ; While top element is '0' ; Pop the top element ; Stores the resultant number without tailing 0 's ; While s is not empty ; Append top element of S in res ; Pop the top element of S ; Reverse the string res ; Driver Code ; Input ; Function Call"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { static string removeTailing ( int A , int B ) { int N = A + B ; Stack < char > s = new Stack < char > ( ) ; string strsum = N . ToString ( ) ; for ( int i = 0 ; i < strsum . Length ; i ++ ) { s . Push ( strsum [ i ] ) ; } while ( s . Peek ( ) == '0' ) { s . Pop ( ) ; } string res = " " ; while ( s . Count != 0 ) { res = res + ( char ) s . Peek ( ) ; s . Pop ( ) ; } char [ ] str = res . ToCharArray ( ) ; Array . Reverse ( str ) ; return new string ( str ) ; } static public void Main ( ) { int A = 130246 , B = 450164 ; Console . WriteLine ( removeTailing ( A , B ) ) ; } }


"Remove two consecutive integers from 1 to N to make sum equal to S | C # program remove two consecutive integers from 1 to N to make sum equal to S ; Function to find the numbers to be removed ; typecast appropriately so that answer is float ; return the obtained result ; Convert i to integer ; If i is an integer is 0 then answer is Yes ; Driver code"
Solution in C#:

using System ; class GFG { static float findNumber ( int N , int S ) { float i = ( ( ( float ) ( N ) * ( float ) ( N + 1 ) ) / 4 ) - ( ( float ) ( S + 1 ) / 2 ) ; return i ; } static void check ( int N , int S ) { float i = findNumber ( N , S ) ; int integerI = ( int ) i ; if ( i - integerI == 0 ) Console . WriteLine ( " Yes : ▁ " + integerI + " , ▁ " + ( integerI + 1 ) ) ; else Console . WriteLine ( " No " ) ; } public static void Main ( ) { int N = 4 , S = 3 ; check ( N , S ) ; N = 5 ; S = 3 ; check ( N , S ) ; } }


"Remove vowels from a string stored in a Binary Tree | C # program for the above approach ; Structure Representing the Node in the Binary tree ; Function to perform a level order insertion of a new Node in the Binary tree ; If the root is empty , make it point to the new Node ; In case there are elements in the Binary tree , perform a level order traversal using a Queue ; If the left child does not exist , insert the new Node as the left child ; In case the right child does not exist , insert the new Node as the right child ; Function to print the level order traversal of the Binary tree ; Function to check if the character is a vowel or not . ; Function to remove the vowels in the new Binary tree ; Declaring the root of the new tree ; If the given character is not a vowel , add it to the new Binary tree ; Driver code"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { class Node { public char data ; public Node left , right ; public Node ( char _val ) { data = _val ; left = right = null ; } } ; static Node addinBT ( Node root , char data ) { if ( root == null ) { root = new Node ( data ) ; } else { List < Node > Q = new List < Node > ( ) ; Q . Add ( root ) ; while ( Q . Count != 0 ) { Node temp = Q [ 0 ] ; Q . RemoveAt ( 0 ) ; if ( temp . left == null ) { temp . left = new Node ( data ) ; break ; } else Q . Add ( temp . left ) ; if ( temp . right == null ) { temp . right = new Node ( data ) ; break ; } else Q . Add ( temp . right ) ; } } return root ; } static void print ( Node root ) { List < Node > Q = new List < Node > ( ) ; Q . Add ( root ) ; while ( Q . Count > 0 ) { Node temp = Q [ 0 ] ; Q . RemoveAt ( 0 ) ; Console . Write ( temp . data ) ; if ( temp . left != null ) Q . Add ( temp . left ) ; if ( temp . right != null ) Q . Add ( temp . right ) ; } } static bool checkvowel ( char ch ) { ch = char . ToLower ( ch ) ; if ( ch == ' a ' ch == ' e ' ch == ' i ' ch == ' o ' ch == ' u ' ) { return true ; } else { return false ; } } static Node removevowels ( Node root ) { List < Node > Q = new List < Node > ( ) ; Q . Add ( root ) ; Node root1 = null ; while ( Q . Count != 0 ) { Node temp = Q [ 0 ] ; Q . RemoveAt ( 0 ) ; if ( ! checkvowel ( temp . data ) ) { root1 = addinBT ( root1 , temp . data ) ; } if ( temp . left != null ) { Q . Add ( temp . left ) ; } if ( temp . right != null ) { Q . Add ( temp . right ) ; } } return root1 ; } public static void Main ( String [ ] args ) { String s = " geeks " ; Node root = null ; for ( int i = 0 ; i < s . Length ; i ++ ) { root = addinBT ( root , s [ i ] ) ; } root = removevowels ( root ) ; print ( root ) ; } }


"Removing a number from array without changing its arithmetic mean | C # program to remove a number from the array without changing its arithmetic mean ; Function to remove a number from the array without changing its arithmetic mean ; Find sum of all elements ; If mean is an integer ; Check if mean is present in the array or not ; Driver code"
Solution in C#:

using System ; class GFG { static int FindElement ( int [ ] a , int n ) { int sum = 0 ; for ( int i = 0 ; i < n ; i ++ ) sum = sum + a [ i ] ; if ( sum % n == 0 ) { int m = sum / n ; for ( int i = 0 ; i < n ; i ++ ) if ( a [ i ] == m ) return m ; } return - 1 ; } public static void Main ( ) { int [ ] a = { 1 , 2 , 3 , 4 , 5 } ; int n = a . Length ; Console . WriteLine ( FindElement ( a , n ) ) ; } }


"Removing elements between the two zeros | C # program to delete elements between zeros ; Function to find the string after operation ; Travesing through string ; Checking for character Between two zeros ; deleting the character At specific position ; updating the length of the string ; Driver code"
Solution in C#:

using System ; class GFG { static string findstring ( string s ) { int n = s . Length ; string st = " " ; for ( int i = 1 ; i < n - 1 ; i ++ ) { if ( ( s [ i - 1 ] == '0' && s [ i + 1 ] == '0' ) ) { st = s . Remove ( i , 1 ) ; s = st ; i -- ; if ( i > 0 && s [ i - 1 ] == '0' ) i -- ; n = s . Length ; } } return s ; } static void Main ( ) { Console . Write ( findstring ( "100100" ) ) ; } }


"Reorder an array according to given indexes | A O ( n ) time and O ( 1 ) extra space C # program to sort an array according to given indexes ; Method to reorder elements of arr [ ] according to index [ ] ; Fix all elements one by one ; While index [ i ] and arr [ i ] are not fixed ; Store values of the target ( or correct ) position before placing arr [ i ] there ; Place arr [ i ] at its target ( or correct ) position . Also copy corrected index for new position ; Copy old target values to arr [ i ] and index [ i ] ; Driver method to test the above function"
Solution in C#:

using System ; public class Test { static int [ ] arr = new int [ ] { 50 , 40 , 70 , 60 , 90 } ; static int [ ] index = new int [ ] { 3 , 0 , 4 , 1 , 2 } ; static void reorder ( ) { for ( int i = 0 ; i < arr . Length ; i ++ ) { while ( index [ i ] != i ) { int oldTargetI = index [ index [ i ] ] ; char oldTargetE = ( char ) arr [ index [ i ] ] ; arr [ index [ i ] ] = arr [ i ] ; index [ index [ i ] ] = index [ i ] ; index [ i ] = oldTargetI ; arr [ i ] = oldTargetE ; } } } public static void Main ( ) { reorder ( ) ; Console . WriteLine ( " Reordered ▁ array ▁ is : ▁ " ) ; Console . WriteLine ( String . Join ( " ▁ " , arr ) ) ; Console . WriteLine ( " Modified ▁ Index ▁ array ▁ is : " ) ; Console . WriteLine ( String . Join ( " ▁ " , index ) ) ; } }


"Reorder an array according to given indexes | C # code to reorder an array according to given indices ; left child in 0 based indexing ; right child in 1 based indexing ; Find largest index from root , left and right child ; Swap arr whenever index is swapped ; Build heap ; Swap the largest element of index ( first element ) with the last element ; Swap arr whenever index is swapped ; Driver Code"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { static int heapSize ; public static void heapify ( int [ ] arr , int [ ] index , int i ) { int largest = i ; int left = 2 * i + 1 ; int right = 2 * i + 2 ; if ( left < heapSize && index [ left ] > index [ largest ] ) { largest = left ; } if ( right < heapSize && index [ right ] > index [ largest ] ) { largest = right ; } if ( largest != i ) { int temp = arr [ largest ] ; arr [ largest ] = arr [ i ] ; arr [ i ] = temp ; temp = index [ largest ] ; index [ largest ] = index [ i ] ; index [ i ] = temp ; heapify ( arr , index , largest ) ; } } public static void heapSort ( int [ ] arr , int [ ] index , int n ) { for ( int i = ( n - 1 ) / 2 ; i >= 0 ; i -- ) { heapify ( arr , index , i ) ; } for ( int i = n - 1 ; i > 0 ; i -- ) { int temp = index [ 0 ] ; index [ 0 ] = index [ i ] ; index [ i ] = temp ; temp = arr [ 0 ] ; arr [ 0 ] = arr [ i ] ; arr [ i ] = temp ; heapSize -- ; heapify ( arr , index , 0 ) ; } } static void Main ( ) { int [ ] arr = { 50 , 40 , 70 , 60 , 90 } ; int [ ] index = { 3 , 0 , 4 , 1 , 2 } ; int n = arr . Length ; heapSize = n ; heapSort ( arr , index , n ) ; Console . WriteLine ( " Reordered ▁ array ▁ is : ▁ " ) ; for ( int i = 0 ; i < n ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; Console . WriteLine ( ) ; Console . WriteLine ( " Modified ▁ Index ▁ array ▁ is : ▁ " ) ; for ( int i = 0 ; i < n ; i ++ ) Console . Write ( index [ i ] + " ▁ " ) ; } }


"Reorder an array according to given indexes | C # to find positions of zeroes flipping which produces maximum number of consecutive 1 's ; Method to reorder elements of arr [ ] according to index [ ] ; arr [ i ] should be present at index [ i ] index ; Copy temp [ ] to arr [ ] ; Driver method to test the above function"
Solution in C#:

using System ; public class Test { static int [ ] arr = new int [ ] { 50 , 40 , 70 , 60 , 90 } ; static int [ ] index = new int [ ] { 3 , 0 , 4 , 1 , 2 } ; static void reorder ( ) { int [ ] temp = new int [ arr . Length ] ; for ( int i = 0 ; i < arr . Length ; i ++ ) temp [ index [ i ] ] = arr [ i ] ; for ( int i = 0 ; i < arr . Length ; i ++ ) { arr [ i ] = temp [ i ] ; index [ i ] = i ; } } public static void Main ( ) { reorder ( ) ; Console . WriteLine ( " Reordered ▁ array ▁ is : ▁ " ) ; Console . WriteLine ( string . Join ( " , " , arr ) ) ; Console . WriteLine ( " Modified ▁ Index ▁ array ▁ is : " ) ; Console . WriteLine ( string . Join ( " , " , index ) ) ; } }


"Reorder an array such that sum of left half is not equal to sum of right half | C # code for the above approach ; Function to print the required reordering of array if possible ; Sort the array in increasing order ; If all elements are equal , then it is not possible ; Else print the sorted array arr [ ] ; Driver code ; Given array ; Function call"
Solution in C#:

 using System ; class GFG { public static void printArr ( int [ ] arr , int n ) { Array . Sort ( arr ) ; if ( arr [ 0 ] == arr [ n - 1 ] ) { Console . Write ( " No
 " ) ; } else { Console . Write ( " Yes
 " ) ; for ( int i = 0 ; i < n ; i ++ ) { Console . Write ( arr [ i ] + " ▁ " ) ; } } } public static void Main ( ) { int [ ] arr = new int [ 6 ] { 1 , 2 , 2 , 1 , 3 , 1 } ; int N = arr . Length ; printArr ( arr , N ) ; } }


"Reorder characters of a string to valid English representations of digits | C # program to implement the above approach ; Function to construct the original set of digits from the string in ascending order ; Store the unique characters corresponding to word and number ; Store the required result ; Store the frequency of each character of S ; Traverse the unique characters ; Store the count of k [ i ] in S ; Traverse the corresponding word ; Decrement the frequency of characters by x ; Append the digit x times to ans ; Sort the digits in ascending order ; Driver Code ; Given string , s ; Function Call"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { static string construct_digits ( string s ) { char [ ] k = { ' z ' , ' w ' , ' u ' , ' x ' , ' g ' , ' h ' , ' o ' , ' f ' , ' v ' , ' i ' } ; string [ ] l = { " zero " , " two " , " four " , " six " , " eight " , " three " , " one " , " five " , " seven " , " nine " } ; int [ ] c = { 0 , 2 , 4 , 6 , 8 , 3 , 1 , 5 , 7 , 9 } ; List < string > ans = new List < string > ( ) ; Dictionary < char , int > d = new Dictionary < char , int > ( ) ; for ( int i = 0 ; i < s . Length ; i ++ ) { if ( ! d . ContainsKey ( s [ i ] ) ) d [ s [ i ] ] = 0 ; d [ s [ i ] ] += 1 ; } for ( int i = 0 ; i < k . Length ; i ++ ) { int x = 0 ; if ( d . ContainsKey ( k [ i ] ) ) x = d [ k [ i ] ] ; for ( int j = 0 ; j < l [ i ] . Length ; j ++ ) { if ( d . ContainsKey ( l [ i ] [ j ] ) ) d [ l [ i ] [ j ] ] -= x ; } ans . Add ( ( ( c [ i ] ) * x ) . ToString ( ) ) ; } ans . Sort ( ) ; string str = ( String . Join ( " " , ans . ToArray ( ) ) ) ; return str . Replace ( "0" , " " ) ; } public static void Main ( string [ ] args ) { string s = " fviefuro " ; Console . WriteLine ( construct_digits ( s ) ) ; } }


"Reorder the position of the words in alphabetical order | C # implementation of the approach ; Function to print the ordering of words ; Creating list of words and assigning them index numbers ; Sort the list of words lexicographically ; Print the ordering ; Driver Code"
Solution in C#:

using System ; using System . Collections . Generic ; class GFG { static void reArrange ( String [ ] words , int n ) { Dictionary < String , int > freq = new Dictionary < String , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { freq . Add ( words [ i ] , ( i + 1 ) ) ; } Array . Sort ( words ) ; for ( int i = 0 ; i < n ; i ++ ) Console . Write ( freq [ words [ i ] ] + " ▁ " ) ; } public static void Main ( String [ ] args ) { String [ ] words = { " live " , " place " , " travel " , " word " , " sky " } ; int n = words . Length ; reArrange ( words , n ) ; } }


"Repdigit Numbers | C # implementation to check if a number is Repdigit ; Function to check if a number is a Repdigit number ; To store previous digit ( Assigning initial value which is less than any digit ) ; Traverse all digits from right to left and check if any digit is smaller than previous . ; Driver code"
Solution in C#:

using System ; class GFG { static bool isRepdigit ( int num , int b ) { int prev = - 1 ; while ( num != 0 ) { int digit = num % b ; num /= b ; if ( prev != - 1 && digit != prev ) return false ; prev = digit ; } return true ; } public static void Main ( ) { int num = 2000 , base1 = 7 ; if ( isRepdigit ( num , base1 ) ) { Console . Write ( " Yes " ) ; } else { Console . Write ( " No " ) ; } } }


"Repeat last occurrence of each alphanumeric character to their position in character family times | C # program for the above approach ; Function to encode the given string ; Variable string to store the result ; Arrays to store the last occuring index of every character in the string ; Length of the string ; Iterate over the range ; If str [ i ] is between 0 and 9 ; If str [ i ] is between a and z ; If str [ i ] is between A and Z ; Iterate over the range ; If str [ i ] is between a and z and i is the last occurence in str ; If str [ i ] is between A and Z and i is the last occurence in str ; If str [ i ] is between 0 and 9 and i is the last occurence in str ; Print the result ; Driver Code"
Solution in C#:

using System ; public class GFG { static void encodeString ( String str ) { String res = " " ; int [ ] small = new int [ 26 ] ; int [ ] capital = new int [ 26 ] ; int [ ] num = new int [ 10 ] ; for ( int i = 0 ; i < 26 ; i ++ ) { small [ i ] = 0 ; capital [ i ] = 0 ; } for ( int i = 0 ; i < 10 ; i ++ ) { num [ i ] = 0 ; } int n = str . Length ; for ( int i = 0 ; i < n ; i ++ ) { if ( str [ i ] >= '0' && str [ i ] <= '9' ) { num [ str [ i ] - 48 ] = i ; } else if ( str [ i ] >= ' a ' && str [ i ] <= ' z ' ) { small [ str [ i ] - 97 ] = i ; } else if ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) { capital [ str [ i ] - 65 ] = i ; } } for ( int i = 0 ; i < n ; i ++ ) { if ( ( str [ i ] >= ' a ' && str [ i ] <= ' z ' ) && small [ str [ i ] - 97 ] == i ) { int occ = str [ i ] - 96 ; while ( occ -- > 0 ) { res += str [ i ] ; } } else if ( ( str [ i ] >= ' A ' && str [ i ] <= ' Z ' ) && capital [ str [ i ] - 65 ] == i ) { int occ = str [ i ] - 64 ; while ( occ -- > 0 ) { res = res + str [ i ] ; } } else if ( ( str [ i ] >= '0' && str [ i ] <= '9' ) && num [ str [ i ] - 48 ] == i ) { int occ = str [ i ] - 48 ; while ( occ -- > 0 ) { res = res + str [ i ] ; } } else { res = res + str [ i ] ; } } Console . Write ( res ) ; } public static void Main ( String [ ] args ) { String str = " Ea2 , ▁ 0 , ▁ E " ; encodeString ( str ) ; } }


"Repeat substrings of the given String required number of times | C # implementation of the approach ; Function that returns true if the passed character is a digit ; Function to return the next index of a non - digit character in the string starting at the index i ( returns - 1 ifno such index is found ) ; If the character at index i is a digit then skip to the next character ; If no such index was found ; Function to append str the given number of times to the StringBuilder ; Function to return the string after performing the given operations ; To build the resultant string ; Index of the first non - digit character in the string ; While there are substrings that do not consist of digits ; Find the ending of the substring ; Starting index of the number ; If no digit appears after the current substring ; Find the index at which the current number ends ; Parse the number from the substring ; Repeat the current substring required number of times ; Find the next non - digit character index ; Return the resultant string ; Driver code"
Solution in C#:

using System ; using System . Text ; class GFG { static bool isDigit ( char ch ) { if ( ch >= '0' && ch <= '9' ) return true ; return false ; } static int nextNonDigit ( string str , int i ) { while ( i < str . Length && isDigit ( str [ i ] ) ) { i ++ ; } if ( i >= str . Length ) return - 1 ; return i ; } static void appendRepeated ( StringBuilder sb , string str , int times ) { for ( int i = 0 ; i < times ; i ++ ) sb . Append ( str ) ; } static String findString ( string str , int n ) { StringBuilder sb = new StringBuilder ( " " ) ; int startStr = nextNonDigit ( str , 0 ) ; while ( startStr != - 1 ) { int endStr = startStr ; while ( ( endStr + 1 ) < n && ! isDigit ( str [ endStr + 1 ] ) ) { endStr ++ ; } int startNum = endStr + 1 ; if ( startNum == - 1 ) break ; int endNum = startNum ; while ( ( endNum + 1 ) < n && isDigit ( str [ endNum + 1 ] ) ) { endNum ++ ; } int num = Int32 . Parse ( str . Substring ( startNum , endNum - startNum + 1 ) ) ; appendRepeated ( sb , str . Substring ( startStr , endStr - startStr + 1 ) , num ) ; startStr = nextNonDigit ( str , endStr + 1 ) ; } return sb . ToString ( ) ; } public static void Main ( string [ ] args ) { string str = " g1ee1ks1for1g1e2ks1" ; int n = str . Length ; Console . Write ( findString ( str , n ) ) ; } }


"Repeated Character Whose First Appearance is Leftmost | C # program to find first repeating character ; The function returns index of the first repeating character in a string . If all characters are repeating then returns - 1 ; Mark all characters as not visited ; Traverse from right and update res as soon as we see a visited character . ; Driver Code"
Solution in C#:

using System ; class GFG { static int NO_OF_CHARS = 256 ; static int firstRepeating ( String str ) { Boolean [ ] visited = new Boolean [ NO_OF_CHARS ] ; for ( int i = 0 ; i < NO_OF_CHARS ; i ++ ) visited [ i ] = false ; int res = - 1 ; for ( int i = str . Length - 1 ; i >= 0 ; i -- ) { if ( visited [ str [ i ] ] == false ) visited [ str [ i ] ] = true ; else res = i ; } return res ; } public static void Main ( String [ ] args ) { String str = " geeksforgeeks " ; int index = firstRepeating ( str ) ; if ( index == - 1 ) Console . Write ( " Either ▁ all ▁ characters ▁ are ▁ " + " distinct ▁ or ▁ string ▁ is ▁ empty " ) ; else Console . Write ( " First ▁ Repeating ▁ character " + " ▁ is ▁ { 0 } " , str [ index ] ) ; } }


"Repeated Unit Divisibility | C # program to find least value of k for which R ( k ) is divisible by n ; To find least value of k ; To check n is coprime or not ; to store the R ( k ) mod n and 10 ^ k mod n value ; Driver code"
Solution in C#:

using System ; public class GFG { public static int repUnitValue ( int n ) { if ( n % 2 == 0 n % 5 == 0 ) return 0 ; int rem = 1 ; int power = 1 ; int k = 1 ; while ( rem % n != 0 ) { k ++ ; power = power * 10 % n ; rem = ( rem + power ) % n ; } return k ; } public static void Main ( ) { int n = 13 ; Console . Write ( repUnitValue ( n ) ) ; } }


"Repeated subsequence of length 2 or more | C # program to check if any repeated subsequence exists in the string ; A function to check if a string str is palindrome ; l and h are leftmost and rightmost corners of str Keep comparing characters while they are same ; The main function that checks if repeated subsequence exists in the string ; Find length of input string ; Create an array to store all characters and their frequencies in str [ ] ; Traverse the input string and store frequencies of all characters in freq [ ] array . ; If the character count is more than 2 we found a repetition ; In - place remove non - repeating characters from the string ; check if the resultant string is palindrome ; special case - if length is odd return true if the middle character is same as previous one ; It is checked so that StringIndexOutOfBounds can be avoided ; return false if string is a palindrome ; return true if string is not a palindrome ; Driver Code"
Solution in C#:

using System ; class GFG { static int MAX_CHAR = 256 ; public static Boolean isPalindrome ( String str , int l , int h ) { while ( h > l ) if ( str [ l ++ ] != str [ h -- ] ) return false ; return true ; } public static Boolean check ( String str ) { int n = str . Length ; int [ ] freq = new int [ MAX_CHAR ] ; for ( int i = 0 ; i < n ; i ++ ) { freq [ str [ i ] ] ++ ; if ( freq [ str [ i ] ] > 2 ) return true ; } int k = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( freq [ str [ i ] ] > 1 ) str . Replace ( str [ k ++ ] , str [ i ] ) ; str . Replace ( str [ k ] , ' \0' ) ; if ( isPalindrome ( str , 0 , k - 1 ) ) { if ( ( k & 1 ) == 1 ) { if ( k / 2 >= 1 ) return ( str [ k / 2 ] == str [ k / 2 - 1 ] ) ; } return false ; } return true ; } public static void Main ( String [ ] args ) { String str = " ABCABD " ; if ( check ( str ) ) Console . WriteLine ( " Repeated ▁ Subsequence ▁ Exists " ) ; else Console . WriteLine ( " Repeated ▁ Subsequence " + " ▁ Doesn ' t ▁ Exists " ) ; } }


"Repeated subtraction among two numbers | C # program to count of steps until one of the two numbers become 0. ; Returns count of steps before one of the numbers become 0 after repeated subtractions . ; If y divides x , then simply return x / y . ; Else recur . Note that this function works even if x is smaller than y because in that case first recursive call exchanges roles of x and y . ; Driver Code"
Solution in C#:

using System ; class GFG { static int countSteps ( int x , int y ) { if ( x % y == 0 ) return x / y ; return x / y + countSteps ( y , x % y ) ; } static public void Main ( ) { int x = 100 , y = 19 ; Console . WriteLine ( countSteps ( x , y ) ) ; } }


"Repeated sum of first N natural numbers | C # implementation of the approach ; Function to return the sum of the first n natural numbers ; Function to return the repeated sum ; Perform the operation exactly k times ; Update n with the sum of first n natural numbers ; Driver code"
Solution in C#:

using System ; class GFG { static int sum ( int n ) { int sum = ( n * ( n + 1 ) ) / 2 ; return sum ; } static int repeatedSum ( int n , int k ) { for ( int i = 0 ; i < k ; i ++ ) { n = sum ( n ) ; } return n ; } public static void Main ( String [ ] args ) { int n = 2 , k = 2 ; Console . WriteLine ( repeatedSum ( n , k ) ) ; } }


"Repeatedly search an element by doubling it after every successful search | C # program to repeatedly search an element by doubling it after every successful search ; Sort the given array so that binary search can be applied on it ; Maximum array element ; search for the element b present or not in array ; Driver code"
Solution in C#:

using System ; public class GFG { static int findElement ( int [ ] a , int n , int b ) { Array . Sort ( a ) ; int max = a [ n - 1 ] ; while ( b < max ) { if ( Array . BinarySearch ( a , b ) > - 1 ) b *= 2 ; else return b ; } return b ; } public static void Main ( ) { int [ ] a = { 1 , 2 , 3 } ; int n = a . Length ; int b = 1 ; Console . WriteLine ( findElement ( a , n , b ) ) ; } }


"Replace ' ? ' in a string such that no two adjacent characters are same | C # program for the above approach ; Function that replace all ' ? ' with lowercase alphabets such that each adjacent character is different ; Store the given String ; If the first character is ' ? ' ; Traverse the String [ 1 , N - 1 ] ; If the current character is ' ? ' ; Change the character ; Check equality with the previous character ; Check equality with the next character ; Check equality with the previous character ; If the last character is ' ? ' ; Change character ; Check with previous character ; Return the resultant String ; Driver Code ; Given String S ; Function Call"
Solution in C#:

using System ; class GFG { static string changeString ( string S ) { char [ ] s = S . ToCharArray ( ) ; int N = S . Length ; if ( s [ 0 ] == ' ? ' ) { s [ 0 ] = ' a ' ; if ( s [ 0 ] == s [ 1 ] ) { s [ 0 ] ++ ; } } for ( int i = 1 ; i < N - 1 ; i ++ ) { if ( s [ i ] == ' ? ' ) { s [ i ] = ' a ' ; if ( s [ i ] == s [ i - 1 ] ) { s [ i ] ++ ; } if ( s [ i ] == s [ i + 1 ] ) { s [ i ] ++ ; } if ( s [ i ] == s [ i - 1 ] ) { s [ i ] ++ ; } } } if ( s [ N - 1 ] == ' ? ' ) { s [ N - 1 ] = ' a ' ; if ( s [ N - 1 ] == s [ N - 2 ] ) { s [ N - 1 ] ++ ; } } string ans = " " ; for ( int i = 0 ; i < s . Length ; i ++ ) { ans += s [ i ] ; } return ans ; } public static void Main ( ) { string S = " ? a ? a " ; Console . WriteLine ( changeString ( S ) ) ; } }


"Replace a character c1 with c2 and c2 with c1 in a string S | C # program to replace c1 with c2 and c2 with c1 ; loop to traverse in the string ; check for c1 and replace ; check for c2 and replace ; Driver code"
Solution in C#:

using System ; public class GFG { static String replace ( String s , char c1 , char c2 ) { int l = s . Length ; char [ ] arr = s . ToCharArray ( ) ; for ( int i = 0 ; i < l ; i ++ ) { if ( arr [ i ] == c1 ) arr [ i ] = c2 ; else if ( arr [ i ] == c2 ) arr [ i ] = c1 ; } return string . Join ( " " , arr ) ; } public static void Main ( ) { String s = " grrksfoegrrks " ; char c1 = ' e ' , c2 = ' r ' ; Console . WriteLine ( replace ( s , c1 , c2 ) ) ; } }


"Replace all array elements with the nearest power of its previous element | C # program for the above approach ; Function to calculate log x for given base ; Function to replace all array elements with the nearest power of previous adjacent nelement ; For the first element , set the last array element to its previous element ; Traverse the array ; Find K for which x ^ k is nearest to arr [ i ] ; Find the power to x nearest to arr [ i ] ; Update x ; Driver Code ; Function Call ; Display the array"
Solution in C#:

using System ; class GFG { static int LOG ( int a , int b ) { return ( int ) ( Math . Log ( a ) / Math . Log ( b ) ) ; } static void repbyNP ( int [ ] arr , int n ) { int x = arr [ n - 1 ] ; for ( int i = 0 ; i < n ; i ++ ) { int k = LOG ( arr [ i ] , x ) ; int temp = arr [ i ] ; if ( Math . Abs ( Math . Pow ( x , k ) - arr [ i ] ) < Math . Abs ( Math . Pow ( x , k + 1 ) - arr [ i ] ) ) arr [ i ] = ( int ) Math . Pow ( x , k ) ; else arr [ i ] = ( int ) Math . Pow ( x , k + 1 ) ; x = temp ; } } public static void Main ( string [ ] args ) { int [ ] arr = { 2 , 4 , 6 , 3 , 11 } ; int n = arr . Length ; repbyNP ( arr , n ) ; for ( int i = 0 ; i < n ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; } }


"Replace all consonants with nearest vowels in a string | C # program to replace all consonants with nearest vowels in a string ; Function to check if a character is vowel or not ; Function to replace consonant with nearest vowels ; if , string element is vowel , jump to next element ; check if consonant lies between two vowels , if it lies , than replace it with nearest vowel ; here the bsolute difference of ascii value is considered ; when s [ i ] is equal to either ' v ' , ' w ' , ' x ' , ' y ' , ' z ' ; Driver code"
Solution in C#:

using System ; public class Solution { static bool isVowel ( char ch ) { if ( ch != ' a ' && ch != ' e ' && ch != ' i ' && ch != ' o ' && ch != ' u ' ) return false ; return true ; } static String replacingConsonants ( String s ) { for ( int i = 0 ; i < s . Length ; i ++ ) { if ( isVowel ( s [ i ] ) ) continue ; else { if ( s [ i ] > ' a ' && s [ i ] < ' e ' ) { if ( Math . Abs ( s [ i ] - ' a ' ) > Math . Abs ( s [ i ] - ' e ' ) ) s = s . Substring ( 0 , i ) + ' e ' + s . Substring ( i + 1 ) ; else s = s . Substring ( 0 , i ) + ' a ' + s . Substring ( i + 1 ) ; } else if ( s [ i ] > ' e ' && s [ i ] < ' i ' ) { if ( Math . Abs ( s [ i ] - ' e ' ) > Math . Abs ( s [ i ] - ' i ' ) ) s = s . Substring ( 0 , i ) + ' i ' + s . Substring ( i + 1 ) ; else s = s . Substring ( 0 , i ) + ' e ' + s . Substring ( i + 1 ) ; } else if ( s [ i ] > ' i ' && s [ i ] < ' o ' ) { if ( Math . Abs ( s [ i ] - ' i ' ) > Math . Abs ( s [ i ] - ' o ' ) ) s = s . Substring ( 0 , i ) + ' o ' + s . Substring ( i + 1 ) ; else s = s . Substring ( 0 , i ) + ' i ' + s . Substring ( i + 1 ) ; } else if ( s [ i ] > ' o ' && s [ i ] < ' u ' ) { if ( Math . Abs ( s [ i ] - ' o ' ) > Math . Abs ( s [ i ] - ' u ' ) ) s = s . Substring ( 0 , i ) + ' u ' + s . Substring ( i + 1 ) ; else s = s . Substring ( 0 , i ) + ' o ' + s . Substring ( i + 1 ) ; } else if ( s [ i ] > ' u ' ) s = s . Substring ( 0 , i ) + ' u ' + s . Substring ( i + 1 ) ; } } return s ; } public static void Main ( ) { String s = " geeksforgeeks " ; Console . WriteLine ( replacingConsonants ( s ) ) ; } }


"Replace all consonants with nearest vowels in a string | C # program to replace all consonants with nearest vowels in a string ; Function to replace consonant with nearest vowels ; Driver code"
Solution in C#:

using System ; public class solution { static String replacingConsonants ( String s ) { String str = " aaaeeeeiiiiioooooouuuuuuuu " ; char [ ] st = s . ToCharArray ( ) ; for ( int i = 0 ; i < s . Length ; i ++ ) { int index = st [ i ] - ' a ' ; st [ i ] = str [ index ] ; } String str1 = new String ( st ) ; return str1 ; } public static void Main ( ) { String s = " geeksforgeeks " ; Console . WriteLine ( replacingConsonants ( s ) ) ; } }


"Replace all elements by difference of sums of positive and negative numbers after that element | C # program to implement above approach ; Function to print the array elements ; Function to replace all elements with absolute difference of absolute sums of positive and negative elements ; Calculate absolute sums of positive and negative elements in range i + 1 to N ; calculate difference of both sums ; replace i - th elements with absolute difference ; Driver code"
Solution in C#:

using System ; class GFG { static void printArray ( int N , int [ ] arr ) { for ( int i = 0 ; i < N ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; Console . WriteLine ( ) ; } static void replacedArray ( int N , int [ ] arr ) { int pos_sum , neg_sum , i , j , diff ; for ( i = 0 ; i < N ; i ++ ) { pos_sum = 0 ; neg_sum = 0 ; for ( j = i + 1 ; j < N ; j ++ ) { if ( arr [ j ] > 0 ) pos_sum += arr [ j ] ; else neg_sum += arr [ j ] ; } diff = Math . Abs ( pos_sum ) - Math . Abs ( neg_sum ) ; arr [ i ] = Math . Abs ( diff ) ; } } static void Main ( ) { int N = 5 ; int [ ] arr = { 1 , - 1 , 2 , 3 , - 2 } ; replacedArray ( N , arr ) ; printArray ( N , arr ) ; N = 6 ; int [ ] arr1 = { - 3 , - 4 , - 2 , 5 , 1 , - 2 } ; replacedArray ( N , arr1 ) ; printArray ( N , arr1 ) ; } }


"Replace all elements by difference of sums of positive and negative numbers after that element | C # program to implement above approach ; Function to print the array elements ; Function to replace all elements with absolute difference of absolute sums of positive and negative elements ; calculate difference of both sums ; if i - th element is positive , add it to positive sum ; if i - th element is negative , add it to negative sum ; replace i - th elements with absolute difference ; Driver Code"
Solution in C#:

using System ; class GFG { static void printArray ( int N , int [ ] arr ) { for ( int i = 0 ; i < N ; i ++ ) Console . Write ( arr [ i ] + " ▁ " ) ; Console . WriteLine ( ) ; } static void replacedArray ( int N , int [ ] arr ) { int pos_sum , neg_sum , i , diff ; pos_sum = 0 ; neg_sum = 0 ; for ( i = N - 1 ; i >= 0 ; i -- ) { diff = Math . Abs ( pos_sum ) - Math . Abs ( neg_sum ) ; if ( arr [ i ] > 0 ) pos_sum += arr [ i ] ; else neg_sum += arr [ i ] ; arr [ i ] = Math . Abs ( diff ) ; } } public static void Main ( ) { int N = 5 ; int [ ] arr = { 1 , - 1 , 2 , 3 , - 2 } ; replacedArray ( N , arr ) ; printArray ( N , arr ) ; N = 6 ; int [ ] arr1 = { - 3 , - 4 , - 2 , 5 , 1 , - 2 } ; replacedArray ( N , arr1 ) ; printArray ( N , arr1 ) ; } }


"Replace all occurrences of a string with space | C # implementation to extract the secret message ; Function to extract the secret message ; Replacing all occurrences of Sub in Str by empty spaces ; Removing unwanted spaces in the start and end of the string ; Driver code"
Solution in C#:

using System ; class GFG { static string extractSecretMessage ( string Str , string Sub ) { Str = Str . Replace ( Sub , " ▁ " ) ; Str = Str . Trim ( ) ; return Str ; } public static void Main ( ) { string Str = " LIELIEILIEAMLIECOOL " ; string Sub = " LIE " ; Console . WriteLine ( extractSecretMessage ( Str , Sub ) ) ; } }


"Replace all occurrences of pi with 3.14 in a given string | C # program to replace all pi in a given string with 3.14 ; Function to replace all occurrences of pi in a given with 3.14 ; Iterate through second last element of the string ; If current and current + 1 alphabets form the word ' pi ' append 3.14 to output ; Append the current letter ; Return the output string ; Driver Code"
Solution in C#:

using System ; class gfg { public string replacePi ( string input ) { string output = " " ; int size = input . Length ; for ( int i = 0 ; i < size ; ++ i ) { if ( i + 1 < size && input [ i ] == ' p ' && input [ i + 1 ] == ' i ' ) { output += "3.14" ; i ++ ; } else { output += input [ i ] ; } } return output ; } } class geek { public static int Main ( ) { gfg g = new gfg ( ) ; string input = "2 ▁ * ▁ pi ▁ + ▁ 3 ▁ * ▁ pi ▁ = ▁ 5 ▁ * ▁ pi " ; Console . WriteLine ( g . replacePi ( input ) ) ; return 0 ; } }


"Replace all occurrences of string AB with C without using extra space | C # program to replace all occurrences of " AB " with " C " ; Start traversing from second character ; If previous character is ' A ' and current character is 'B" ; Replace previous character with ' C ' and move all subsequent characters one position back ; Driver code"
Solution in C#:

using System ; class GFG { static void translate ( char [ ] str ) { for ( int i = 1 ; i < str . Length ; i ++ ) { if ( str [ i - 1 ] == ' A ' && str [ i ] == ' B ' ) { str [ i - 1 ] = ' C ' ; int j ; for ( j = i ; j < str . Length - 1 ; j ++ ) str [ j ] = str [ j + 1 ] ; str [ j ] = ' ▁ ' ; } } return ; } public static void Main ( ) { String st = " helloABworldABGfG " ; char [ ] str = st . ToCharArray ( ) ; translate ( str ) ; Console . WriteLine ( " The ▁ modified ▁ string ▁ is ▁ : " ) ; Console . Write ( str ) ; } }


"Replace all occurrences of string AB with C without using extra space | Efficient C # program to replace all occurrences of " AB " with " C " ; Index in modified string ; Index in original string ; Traverse string ; Replace occurrence of " AB " with " C " ; Increment j by 2 ; add a null character to terminate string ; Driver code"
Solution in C#:

using System ; class GFG { static void translate ( char [ ] str ) { int len = str . Length ; if ( len < 2 ) return ; int i = 0 ; int j = 0 ; while ( j < len - 1 ) { if ( str [ j ] == ' A ' && str [ j + 1 ] == ' B ' ) { j = j + 2 ; str [ i ++ ] = ' C ' ; continue ; } str [ i ++ ] = str [ j ++ ] ; } if ( j == len - 1 ) str [ i ++ ] = str [ j ] ; str [ i ] = ' ▁ ' ; str [ len - 1 ] = ' ▁ ' ; } public static void Main ( ) { String st = " helloABworldABGfG " ; char [ ] str = st . ToCharArray ( ) ; translate ( str ) ; Console . Write ( " The ▁ modified ▁ string ▁ is ▁ : " ) ; Console . Write ( str ) ; } }


"Replace all â €˜ 0 â €™ with â €˜ 5 â €™ in an input Integer |  ; Returns the number to be added to the input to replace all zeroes with five ; Amount to be added ; Unit decimal place ; A number divisible by 10 , then this is a zero occurrence in the input ; Move one decimal place ; Driver Code"
Solution in C#:

using System ; class GFG { static int replace0with5 ( int number ) { return number += calculateAddedValue ( number ) ; } static int calculateAddedValue ( int number ) { int result = 0 ; int decimalPlace = 1 ; if ( number == 0 ) { result += ( 5 * decimalPlace ) ; } while ( number > 0 ) { if ( number % 10 == 0 ) result += ( 5 * decimalPlace ) ; number /= 10 ; decimalPlace *= 10 ; } return result ; } static public void Main ( ) { Console . WriteLine ( replace0with5 ( 1020 ) ) ; } }