Problem · String
Add Drama to Text Groups
Learn this problemProblem statement
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) → StringExamples
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 <= 200000scontains printable ASCII characters and spaces.- A space is the only group separator.
More Upstart problems
- Lexicographic Word FrequenciesOA · Seen Jul 2026
- Minimum Absolute Pair DifferenceOA · Seen Jul 2026
- Sum Multiples of 3, 5, or 7 Below NOA · Seen Jul 2026
- Coordinate Bounding BoxOA · Seen Jul 2026
- Increase Exclamations and Convert PeriodsOA · Seen Jul 2026
- Interleave Equal-Length Strings by ColumnOA · Seen Jul 2026
- Scale Ingredient QuantitiesOA · Seen Jul 2026
- Bounding Box from CoordinatesOA · Seen May 2026