This problem is one of the competitive questions dealing with strings, so as indicated by the title we need to find first unique i.e non-repeating character in a given string and return the index or else if no such character exists we return -1.
Note: We are considering only lowercase, if asked with uppercase or camelcase full string can be converted to lowercase.
Example :
Input : opengenus
Output : 0
# unique character ' O ' at position zero
Input : hellhell
Output : -1
# no unique character...
Published on June 16, 2020 06:06