Find the last non repeating character in string | C # implementation of the approach ; 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
using System ; class GFG { static readonly int MAX = 256 ; static String lastNonRepeating ( String str , int n ) { int [ ] freq = new int [ MAX ] ; for ( int i = 0 ; i < n ; i ++ ) freq [ str [ i ] ] ++ ; for ( int i = n - 1 ; i >= 0 ; i -- ) { char ch = str [ i ] ; if ( freq [ ch ] == 1 ) return ( " " + ch ) ; } return " - 1" ; } public static void Main ( String [ ] args ) { String str = " GeeksForGeeks " ; int n = str . Length ; Console . WriteLine ( lastNonRepeating ( str , n ) ) ; } }