Reported September 2026
Amazonhash table

First Non-Repeating Character

Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Amazon OA. Under 2s to a working solution.
Founder's read

The mistake that sinks a first attempt at this Amazon question is checking each character against the rest of the string. It looks fine on "swiss" and dies on a 100000-character input. Amazon candidates reported First Non-Repeating Character in September 2026, and it's a counting problem in disguise. Count every character, then scan the string in its original order and return the first one with a count of one. That's the whole job. If your head goes blank on the live OA, StealthCoder is the silent safety net running invisibly on your desktop, but you shouldn't need it for this one.

The problem

Given a non-empty string s, return the first character whose total frequency in the string is exactly one.
If no such character exists, return the empty string. Character comparisons are case-sensitive.

Function
firstNonRepeating(s: String) → String

Examples
Example 1
s = "swiss"
return = "w"
The first s repeats, while w occurs once.
Example 2
s = "aabbc"
return = "c"
Only c has frequency one.
Example 3
s = "aabb"
return = ""
Every character repeats, so the result is empty.

Constraints
1 ≤ s.length ≤ 100000.
s contains printable ASCII characters.

Reported by candidates. Source: FastPrep

Pattern and pitfall

The trick is two passes. Pass one builds a frequency map, either a hash map or a 128-slot array since the input is printable ASCII. Pass two walks the string left to right and returns the first character whose count equals one. Order comes from the string, not the map, and that's where people slip. Iterating the map and returning its first singleton gives you the wrong answer when map order differs from string order. The other pitfall is the O(n^2) approach of calling a count or indexOf per character, which is too slow at 100000. Remember the return type is a string, so the no-match case returns "" and not null or a space. Case matters, so 'a' and 'A' are different keys. Total cost is O(n) time and O(1) space. If you freeze during the live Amazon OA, StealthCoder can surface this exact two-pass solution while you keep typing.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill First Non-Repeating Character cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as first unique character in a string. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Amazon's OA.

Amazon reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

First Non-Repeating Character FAQ

How hard is First Non-Repeating Character really?+

It's easy. Once you see it as a frequency count plus an ordered scan, it's about ten lines. The only difficulty is avoiding the nested-loop instinct, which times out at 100000 characters. Most candidates who fail it fail on efficiency or return the wrong type.

What's the trick to solving it fast?+

Count first, then scan the original string in order. Use a hash map or a 128-length array for printable ASCII. The first character in the string whose count is exactly one is your answer. Don't iterate the map for the result, because map order isn't string order.

What should I return when every character repeats?+

Return the empty string, as in the aabb example. Not null, not a space, not a sentinel character. The function signature returns a String, so a single-character string on success and "" on failure keeps the types consistent.

Do I need to worry about case or special characters?+

Comparisons are case-sensitive, so 'a' and 'A' count separately. The input is printable ASCII, so a fixed array of 128 slots works and avoids hashing overhead. Don't lowercase the string or you'll break correctness on mixed-case inputs.

How do I prepare for this in 48 hours?+

Write the two-pass solution from memory twice, once with a hash map and once with an array. Then test it on swiss, aabbc, aabb, and a single-character string. Also practice similar counting problems like anagram checks so the frequency-map pattern becomes automatic.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Amazon.

OA at Amazon?
Invisible during screen share
Get it