Problem Description
Given an array of strings (words) and a character (separator), split each string by the given separator and return an array of the resulting substrings in order. Any empty strings resulting from the split should be excluded.
Key Insights
- Process each string individually from the words array.
- Use the built-in string split functionality to split by the separator.
- Filter out any empty strings that result from splitting.
- Maintain the order of substrings as they appear in the original array.
Space and Time Complexity
Time Complexity: O(n) where n is the total number of characters in all the given words, since each character is processed essentially once. Space Complexity: O(n) for storing the resulting substrings.
Solution
The solution involves iterating through each string in the words array, using the language's native split operation with the specified separator. After splitting, we filter out any empty strings (which might occur if the string starts, ends, or has consecutive separators). Append the non-empty substrings to the result list. Finally, return the result list. This approach leverages simple iteration and filtering, keeping the implementation clear and efficient.