[ INFO ]category: Coding difficulty: medium freq: Must first seen: 2026-03-13
[MEDIUM][CODING][MUST]
$catproblem.md
Practice/Google/Leetcode 2296. Design a Text Editor
Leetcode 2296. Design a Text Editor
CodingMust
Problem
Design and implement a text editor class that maintains a document with a movable cursor. Your editor should support the following operations:
addText(text): Insert the given string at the current cursor position and move the cursor to the end of the inserted text
deleteText(k): Delete up to k characters to the left of the cursor (like pressing backspace k times), return the actual number of characters deleted
cursorLeft(k): Move the cursor k positions to the left (stop at the beginning if k is too large), return the last 10 characters to the left of the cursor after moving
cursorRight(k): Move the cursor k positions to the right (stop at the end if k is too large), return the last 10 characters to the left of the cursor after moving
The cursor starts at position 0 (before any text).
Requirements
Implement a TextEditor class with the four methods described above
The deleteText method must return an integer representing how many characters were actually deleted
The cursorLeft and cursorRight methods must return a string containing at most the last 10 characters to the left of the cursor after the movement
Handle edge cases where operations would move the cursor beyond document boundaries
Efficiently handle insertion and deletion operations at the cursor position
Constraints
The total number of characters inserted will not exceed 50,000
At most 20,000 operations will be called
1 ≤ text.length ≤ 100 for addText
1 ≤ k ≤ 50,000 for deleteText, cursorLeft, and cursorRight
All input strings consist of lowercase English letters
Aim for efficient operations on the cursor position