FastPrepText Editor Operations
Problems/Text Editor Operations

Text Editor Operations

Microsoft logoMicrosoft● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a review of a Microsoft software engineering internship. The only question the review lists is an editing task, described by three operation names (backspace, delete and insert) and no rules, so how the editor works below is our choice. The round was the online assessment, the only round the review describes, which had two questions it calls easy.

Here the editor starts empty with the cursor at the start, and up to 10^4 operations come as text. insert s puts 1 to 5 lowercase letters at the cursor and moves the cursor after them (at most 2 * 10^4 inserted letters in total). backspace k and delete k remove up to k characters to the left and to the right of the cursor. left k and right k move the cursor up to k places (k from 1 to 100). Moves and erases stop at the ends of the text, and you return the final text. The cursor moves are our addition, needed for delete to mean anything.

Our version is about 70% the same as the reported question.

Implement a simple text editor with a cursor. The text starts empty and the cursor is at position 0. The cursor always sits between two characters (or at either end). Process the operations in order:

  • "insert s": insert s at the cursor; the cursor ends up right after the inserted text.
  • "backspace k": delete up to k characters to the left of the cursor (fewer if the cursor is closer to the start).
  • "delete k": delete up to k characters to the right of the cursor (fewer if the cursor is closer to the end). The cursor does not move.
  • "left k" / "right k": move the cursor up to k places left or right, stopping at the start or end of the text.

Return the final text.

Function

runEditor(operations: String[]) → String

Examples

Example 1

operations = ["insert hel","insert lo","left 2","insert x","backspace 2","delete 1","right 9","insert z"]return = "heoz"

Writing | for the cursor: hel|, then hello|. left 2 gives hel|lo, and insert x gives helx|lo. backspace 2 removes l and x to the left: he|lo. delete 1 removes l to the right: he|o. right 9 can only move one place, to the end: heo|. Finally insert z gives heoz.

Example 2

operations = ["insert abc","left 5","backspace 3","delete 1","insert xy","right 1","delete 4","insert q"]return = "xybq"

left 5 stops at the start: |abc. backspace 3 has nothing to its left and changes nothing. delete 1 removes a: |bc. insert xy gives xy|bc, right 1 gives xyb|c, and delete 4 can only remove c: xyb|. insert q gives xybq.

Constraints

  • 1 <= operations.length <= 10^4
  • Each operation is "insert s" where s has 1 to 5 lowercase English letters, or "backspace k", "delete k", "left k" or "right k" with 1 <= k <= 100.
  • The inserted strings have at most 2 * 10^4 letters in total.

More Microsoft Online Assessment questions

  • Minimum Cost to Process Priority TasksOA · Seen Nov 2026
  • Most Visited Sprint MarkerOA · Seen Nov 2026
  • Maximum Escape Game ScoreOA · Seen Nov 2026
  • Count Subarrays with a Perfect-Square ProductOA · Seen Nov 2026
  • Maximum Interactive Team SizeOA · Seen Nov 2026
  • Maximize Pipeline Throughput Under a Scaling BudgetOA · Seen Nov 2026
  • Minimum Cost K-Capable ModelsOA · Seen Nov 2026
  • Find Available Meeting RoomsOA · Seen Oct 2026
  • Maximum Sum of a K-StarOA · Seen Oct 2026
  • Capacity to Ship Packages Within DaysOA · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Multiline Text Editor with Cursor MovementDatologyAI · PHONE SCREEN
  • Code Editor FoldingJane Street · ONSITE INTERVIEWJane Street interview questions
  • Text Editor, Part 2: Undo and RedoOpenAI · PHONE SCREENOpenAI interview questions
  • Text Document HistoryNotion · PHONE SCREEN · ONSITE INTERVIEWNotion interview questions
  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Parcel Event TrackingAirbnb · OAAirbnb interview questions
  • Layer History with Batch Undo and RedoFigma · OA · PHONE SCREENFigma interview questions
  • Undo/Redo Timeline State EngineKickdrum · OA
  • Communications HandlerAkuna Capital · OAAkuna Capital interview questions
  • Adding Stack 2.0IMC Trading · OAIMC Trading interview questions

Interview reports that mention this question

  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public String runEditor(String[] operations) {
        // Write your code here.
    }
}
Checking account…