Break on
Scan left to right. At each delimiter, save the current piece and start a new one.
A foundation for interview problems
Strings are sequences of character codes. Learn how to inspect them, transform them, and avoid hidden work when assembling new text.
CHARACTER INSPECTOR
Letters and digits live in consecutive code ranges. Comparing a character against the range is often all you need.
m is a lowercase letter.
The detail that changes the algorithm
Appending with result += char can create a fresh string and copy everything already built. In a loop, that repeated copying can become the bottleneck.
Instead, collect characters or pieces in a dynamic array. When the work is complete, join them once. You still create the final string, but you avoid rebuilding its growing prefix over and over.
Three common operations
Scan left to right. At each delimiter, save the current piece and start a new one.
The output must contain every piece and separator, so the work is proportional to its length.
byA basic matcher tests the pattern at each possible starting position.
Use the sequential ranges for English letters and digits when a problem calls for low-level character checks.
Know your language’s split, join, and search APIs—but be ready to explain the underlying scan.
When building text incrementally, favor an array or builder and create the finished string once.