Split Strings by Separator

Given an array of strings words and a character separator, split each string in words by separator.

Return an array of strings containing the new strings formed after the splits, excluding empty strings.

Notes

  • separator is used to determine where the split should occur, but it is not included as part of the resulting strings.
  • A split may result in more than two strings.
  • The resulting strings must maintain the same order as they were initially given.
Example 1
Inputwords = ["one.two.three","four.five","six"], separator = "."
Output["one","two","three","four","five","six"]
Splitting each word by . produces one, two, three, four, five, and six in order.
Example 2
Inputwords = ["$easy$","$problem$"], separator = "$"
Output["easy","problem"]
Splitting by $ produces easy and problem, excluding the empty strings from leading and trailing separators.

Constraints

  • 1 <= words.length <= 100
  • 1 <= words[i].length <= 20
  • characters in words[i] are either lowercase English letters or characters from the string ".,|$#@" (excluding the quotes)
  • separator is a character from the string ".,|$#@" (excluding the quotes)

Asked at 3 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate