Skip to main content
All Questions

Split a string on several delimiters at once: delete every character covered by an occurrence of any delimiter, overlapping occurrences included, and return the non-empty pieces.

Unlock detailed company stats for this questionUpgrade
Write split(text, delimiters), which splits a string on several delimiter strings at once and returns a flat list of the pieces in their original order. Empty pieces are dropped, so splitting a string that is exactly one of the delimiters returns an empty list. Occurrences of delimiters may overlap each other in the text, and when they do, every character covered by any of the overlapping occurrences is removed. Put another way: mark each character that lies inside at least one occurrence of some delimiter, delete the marked characters, and return the non-empty runs that remain. Examples: split('banana bread', ['an', 'b']) returns ['a ', 'read']; split('seashell', ['eas', 'ash']) returns ['s', 'ell'], because the two delimiters overlap on 'as' and together remove 'eash'.

Community answers

No answers contributed by the community yet.

Related courses

Course

Behavioral Interviews: A Practical Guide for Engineers

Get offers at the level you deserve. Prep for senior+ behavioral interviews at FAANG and Tier-1 companies. Made with staff and principal engineers from Meta, Netflix, Google, and more. Avoid downleveling, elevate past projects, and stop sounding like a robot.

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.