Generate a string with maximum possible alphabets with odd frequencies | Function to generate a string of length n with maximum possible alphabets each occuring odd number of times . ; If n is odd ; Add all characters from b - y ; Append a to fill the remaining length ; If n is even ; Add all characters from b - z ; Append a to fill the remaining length ; Driven code
function generateTheString ( n ) { var ans = " " ; if ( n % 2 ) { for ( var i = 0 ; i < min ( n , 24 ) ; i ++ ) { ans += ( char ) ( ' ' + i ) ; } if ( n > 24 ) { for ( var i = 0 ; i < ( n - 24 ) ; i ++ ) ans += ' ' ; } } else { for ( var i = 0 ; i < Math . min ( n , 25 ) ; i ++ ) { ans += String . fromCharCode ( ' ' . charCodeAt ( 0 ) + i ) ; } if ( n > 25 ) { for ( var i = 0 ; i < ( n - 25 ) ; i ++ ) ans += ' ' ; } } return ans ; } var n = 34 ; document . write ( generateTheString ( n ) ) ;