Modify given string such that odd and even indices is lexicographically largest and smallest | C # program for the above approach ; Function to modify the given string satisfying the given criteria ; Traverse the string S ; If i is even ; If the S [ i ] is ' a ' , then change S [ i ] to ' b ' ; Otherwise , change S [ i ] to ' a ' ; If S [ i ] is ' z ' , then change S [ i ] to ' y ' ; Otherwise , change S [ i ] to ' z ' ; Return the result ; Driver Code
using System ; using System . Collections . Generic ; class GFG { static string performOperation ( string S , int N ) { for ( int i = 0 ; i < N ; i ++ ) { if ( i % 2 == 0 ) { if ( S [ i ] == ' a ' ) { S = S . Substring ( 0 , i ) + ' b ' + S . Substring ( i + 1 ) ; } else { S = S . Substring ( 0 , i ) + ' a ' + S . Substring ( i + 1 ) ; } } else { if ( S [ i ] == ' z ' ) { S = S . Substring ( 0 , i ) + ' y ' + S . Substring ( i + 1 ) ; } else { S = S . Substring ( 0 , i ) + ' z ' + S . Substring ( i + 1 ) ; } } } return S ; } public static void Main ( ) { string S = " giad " ; int N = S . Length ; Console . Write ( performOperation ( S , N ) ) ; } }