Data Structures · Assignment

Problem 1: First Non-Repeating Character — Using a Hash Table

Count frequencies with a hash table → pass 1 counts, pass 2 finds the first character that occurs once

📥 Input string s

character being processed already counted in pass 1 hit: the first non-repeating character

🔢 Hash table = counting array int count[26] index = letter − 'a'

letter not seen (count = 0) seen count +1 happening / being checked count = 1 → candidate

💬 Current step

💻 C++ program (two passes)

Yellow = current line. Pass 1 counts how often each letter occurs, then pass 2 scans left to right for the first count == 1.

💡 The idea the problem asks for a hash table

Why two passes? In one pass you cannot know whether a character repeats later → count everything first, then search.
● Hash: only 26 letters → use array count[26]; index c − 'a' is the "hash address" (O(1) read/write). More generally you may use map<char,int>.
● Pass 1: for each character count[c − 'a']++.
● Pass 2: scan again in the original order; output the first count == 1 and stop. If none qualifies → print None.
Speed
Shortcuts: Space play/pause · ←→ step · R reset · E result