Rewrite Sentence-Ending Punctuation
Company: Upstart
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Take-home Project
# Rewrite Sentence-Ending Punctuation
Transform a string in two conceptual steps:
1. Add one extra exclamation mark to every maximal run of existing `!` characters.
2. Replace every period `.` from the original string with one `!`.
Return the transformed string.
### Function Signature
```python
def intensify_punctuation(text: str) -> str:
...
```
### Example
```text
Input: "Hello. Nice to meet you!!"
Output: "Hello! Nice to meet you!!!"
```
### Constraints
- `0 <= len(text) <= 1_000_000`
- `text` may contain arbitrary Unicode characters.
### Clarifications
- A run of `k` original exclamation marks becomes `k + 1` exclamation marks.
- A period becomes exactly one exclamation mark; it is not treated as an original `!` and does not receive the extra mark.
- Other characters are unchanged.
- An empty input returns an empty string.
### Hints
- A single left-to-right pass can distinguish the end of each original exclamation run.
Quick Answer: Transform punctuation so every original run of exclamation marks gains one mark and every original period becomes exactly one exclamation mark. A single left-to-right pass preserves all other Unicode characters and avoids treating converted periods as existing runs.
Transform text by adding one exclamation mark to every maximal run of original exclamation marks and replacing each original period with exactly one exclamation mark. Other Unicode characters are unchanged.
Constraints
- The string may contain up to 1,000,000 Unicode characters.
- A run of k original exclamation marks becomes k+1.
- A replaced period does not receive an extra mark.
- The empty string stays empty.
Examples
Input: ('Hello. Nice to meet you!!',)
Expected Output: 'Hello! Nice to meet you!!!'
Explanation: The supplied example.
Input: ('',)
Expected Output: ''
Explanation: The empty string is unchanged.
Hints
- Scan original characters only.
- Append the extra mark when the current original exclamation is the last in its run.