Find the last non repeating character in string | Maximum distinct characters possible ; Function to return the last non - repeating character ; To store the frequency of each of the character of the given string ; Update the frequencies ; Starting from the last character ; Current character ; If frequency of the current character is 1 then return the character ; All the characters of the string are repeating ; Driver code
let MAX = 256 ; function lastNonRepeating ( str , n ) { let freq = new Array ( MAX ) ; for ( let i = 0 ; i < MAX ; i ++ ) { freq [ i ] = 0 ; } for ( let i = 0 ; i < n ; i ++ ) freq [ str [ i ] . charCodeAt ( 0 ) ] ++ ; for ( let i = n - 1 ; i >= 0 ; i -- ) { let ch = str [ i ] ; if ( freq [ ch . charCodeAt ( 0 ) ] == 1 ) return ( " " + ch ) ; } return " " ; } let str = " " ; let n = str . length ; document . write ( lastNonRepeating ( str , n ) ) ;