| Topic | Difficulty | Companies |
|---|---|---|
| Hash Table | EASY | Amazon Microsoft |
Given a string s, write a program to find the first non-repeating character in it and return its index.
Problem Note
s, return -1.s contains only lowercase characters.Example 1
Input: s = "afteracademy"
Output: 1
Explanation: 'f' is the first non-repeating character in the string s. Hence, the output is index 1.
Example 2
Input: s = "mindorks"
Output: 0
Explanation: 'm' is the first non-repeating character in the string s. Hence, the output is index 0.
Example 3
Input: s = "abacdcd"
Output: -1
Explanation: In the string s, there is no non-repeating character. Hence, the output is -1.