FastPrepSplit a Log Outside Quotes
Problems/Split a Log Outside Quotes

Split a Log Outside Quotes

Google logoGoogle● MediumFULLTIMEONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source omits quote-edge conventions and a callable interface. The judged core task matches the visible source at about 92%.

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.

More Google problems

  • Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
  • Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public String[] splitLog(String log) {
        // Write your code here
    }
}
Checking account…