Lexicographically largest string with sum of characters equal to N | Function to construct the lexicographically largest string having sum of characters as N ; Stores the resulting string ; Iterate until N is at least 26 ; Append ' z ' to the string ans ; Decrement N by 26 ; Append character at index ( N + ' a ' ) ; Return the resultant string ; Driver Code
function getString ( N ) { let ans = " " while ( N >= 26 ) { ans += ' ' N -= 26 } ans += String . fromCharCode ( N + ' ' . charCodeAt ( 0 ) - 1 ) return ans } let N = 30 document . write ( getString ( N ) )