Count and Say
Reported by candidates from Bloomberg's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The data structure here is almost embarrassingly simple: a string you rebuild n-1 times. Bloomberg reported Count and Say in December 2020, and it's the kind of OA question that looks like a puzzle but is really a run-length encoding loop. You read the previous term, group equal digits, and write count then digit. n tops out at 30, so nothing fancy is needed. The risk isn't difficulty, it's a sloppy off-by-one on the last run when your mind goes blank. If that happens mid-assessment, StealthCoder sits invisibly on your screen as a safety net.
The problem
The count-and-say sequence begins with countAndSay(1) = "1". Each later term describes the maximal equal-digit runs of the previous term as count followed by digit. Return the n-th term. Function countAndSay(n: int) → String Examples Example 1 n = 1 return = "1" The first term is defined as 1. Example 2 n = 4 return = "1211" Term 3 is 21, which is read as one 2 and one 1. Constraints 1 <= n <= 30.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is to stop treating it as a sequence puzzle and treat it as run-length encoding applied repeatedly. Start with "1". For each step from 2 to n, scan the current string with an index or two pointers, count how many times the current digit repeats, then append the count and the digit to a list of characters. Join it into the next term. The classic pitfall is forgetting to flush the final run after the loop ends, or comparing against index i+1 without a bounds check. Another one is using string concatenation in a tight loop instead of a builder, which is fine at n=30 but sloppy. Time is proportional to the total length of all generated terms. If you freeze on the run-flush logic during the live OA, StealthCoder is the hedge that gives you the clean loop instantly.
If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.
You can drill Count and Say 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 would have shipped this the night before his JPMorgan OA if he'd had it.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as count and say. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Bloomberg's OA.
Bloomberg reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Count and Say FAQ
How hard is Count and Say really?+
It's easy on paper. There's no clever algorithm, just careful iteration. Most people stumble on understanding the statement, not the code. Read Example 2 twice: term 3 is 21, read as one 2 and one 1, giving 1211. Once that clicks, it's about ten lines.
What's the trick to solving it?+
Run-length encoding in a loop. Start at "1", and for each term walk the string, count consecutive equal digits, and append count then digit. Build the next term in a list, then join. Do that n-1 times and return the result.
What's the most common bug?+
Missing the last run. If you only emit a group when the next digit differs, the final group never gets written unless you handle it after the loop. The other bug is reading past the end of the string when comparing neighbors.
Should I use recursion or iteration?+
Either works with n up to 30, but iteration is cleaner and avoids stack worries. Recursion just calls countAndSay(n-1) and encodes the result. Pick whichever you can write without second-guessing. Iteration is usually the safer pick under time pressure.
How do I prepare for this in 48 hours?+
Hand-trace terms 1 through 5 until the pattern is automatic: 1, 11, 21, 1211, 111221. Then write the run-counting loop from memory twice. Also do a couple of similar string-compression problems so the two-pointer grouping feels routine.