First Non-Repeating Character
Reported by candidates from Goldman Sachs's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
This Goldman Sachs OA, reported in October 2026, looks like a string problem, but it really reduces to counting. You tally how often each letter shows up, then walk the string again and return the first one with a count of 1. That's it. The trap is overthinking it or reaching for nested loops on a 10^5 length input. If you've got the invite and 48 hours, this is one you want cold. StealthCoder sits invisible as a safety net during the live OA if you blank on the two-pass idea, but you shouldn't need it here.
The problem
Given a non-empty string text containing lowercase English letters, return its first character that occurs exactly once. The first character is determined by its position in text, not by alphabetical order. If every character repeats, return the empty string "". Function firstNonRepeatingCharacter(text: String) → String Examples Example 1 text = "swiss" return = "w" The letter s repeats. The next character, w, occurs once, so it is the first non-repeating character. Example 2 text = "aabbc" return = "c" Both a and b occur twice, while c occurs once. Example 3 text = "aabb" return = "" No character occurs exactly once, so the result is the empty string. Constraints 1 <= text.length <= 10^5 text contains only lowercase English letters.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is two passes. Pass one builds a frequency map of the lowercase letters. Because the alphabet is only 26 characters, a fixed array of size 26 works and keeps space constant. Pass two scans the original string left to right and returns the first character whose count equals 1. Scanning the string, not the map, is what preserves position order. The common pitfall is iterating the counts alphabetically, which returns the wrong answer for "swiss" (you'd pick "w" only by luck). Another miss is the all-repeating case: return an empty string, not null or a space. The nested loop approach is O(n^2) and risks timing out at 10^5. The two-pass approach is O(n) time. If you freeze mid-assessment, StealthCoder is the hedge that surfaces this pattern in real time, but the logic is short enough to memorize tonight.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
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. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as first unique character in a string. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Goldman Sachs's OA.
Goldman Sachs reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
First Non-Repeating Character FAQ
How hard is the Goldman Sachs First Non-Repeating Character question really?+
It's easy. The whole solution is a frequency count plus a second scan. The only real difficulty is staying calm and not overcomplicating it. If you can write a hash map or a 26-slot array, you can finish this in a few minutes.
What's the trick to solving it efficiently?+
Count first, then scan in original order. Build counts for each letter, then loop through the string from index 0 and return the first character with count 1. This is O(n) time and O(1) space since the alphabet is fixed at 26 letters.
Why can't I just loop through my frequency map?+
Because the problem wants the first character by position in the text, not alphabetical or insertion-dependent order. Iterating the array of 26 counts returns letters in alphabetical order, which gives wrong answers. Always do the second pass over the original string.
What should I return when every character repeats?+
Return the empty string "". The problem states this explicitly for inputs like "aabb". Don't return null, a space, or a sentinel character. Test this case before submitting since it's an easy edge to miss.
How do I prepare for this in 48 hours?+
Write the two-pass solution from scratch in your language twice. Then try a single-pass variant using a map of first indices as a bonus. Test on "swiss", "aabbc", and "aabb". Also practice a few other counting and hash map string problems so the pattern feels automatic.