Given a string s, write a program to find the first non-repeating character in it and return its index.

Problem Note

  • The string index starts from 0.
  • If there is no non-repeating character in the string s, return -1.
  • You may assume the string 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.