Final string after performing given operations | C # implementation of the approach ; Function to return the modified String ; Count number of ' x ' ; } Count number of ' y ' ; min ( x , y ) number of ' x ' and ' y ' will be deleted ; Driver Code
using System ; class GFG { static string printFinalString ( string s ) { int i , n ; n = s . Length ; int x = 0 , y = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( s [ i ] == ' x ' ) { x ++ ; else { y ++ ; } } string finalString = " " ; if ( x > y ) { for ( i = 0 ; i < x - y ; i ++ ) { finalString += " x " ; } } else { for ( i = 0 ; i < y - x ; i ++ ) { finalString += " y " ; } } return finalString ; } public static void Main ( ) { string s = " xxyyxyy " ; Console . WriteLine ( printFinalString ( s ) ) ; } }