cswork / libraryOpen practice workspace

Interview questions · Clickup

Process document edit events

This question evaluates implementing and manipulating a line-based document through sequential event processing, emphasizing array/list operations, string handling, and state management; it belongs to the Coding & Algorithms domain and tests data-structure and input-event processing competency.

Implement a line-based document editor.

You are given:

  • an initial document represented as an array of strings, where each string is one line
  • a list of events in chronological order

Each event is one of the following:

  1. {"type": "insert_line", "index": i, "text": s}: insert a new line s at 0-based position i. Valid positions are from 0 to document.length.
  2. {"type": "delete_document"}: delete the entire document so it becomes empty.

Apply all events in order and return the final document as an array of strings.

Be careful about corner cases such as inserting into an empty document, inserting at the beginning or end, multiple delete_document events in a row, and additional edits after the document has been deleted.

Community answers

Nothing here yet.

Join in on CSWork →