First Unique Character in a String
Updated
Problem statement
Given a string s, return the first character of s that appears in s exactly once, as a string of length 1.
"First" means the character with the smallest index among all characters that appear exactly once. If no character of s appears exactly once, return an empty string "".
Function
firstUniqueChar(s: String) → StringExamples
Example 1
s = "aabbcd"return = "c"'a' and 'b' each appear twice. 'c' and 'd' each appear once, and 'c' comes first.
Example 2
s = "level"return = "v"'l' and 'e' come before 'v', but each of them appears again later in the string. 'v' at index 2 is the only character that appears once.
Example 3
s = "abcabc"return = ""Every character appears twice, so no character appears exactly once and the answer is an empty string.
Example 4
s = "z"return = "z"The only character appears once, so it is the answer.
Constraints
1 <= s.length <= 105sconsists only of lowercase English letters.
More Zillow Phone Screen questions
- Valid ParenthesesPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2025
- Build a Hash TableOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2023
- Reversible Run-Length EncodingPHONE SCREEN · Seen Nov 2022
- Cumulative Fibonacci SumOA · PHONE SCREEN · Seen Aug 2021
- First N Fibonacci NumbersOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2021
- Lowest Common Ancestor in a Binary TreePHONE SCREEN · Seen Sep 2019
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2016
- Blackjack Hand ScorePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2016
- FactorialPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2014
- Find the Four Missing Numbers in a FileOA · PHONE SCREEN · Seen Feb 2014
Similar questions at other companies
- Non-Repeating CharacterAutodesk · ONSITE INTERVIEWAutodesk interview questions
- Container Ledger with TradesFlexport · ONSITE INTERVIEWFlexport interview questions
- Branch with the Most FilesCapital One · OACapital One interview questions
- Transaction Fee Calculator — Parts 1–2: Basic Fee Calculation and Conditional Fee RulesStripe · PHONE SCREENStripe interview questions
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- Detect a Straight FlushTemu · PHONE SCREENTemu interview questions
- First Letter to Appear TwiceCisco · PHONE SCREENCisco interview questions
- Halfway Course in a Single TrackCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Count Adjacent Symbol Pairs for BPEAmazon · ONSITE INTERVIEW
- Total Each Letter's Count in an Encoded StringIBM · OAIBM interview questions