Character Frequencies in First-Appearance Order
Reported by candidates from Epic's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Epic reportedly put this one in front of candidates in September 2026, and it looks easier than it is. Count letters, ignore spaces, lowercase everything, then print them as letter:count in first-appearance order. The hinted tag says sorting, but that's the bait. It's a hash table plus insertion order problem, and the first attempt usually trips on ordering. If you've got an OA coming in the next day or two, read the trap below. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but this one is short enough to nail cold.
The problem
Count the letters in text after ignoring spaces and converting every letter to lowercase. Return one string for each distinct letter in the order of its first appearance. Format every entry as letter:count. Function orderedCharacterFrequencies(text: String) → String[] Examples Example 1 text = "Amount Characters" return = ["a:3","m:1","o:1","u:1","n:1","t:2","c:2","h:1","r:2","e:1","s:1"] The first distinct letters are a, m, o, u, n, t, c, h, r, e, and s. Example 2 text = "A b A" return = ["a:2","b:1"] Case and spaces are ignored, while a remains the first distinct letter. Constraints 1 <= text.length <= 200000 text contains English letters and spaces. text contains at least one letter.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick: don't sort anything. Walk the string once. Skip spaces, lowercase each character, and increment its count in a map. Use an insertion-ordered map, like a LinkedHashMap in Java, a regular dict in Python 3.7+, or a Map in JavaScript. Then emit letter:count for each key in order. The mistake that sinks a first attempt is sorting alphabetically, or using an unordered map in C++ or Java's HashMap and getting scrambled output. Another one is lowercasing after the first-appearance check, so 'A' and 'a' get treated as different letters. With length up to 200000, O(n) is the target, and a 26-slot array plus an order list works too. If you freeze on the live OA, StealthCoder can hand you the clean version fast, but you really just need one pass and an ordered structure.
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 Character Frequencies in First-Appearance Order 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
You've seen the question.
Make sure you actually pass Epic's OA.
Epic 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.
Character Frequencies in First-Appearance Order FAQ
What's the actual trick in the Epic character frequency problem?+
Preserve first-appearance order without sorting. Use an insertion-ordered map, or a 26-element count array plus a list that records each letter the first time you see it. One pass, then build the output strings from that order.
Is this a sorting problem since it's tagged that way?+
No. Sorting would break the required order, since output follows first appearance and not alphabet order. The real work is counting with a hash map or array and remembering insertion order. Treat the sorting hint as a distraction.
What mistakes should I avoid on this one?+
Three common ones: counting spaces, forgetting to lowercase before the lookup so 'A' and 'a' split, and using an unordered map so the output order is random. Check Example 2, 'A b A', to confirm your case handling.
How fast does the solution need to be?+
The text can reach 200000 characters, so you want O(n) time. A single pass with a map or 26-slot array does it easily. Avoid repeated string searches or re-scanning for each letter, which pushes you toward O(n^2).
How do I prepare for this in 48 hours?+
Practice two or three frequency-count problems where order matters, and learn your language's ordered map. Write this one from scratch once, including the letter:count formatting. It's a 10-minute problem once you know to skip the sort.