Oracle 面试题:文本中的剪贴重复错误检测与修复|String Manipulation|Text Processing|一亩三分地 | 面试辅助

82次阅读
没有评论

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.)

  1. Here_is_some — paste
  2. _piece_of_text — paste ×2
  3. that — paste
  4. _was — paste ×2
  5. _accidentally — paste
  6. _double — paste ×4
  7. _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
    • address is 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

Tricky 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

这题要你从一段文本中 找出并修复“粘贴过多次”造成的重复片段
重复必须满足:

  • 必须是 相邻 的重复
  • 重复的片段必须完全一致
  • 不能把单词拆开
  • 只修复 第一次出现 的重复
  • 删除“最短序列里最长的重复次数”

最终要求输出纠正后的正常句子。

VOprep 团队长期陪同学员实战各类大厂 OA 与 VO,包括 Oracle、Google、Amazon、Citadel、SIG 等,提供实时答案助攻、远程陪练与面试节奏提醒,帮助大家在关键时刻不卡壳。
如果你也在准备公司,可以了解一下我们的定制助攻方案——从编程面到系统设计,全程护航上岸。

正文完
 0