Background
Congratulations! Your next best-selling novel is finally finished. You cut/paste text fragments from your various notes to build the final manuscript. But you are a terrible typist! Often you press the “paste” key multiple times by mistake.
You’d better fix those errors before sending it off to the publisher. Fortunately, you can code better than you can type.
Kata Task
Detect and correct accidental cut/paste errors in the given text.
Example
What you did
(The spaces in the text are shown below as“_”for clarity.)
Here_is_some— paste_piece_of_text— paste ×2that— paste_was— paste ×2_accidentally— paste_double— paste ×4_pasted.— paste
The result
Here is some piece of text piece of text that
was accidentally double double double double pasted.
The corrected result
Here is some piece of text that was accidentally double pasted.
Notes
- words are groups of alphabetic characters
- Non-alphabetic characters are considered punctuation and spaces
- Repeated letters within words are NOT errors
addressis okay
- Cutting never breaks words apart
- Fragments of only punctuation/space are never double-pasted
- repeated punctuation — allowed
- repeated spaces — allowed
- Only detect adjacent double-pasting
- Only treat the first repetition as the double-paste
- Remove the longest repetition of the shortest sequence
- Pasting happens left-to-right
Trickier Examples
| Input | Output | Explanation |
|---|---|---|
A_X_A_X_O_X_O_X_ |
A_X_O_X_ |
Correct(finds the first repeat) |
A_X_A_X_O_X_O_X_ |
A_X_A_X_O_X_X_ |
Wrong |
A_A_B_A_A_B_ |
A_B_A_B_ |
Correct(finds the first repeat, not the bigger one) |
A_A_B_A_A_B_ |
A_A_B_ |
Wrong |
This problem asks you to analyze a text and detect accidental repeated pastes. A valid repeated paste must:
- be adjacent,
- represent repeated occurrences of the same sequence,
- not split words,
- and must prioritize removing the longest repetition of the shortest sequence.
The goal is to reconstruct the intended text with only one copy of each mistakenly repeated fragment.
The VOprep team has long accompanied candidates through various major company OAs and VOs, including Oracle, Google, Amazon, Citadel, SIG, providing real-time voice assistance, remote practice, and interview pacing reminders to help you stay smooth during critical moments. If you are preparing for these companies, you can check out our customized support plans—from coding interviews to system design, we offer full guidance to help you succeed.