Given a string, this algorithm will find the first non-repeating character in the string and return its index. If no such character exists, it will return -1.
The candidate's solution is a good one. It uses a hash table to store the characters and their indices, and then iterates through the string to check if each character is in the hash table. If it is, then the character is a repeating character. If it is not, then the character is a non-repeating character. The candidate then returns the index of the first non-repeating character. This solution is optimal because it is O(n) time complexity and O(n) space complexity.
Evaluated at: 2022-11-21 08:16:13