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:
{"type": "insert_line", "index": i, "text": s}: insert a new linesat 0-based positioni. Valid positions are from0todocument.length.{"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 →