Earliest Letter With a Single Appearance
Updated
Problem statement
In the lowercase string s, some letters occur only once and others occur several times. Among the letters that occur only once, give back the one nearest the start of s, written as a string of length one.
When no letter is single, return "", the string with no characters.
Function
firstUnique(s: String) → StringExamples
Example 1
s = "sweets"return = "w"s appears twice and e twice. w is the first letter that appears just once.
Example 2
s = "abcabc"return = ""a, b and c each show up two times, so there is no single-appearance letter to return and the result is the empty string.
Example 3
s = "teetered"return = "r"t appears twice, e four times, and r and d once each. Reading from the left, r comes before d, so r is the first letter with a count of one.
Constraints
1 <= s.length <= 10^5scontains only lowercase English letters.
More Capital One Onsite Interview questions
- Digit-Coded Card ValidationONSITE INTERVIEW · Seen Nov 2026
- Sort ColorsONSITE INTERVIEW · Seen Oct 2026
- Virtual Card Transaction ValidatorONSITE INTERVIEW · Seen Oct 2026
- Banking System with Top ActivityONSITE INTERVIEW · Seen Sep 2026
- Transaction Event StoreONSITE INTERVIEW · Seen Jul 2026
- Shortest Path in an Unweighted GraphONSITE INTERVIEW · Seen Jul 2026
- Duplicate Transactions Within 60 SecondsONSITE INTERVIEW · Seen May 2026
- LRU CachePHONE SCREEN · ONSITE INTERVIEW · Seen May 2026
- Cashback TrackerONSITE INTERVIEW · Seen Nov 2025
- Reverse a StringOA · ONSITE INTERVIEW · Seen Oct 2025
Similar questions at other companies
- Count Adjacent Symbol Pairs for BPEAmazon · ONSITE INTERVIEW
- Count a User's Actions in an Event LogMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
- Filter Pins by Excluded IDsPinterest · ONSITE INTERVIEWPinterest interview questions
- First Non-Repeating CharacterGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
- Longest Dictionary Word from Nine LettersGoogle · ONSITE INTERVIEWGoogle interview questions
- Minimum Replacements to Make Two Strings AnagramsBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Logger Rate LimiterAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
- Isomorphic StringsRemitly · ONSITE INTERVIEWRemitly interview questions
- Check AnagramsDeloitte · ONSITE INTERVIEWDeloitte interview questions
Capital One interview experiences
- Capital One Coding OA Questions: 3 Experiences
- Capital One Experienced Engineer Power Day and OA: 6 Experiences
- Capital One New Grad OA Questions: 14 Experiences (Part 2 of 2)
- Capital One TDP Agentic Round (AI Coding): 7 Experiences
- Capital One SWE Power Day, Level Not Reported: 6 Experiences
- Capital One TIP Intern OA and Power Day: 13 Experiences