Given a string str, the task is to find the last non-repeating character in it.
For example, if the input string is “GeeksForGeeks”, then the output should be ‘r’ and if input string is “GeeksQuiz” then the output should be ‘z’. if there is no non-repeating character then print -1.
Input: str = “GeeksForGeeks”
‘r’ is the first character from the end which has frequency 1.
Input: str = “aabbcc”
All the characters of the given string have frequencies greater than 1.
Approach: Create a frequency array which will store the frequency of each of the character of the given string. Once the frequencies have been updated, start traversing the string from the end character by character and for every character, if the frequency of the current character is 1 then this is the last non-repeating character. If all the characters have frequency greater than 1 then print -1.
Below is the implementation of the above approach:
- Given a string, find its first non-repeating character
- Queries to find the first non-repeating character in the sub-string of a string
- Queries to find the last non-repeating character in the sub-string of a given string
- First non-repeating character using one traversal of string | Set 2
- Maximum consecutive repeating character in string
- Encrypt a string by repeating i-th character i times
- Decrypt a string encrypted by repeating i-th character i times
- Find the first non-repeating character from a stream of characters
- Find a string such that every character is lexicographically greater than its immediate next character
- Find the character in first string that is present at minimum index in second string
- K'th Non-repeating Character
- Find k-th character of decrypted string | Set - 2
- Find last index of a character in a string
- Find the first repeated character in a string
- Find one extra character in a string
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.