Text Editor Operations
Updated
Problem statement
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": insertsat the cursor; the cursor ends up right after the inserted text."backspace k": delete up tokcharacters to the left of the cursor (fewer if the cursor is closer to the start)."delete k": delete up tokcharacters 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 tokplaces left or right, stopping at the start or end of the text.
Return the final text.
Function
runEditor(operations: String[]) → StringExamples
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"whereshas 1 to 5 lowercase English letters, or"backspace k","delete k","left k"or"right k"with1 <= k <= 100. - The inserted strings have at most
2 * 10^4letters 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