Split a Log Outside Quotes
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt at this Google OA, reported in July 2026, is reaching for log.split(" "). It shreds quoted fields and spits out empty tokens. This is "Split a Log Outside Quotes", a single-pass string parsing problem on a log up to 200000 characters. Spaces split tokens only outside double quotes, quotes get dropped, and a quoted empty string still counts as a token. It looks easy, and that's the trap. If you blank on the edge cases mid-assessment, StealthCoder runs invisibly as a safety net and hands you the state machine. Read this first and you probably won't need it.
The problem
Given a printable-ASCII logging string log, split it on ASCII space characters that occur outside double-quoted regions. Spaces inside a balanced pair of double quotes belong to the current token. Quote characters group content and are omitted from returned tokens. There are no escape sequences, and all double quotes are balanced. Leading, trailing, or consecutive spaces outside quotes do not create empty tokens. A quoted empty string "" does create one empty token. Return the tokens in encounter order. Function splitLog(log: String) → String[] Examples Example 1 log = "level info \"request completed\" code 200" return = ["level","info","request completed","code","200"] The space inside "request completed" is retained, while the other spaces delimit tokens. Example 2 log = " a \"b c\" \"\" d " return = ["a","b c","","d"] Repeated unquoted spaces are ignored, while the explicitly quoted empty field is preserved. Constraints 0 <= log.length <= 200000 log contains printable ASCII characters. Double quotes occur in balanced pairs. Escape sequences are outside the scope of this exercise.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is a linear scan with two pieces of state: an inQuotes boolean and a current token buffer. Add a third flag, hasToken, because a quoted empty string must produce an empty token while stray spaces must not. Walk each character. On a quote, flip inQuotes and set hasToken to true, without appending the quote. On a space outside quotes, if hasToken is true, push the buffer, then reset both. Otherwise append the character and set hasToken. After the loop, flush if hasToken is true. The common pitfall is deciding to emit by checking buffer length, which silently drops "". Another is forgetting the trailing flush. Use a list of characters or a StringBuilder, not repeated string concatenation, with 200000 characters. Time is O(n), space is O(n). If your head goes blank during the live OA, StealthCoder is the hedge that surfaces this exact flag logic.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Split a Log Outside Quotes 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 StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Google's OA.
Google 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.
Split a Log Outside Quotes FAQ
What's the trick in Split a Log Outside Quotes?+
Track whether you're inside quotes and whether a token has started. The second flag is what lets a quoted empty string "" produce an empty token while repeated unquoted spaces produce nothing. Scan once, flip state on quotes, and flush on unquoted spaces.
Why can't I just use split on spaces?+
Splitting on spaces breaks quoted fields like "request completed" into two pieces and creates empty strings from consecutive spaces. You'd need to repair that afterward, which is messier than a single pass state machine. Write the scan directly.
How do I handle the empty quoted string case?+
Don't decide whether to emit based on buffer length. Set a hasToken flag when you see an opening quote, and emit when you hit an unquoted space or the end of the input if the flag is set. That keeps "" as one empty token.
How hard is this one really?+
Easy on algorithm, medium on care. There's no fancy data structure. It's O(n) with a couple of booleans. Most failures come from edge cases: leading or trailing spaces, an empty input string, a quoted empty field, and a missing final flush.
How do I prepare for this in 48 hours?+
Write the scanner from scratch twice and test it on both examples, an empty string, all spaces, and adjacent quoted fields like "a""b". Then do a few similar tokenizer problems. Pattern recognition for flag-based parsing matters more than volume here.