Lexicographically largest string possible by at most K replacements | C # implementation of the above approach ; Traverse each element of the string ; If the current character can be replaced with ' z ' ; Return the modified string ; Driver code
using System ; using System . Collections . Generic ; class GFG { static string largestString ( string s , int k ) { for ( int i = 0 ; i < s . Length ; i ++ ) { if ( s [ i ] != ' z ' && k > 0 ) { s = s . Replace ( s [ i ] , ' z ' ) ; k -- ; } } return s ; } public static void Main ( ) { string s = " dbza " ; int k = 1 ; Console . Write ( largestString ( s , k ) ) ; } }