Return the First Non-Repeating Character
Company: Goldman Sachs
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Overview: Return the first character whose total frequency is one, preserving input order and defining the result when every character repeats.
Constraints
- s is an ASCII string with character codes 0 through 127.
- 0 <= s.length <= 100000.
- Comparison is case-sensitive. Whitespace, punctuation and ASCII control characters count as ordinary characters.
- Return the first globally unique character in original order, as a one-character string; return an empty string if none exists.
Examples
Input: ('swiss',)
Expected Output: 'w'
Explanation: Published sample 1: s repeats; w is the earliest globally unique character.
Input: ('aabb',)
Expected Output: ''
Explanation: Published sample 2: every character repeats.