Loading section...
First Unique Character: When Order Matters
Concepts: pyFirstUnique, pyOrderedDict, pyTwoPass
First non-repeating character (LeetCode 387) looks like a trivial frequency problem, but it has an interesting wrinkle: you need the FIRST unique character, not just any unique character. This means order matters. And order mattering in a dict context is where candidates who do not know Python's memory model make mistakes. There are two clean approaches: two-pass with a plain dict, and one-pass with an OrderedDict. Knowing both and the tradeoff between them shows the interviewer you think about data structure semantics, not just correctness. Two-Pass Approach: Clean and Clear The two-pass approach is the right answer for most interviews. It is O(n) time, O(1) space (alphabet is bounded), clean, and easy to explain. Say: 'I make two passes. First pass builds a frequency map. Second pass wal