FastPrepEarliest Letter With a Single Appearance

Earliest Letter With a Single Appearance

Capital One logoCapital One● EasyNEW GRADFULLTIMEONSITE INTERVIEW

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) → String

Examples

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^5
  • s contains only lowercase English letters.

More Capital One Onsite Interview questions

Similar questions at other companies

Capital One interview experiences

All Capital One interview questionsSee Capital One hiring insights
Saved
class Solution {
    public String firstUnique(String s) {
        // Write your code here.
    }
}
Checking account…