FastPrepAdd Drama to Text Groups
Problems/Add Drama to Text Groups

Add Drama to Text Groups

Upstart logoUpstart● EasyFULLTIMEOA
QuestionFunctionExamplesConstraints

Problem statement

Source note: The source says to replace periods and append an exclamation mark after each group, but it does not define group boundaries, whitespace handling, repeated punctuation, or bounds. The judged core task matches the visible source at about 88%.

Transform a string s in two steps:

  1. Replace every period . with an exclamation mark !.
  2. 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.

More Upstart problems

  • Babysitter Quote with Hourly RatesONSITE INTERVIEW · Seen Oct 2026
  • Maximum SubarrayONSITE INTERVIEW · Seen Oct 2026
  • Buffet Day GainsOA · Seen Sep 2026
All Upstart interview questionsSee Upstart hiring insights
Saved
class Solution {
    public String addDrama(String s) {
        // Write your code here.
    }
}
Checking account…