Split Strings by Separator
Split Strings by Separator
Given an array of strings words and a character separator, split each string in words by the separator. Return an array of strings containing the new strings formed after the splits, excluding any empty strings. The separator character itself should not be included in the resulting strings.
Example 1:
Input: words = ["one.two.three","four.five","six"], separator = "."
Output: ["one","two","three","four","five","six"]
Example 2:
Input: words = ["$easy$","$problem$"], separator = "$"
Output: ["easy","problem"]
Example 3:
Input: words = ["|||"], separator = "|"
Output: []
Constraints:
1 <= words.length <= 1001 <= words[i].length <= 20- Characters in
words[i]are either lowercase English letters or characters from the string".,|$#@". separatoris a character from the string".,|$#@".
Similar LeetCode problem: Split Strings by Separator
AI interview prep
Core dilemma
Efficiently parsing and filtering strings based on a delimiter, while managing potential edge cases like consecutive delimiters or delimiters at string boundaries.
2 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Split Strings by Separator
Split Strings by Separator
Given an array of strings words and a character separator, split each string in words by the separator. Return an array of strings containing the new strings formed after the splits, excluding any empty strings. The separator character itself should not be included in the resulting strings.
Example 1:
Input: words = ["one.two.three","four.five","six"], separator = "."
Output: ["one","two","three","four","five","six"]
Example 2:
Input: words = ["$easy$","$problem$"], separator = "$"
Output: ["easy","problem"]
Example 3:
Input: words = ["|||"], separator = "|"
Output: []
Constraints:
1 <= words.length <= 1001 <= words[i].length <= 20- Characters in
words[i]are either lowercase English letters or characters from the string".,|$#@". separatoris a character from the string".,|$#@".
Similar LeetCode problem: Split Strings by Separator