FastPrepSplit a String by a Delimiter
Problems/Split a String by a Delimiter

Split a String by a Delimiter

Microsoft logoMicrosoft● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Writing your own string split was the task in one interview of a Microsoft software engineering internship process, according to a review. The delimiter could be a single character, a longer substring, or a regular expression.

The review gives no examples, no rule for empty pieces and no limits. Here the delimiter is a character or substring taken literally, matches are found from the left without overlapping, every piece is kept even when empty (including at the start and end), and you return the list of pieces. Splitting by a regular expression is a follow-up and is not tested. The tests also cannot check the rule against using a built-in split.

Our version is about 70% the same as the reported question.

Implement your own string split. Given a string s and a non-empty string delimiter, cut s at every place where delimiter appears and return the pieces in order.

  • The delimiter is taken literally, character for character. Characters such as | and . have no special meaning.
  • Matches are found from the left and never overlap: after a match, the search continues right after it.
  • Keep every piece, including empty ones: two delimiters next to each other, or a delimiter at the start or end of s, produce empty pieces.
  • If the delimiter never appears, the answer is [s]. An empty s gives [""].

Do not use your language's built-in split function.

Follow-up: how would you extend your function so the delimiter can also be a regular expression?

Function

splitString(s: String, delimiter: String) → String[]

Examples

Example 1

s = "red,green,,blue"delimiter = ","return = ["red","green","","blue"]

There are three commas. Cutting at each one gives red, green, an empty piece (between the two commas next to each other), and blue.

Example 2

s = "a--b--c"delimiter = "--"return = ["a","b","c"]

The delimiter is the two-character substring --. It appears twice, giving three pieces.

Example 3

s = "aaa"delimiter = "aa"return = ["","a"]

Matches are found from the left and do not overlap: aa at index 0 is a delimiter, and the remaining a is too short for another match. So the pieces are the empty string before the match and a after it.

Constraints

  • 0 <= s.length <= 10^4
  • 1 <= delimiter.length <= 100
  • s and delimiter consist of lowercase English letters, digits, spaces, and the characters , ; : | . -

More Microsoft Onsite Interview questions

  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
  • Totals from a Tiered Rate TableONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Rich Text Parser Part 1 (Validate Tokens)Figma · PHONE SCREEN · ONSITE INTERVIEWFigma interview questions
  • Message Latencies from CSV LogsAmazon · ONSITE INTERVIEW
  • URL / Path Segment Compression Part 1Stripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
  • Most Cost-Effective MachineCapital One · ONSITE INTERVIEWCapital One interview questions
  • Word Appears Exactly N TimesNutanix · ONSITE INTERVIEWNutanix interview questions
  • Single-Pass S-Expression ParserBaseten · ONSITE INTERVIEWBaseten interview questions
  • Flatten a Mixed JSON ListNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
  • Transform Dotted Keys into a Nested MapProofpoint · ONSITE INTERVIEW
  • Serialize and Deserialize a String Key-Value StoreByteDance · ONSITE INTERVIEWByteDance interview questions
  • Molecular Weight of a Grouped FormulaAgoda · ONSITE INTERVIEWAgoda interview questions

Interview reports that mention this question

  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public String[] splitString(String s, String delimiter) {
        // Write your code here.
    }
}
Checking account…