text: Lexicographically smallest string of maximum length made up of first K alphabets that does not contain any repeating substring | Function to find the lexicographically smallest string of the first K lower case alphabets having unique substrings ; Stores the resultant string ; Iterate through all the characters ; Inner Loop for making pairs and adding them into string ; Adding first character so that substring consisting of the last the first alphabet is present ; Print the resultant string ; Driver code
code: function generateString ( K ) { var s = " " ; for ( var i = 97 ; i < 97 + K ; i ++ ) { s = s + String . fromCharCode ( i ) ; for ( var j = i + 1 ; j < 97 + K ; j ++ ) { s += String . fromCharCode ( i ) ; s += String . fromCharCode ( j ) ; } } s += String . fromCharCode ( 97 ) ; document . write ( s ) ; } var K = 4 ; generateString ( K ) ;