Recall & Review
beginner
What is the purpose of using a hash (dictionary) in finding the first non-repeating character?
A hash (dictionary) stores the count of each character in the string, allowing quick lookup to identify characters that appear only once.
Click to reveal answer
beginner
How do you identify the first non-repeating character after counting frequencies?
By scanning the string from left to right and checking the count of each character in the hash, the first character with count 1 is the first non-repeating character.
Click to reveal answer
intermediate
Why is the time complexity of this approach O(n)?
Because we traverse the string twice: once to count characters and once to find the first non-repeating character, each operation is O(n), so total is O(n).
Click to reveal answer
beginner
What happens if all characters repeat in the string?
If all characters repeat, the function returns a special value (like -1 or None) indicating no non-repeating character exists.
Click to reveal answer
beginner
Show the Python code snippet to count characters using a dictionary.
counts = {}
for ch in s:
counts[ch] = counts.get(ch, 0) + 1
Click to reveal answer
What data structure is best to count character frequencies for this problem?
✗ Incorrect
A hash (dictionary) allows fast counting and lookup of character frequencies.
What is the first step in finding the first non-repeating character?
✗ Incorrect
Counting frequencies helps identify which characters appear only once.
If the string is 'aabbcc', what should the function return?
✗ Incorrect
All characters repeat, so no non-repeating character exists.
What is the time complexity of this approach?
✗ Incorrect
Two passes over the string make the time complexity linear, O(n).
Which of these is NOT required to find the first non-repeating character?
✗ Incorrect
Sorting is not needed; it changes the order and is unnecessary.
Explain how to find the first non-repeating character in a string using a hash.
Think about counting first, then scanning.
You got /4 concepts.
Describe the time complexity and why this method is efficient.
Focus on number of traversals and hash operations.
You got /4 concepts.