Problem 208161 · easy · Phase 02 Linear Data Structures

First Letter That Never Repeats

strings · counting · dicts

Write first_unique(s) that returns the first character of s that appears exactly once in the whole string. Return "" if every character repeats or the string is empty. Comparison is case-sensitive, and every character counts (spaces and punctuation included).

Examples

Input:  s = "swiss"
Output: "w"

Input:  s = "aabb"
Output: ""

Input:  s = "programming"
Output: "p"

Constraints

  • 0 <= len(s) <= 10**5, printable ASCII
  • Target: O(n) time

Goals

  • Count frequencies in one pass
  • Make a second pass in original order
  • Return a sentinel when nothing qualifies
Starting Python…