Did the two-pass approach: first loop to count frequencies, second loop to find the first count-1 character.
Start by clarifying the problem: define 'first' as the earliest index in the string, and 'doesn't repeat' as occurring exactly once. Then propose an efficient solution using a hash map to count character frequencies in one pass, followed by a second pass to find the first character with count 1. Discuss time and space complexity, and consider edge cases like empty strings or all repeating characters.
Pro tip: Mention that you can optimize to a single pass by storing both the count and the first index of each character, then after processing, find the minimum index among characters with count 1. This shows you think about efficiency and trade-offs.
Confirm that 'first' means smallest index, and 'doesn't repeat' means appears exactly once. Ask about input constraints (e.g., ASCII vs Unicode, string length) and handle edge cases like empty string or no unique character.
Select a hash map (dictionary) to count character frequencies. Explain that this allows O(1) average-time lookups and updates, making the overall solution O(n) time.
First pass: iterate through the string and populate the frequency map. Second pass: iterate again and return the index of the first character with frequency 1. If none, return -1.
State that time complexity is O(n) and space complexity is O(k) where k is the number of unique characters (bounded by alphabet size). Mention that a single-pass approach storing first indices is possible but may use more space.
Walk through examples like 'leetcode' (returns 0 for 'l'), 'loveleetcode' (returns 2 for 'v'), and 'aabb' (returns -1) to verify correctness.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.