PracHub
QuestionsLearningGuidesInterview Prep
|Home/Coding & Algorithms/Upstart

Add Dramatic Punctuation to Text

Last updated: Jul 28, 2026

Quick Overview

Transform text by replacing periods inside each non-whitespace token and adding the required dramatic suffix while preserving every whitespace character. Handle empty or whitespace-only input, existing punctuation, repeated spaces, tabs, newlines, million-character strings, and streaming extensions.

  • medium
  • Upstart
  • Coding & Algorithms
  • Software Engineer

Add Dramatic Punctuation to Text

Company: Upstart

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Take-home Project

# Add Dramatic Punctuation to Text Implement `add_drama(text)`. Preserve all whitespace exactly. For each maximal non-whitespace token, first replace every period `.` in that token with `!`, then append one additional `!` to the token. Other characters are unchanged. An empty string or a string containing only whitespace is returned unchanged. ## Constraints - `0 <= len(text) <= 10^6` - Input may contain spaces, tabs, and newlines. - The output must be built in linear time. ## Examples - `"hello. world"` becomes `"hello!! world!"`. - `"a b.c"` becomes `"a! b!c!"`. - `" "` remains `" "`. ## Clarifications A token that already ends in `!` still receives the required extra `!`. Replacing a final period and then appending therefore produces two exclamation marks. ## Hints Track whether the scan is inside a token so the extra punctuation is emitted exactly at a token boundary. ## Extensions - Process the text as a character stream. - Treat Unicode grapheme clusters as characters. - Make the replacement and suffix characters configurable.

Quick Answer: Transform text by replacing periods inside each non-whitespace token and adding the required dramatic suffix while preserving every whitespace character. Handle empty or whitespace-only input, existing punctuation, repeated spaces, tabs, newlines, million-character strings, and streaming extensions.

Related Interview Questions

  • Sum Multiples of Three, Five, or Seven - Upstart (medium)
  • Count Words in Lexicographic Order - Upstart (medium)
  • Find the Minimum Absolute Difference - Upstart (medium)
  • Interleave Three Equal-Length Strings - Upstart (easy)
|Home/Coding & Algorithms/Upstart

Add Dramatic Punctuation to Text

Upstart logo
Upstart
Jul 27, 2026, 12:00 AM
mediumSoftware EngineerTake-home ProjectCoding & Algorithms
0
0

Add Dramatic Punctuation to Text

Implement add_drama(text). Preserve all whitespace exactly. For each maximal non-whitespace token, first replace every period . in that token with !, then append one additional ! to the token.

Other characters are unchanged. An empty string or a string containing only whitespace is returned unchanged.

Constraints

  • 0 <= len(text) <= 10^6
  • Input may contain spaces, tabs, and newlines.
  • The output must be built in linear time.

Examples

  • "hello. world" becomes "hello!! world!" .
  • "a b.c" becomes "a! b!c!" .
  • " " remains " " .

Clarifications

A token that already ends in ! still receives the required extra !. Replacing a final period and then appending therefore produces two exclamation marks.

Hints

Track whether the scan is inside a token so the extra punctuation is emitted exactly at a token boundary.

Extensions

  • Process the text as a character stream.
  • Treat Unicode grapheme clusters as characters.
  • Make the replacement and suffix characters configurable.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Upstart•More Software Engineer•Upstart Software Engineer•Upstart Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.