FastPrepEarliest Unrepeated Letter in a Stream
Problems/Earliest Unrepeated Letter in a Stream

Earliest Unrepeated Letter in a Stream

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: This problem reports, after each letter of an incoming sequence, the earliest letter that has so far shown up exactly once, or # when there is none. An Adobe Computer Scientist 2 report gives this as the first of two questions in its first round, with one worked sequence of seven characters and its seven answers; it gives no limits, character set or return type.

Our choices: lowercase letters only, the input as one string and the answers returned as one string of the same length, at most 5000 letters, and new examples.

The judged task matches the report at about 90%.

Letters arrive one at a time; stream lists them in arrival order. After each letter arrives, report the earliest-arrived letter that has so far appeared exactly once, or # if every letter seen so far has appeared at least twice.

Return a string of the same length as stream whose i-th character is the report after the first i + 1 letters. A letter that repeats never counts again, even if it appears a third time.

Function

firstUniqueSoFar(stream: String) → String

Examples

Example 1

stream = "abacbd"return = "aabbcc"

After a: a. After ab: still a. The second a leaves b as the earliest single letter. Adding c keeps b. The second b leaves only c. Adding d keeps c. So the answer is "aabbcc".

Example 2

stream = "mmm"return = "m##"

After the first m it is the answer. After two or three ms no letter has appeared exactly once, so both positions get #.

Example 3

stream = "qrsrq"return = "qqqqs"

q stays the answer while r and s arrive and r repeats. When q repeats at the end, s is the only letter seen once.

Constraints

  • 1 <= stream.length <= 5000
  • stream contains only lowercase English letters a to z

More Adobe problems

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
All Adobe interview questionsSee Adobe hiring insights
Saved
public String firstUniqueSoFar(String stream) {
    // Write your code here.
}
Checking account…