Add Drama to Text Groups
Reported by candidates from Upstart's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Upstart reportedly put "Add Drama to Text Groups" in an OA in July 2026, and the trap is in the spaces, not the logic. You replace every period with !, then append one extra ! after each run of non-space characters. Sounds trivial. Then leading spaces, double spaces, trailing spaces and an empty string show up, and a quick split-and-join solution quietly mangles them. If you have this OA in a day or two, read the edge cases first. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but this one is easy once you see the shape.
The problem
Transform a string s in two steps: Replace every period. with an exclamation mark !. Treat every maximal non-space run as one group and append one additional ! after that group. Preserve every space exactly, including leading, trailing, and repeated spaces. Existing exclamation marks are unchanged before the group-ending mark is appended. Therefore a group whose last character is a period or exclamation mark can end with multiple exclamation marks. Function addDrama(s: String) → String Examples Example 1 s = "Hello. world" return = "Hello!! world!" The period becomes !, then one additional ! is appended after each of the groups Hello! and world. Example 2 s = "Wait... now!" return = "Wait!!!! now!!" Three periods become three exclamation marks. The group-ending operation adds a fourth after Wait!!! and a second after now!. Example 3 s = " a.b c " return = " a!b! c! " The leading, repeated, and trailing spaces are preserved. The two non-space groups each receive one final !. Constraints 0 <= s.length <= 200000 s contains printable ASCII characters and spaces. A space is the only group separator.
Reported by candidates. Source: FastPrep
Pattern and pitfall
This is a single-pass string scan. Walk the string once, keep it as a character array or builder, and track whether you're inside a group. For each character: if it's a space and you were in a group, emit ! first, then emit the space. If it's a period, emit !. Otherwise emit it as is. After the loop, if you ended inside a group, emit one more !. That's O(n) with n up to 200000, so no quadratic string concatenation. The pitfall is split(" "), which loses or distorts repeated and edge spaces, and forgetting the final group when the string doesn't end in a space. Also check empty input and all-space input, where nothing should be appended. Example 2 shows why order matters: replace first, then append, so "Wait..." becomes four exclamation marks. StealthCoder is your hedge in the live OA if the edge cases slip, but a flag variable covers it.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Add Drama to Text Groups cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Upstart's OA.
Upstart reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Add Drama to Text Groups FAQ
How hard is Add Drama to Text Groups really?+
Easy on algorithm, tricky on details. It's a linear string scan with no data structures. The difficulty is spaces: leading, trailing and repeated ones must survive exactly. If you handle the end-of-string group and empty input, you're done in a few minutes.
What's the trick to getting it right?+
Use an in-group boolean. When you hit a space after a group, append ! before the space. When the loop ends and you're still in a group, append one more !. Convert periods to ! as you go, so the group-ending mark stacks after them.
Why does split and join fail here?+
Splitting on a space can produce empty tokens, and joining them back is easy to get wrong with consecutive, leading or trailing spaces. You'd need to special-case empty pieces. A manual scan preserves every space naturally and avoids that whole class of bugs.
What edge cases should I test before submitting?+
Test an empty string, a string of only spaces, a single character, a string ending in a period like "Wait...", a string with leading and trailing spaces, and multiple spaces between groups. Also try a group already ending in !, which should end up with two.
How should I prepare in 48 hours for an Upstart OA like this?+
Practice string-scanning problems where you build output in one pass using a state flag. Use a list or builder instead of repeated concatenation. Write the examples from this problem as tests, since they cover the traps. Then rehearse a clean loop-and-flush structure.