Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Design a Text Editor
Bookmark
Cursor Index
Two Stacks
Input
LeetCode Example
Simple Edit
Insert Middle
Custom
operations
=
[TextEditor, addText, deleteText, addText, cursorRight, cursorLeft, deleteText, cursorLeft, cursorRight]
,
values
=
[null, leetcode, 4, practice, 3, 9, 4, 7, 6]
TextEditor
Left Stack
Right Stack
cursor
(empty)
Full Text (| = cursor position)
|
TextEditor
Left Stack
Right Stack
cursor
(empty)
Full Text (| = cursor position)
|
addText("leetcode")
Left Stack
Right Stack
l
0
e
1
e
2
t
3
cursor
Full Text (| = cursor position)
l
e
e
t
|
deleteText(4)
Left Stack
Right Stack
l
0
e
1
e
2
t
3
c
4
o
5
d
6
e
7
cursor
Full Text (| = cursor position)
l
e
e
t
c
o
d
e
|
addText("practice")
Left Stack
Right Stack
l
0
e
1
e
2
t
3
p
4
cursor
Full Text (| = cursor position)
l
e
e
t
p
|
addText("practice")
Left Stack
Right Stack
l
0
e
1
e
2
t
3
p
4
r
5
a
6
c
7
t
8
i
9
c
10
cursor
Full Text (| = cursor position)
l
e
e
t
p
r
a
c
t
i
c
|
cursorLeft(9)
Left Stack
Right Stack
l
0
e
1
e
2
t
3
p
4
r
5
a
6
c
7
t
8
i
9
c
10
e
11
cursor
Full Text (| = cursor position)
l
e
e
t
p
r
a
c
t
i
c
e
|
cursorLeft(9)
Left Stack
Right Stack
l
0
e
1
e
2
t
3
p
4
r
5
cursor
a
0
c
1
t
2
i
3
c
4
e
5
Full Text (| = cursor position)
l
e
e
t
p
r
|
a
c
t
i
c
e
deleteText(4)
Left Stack
Right Stack
l
0
cursor
t
0
p
1
r
2
a
3
c
4
t
5
i
6
c
7
e
8
Full Text (| = cursor position)
l
|
t
p
r
a
c
t
i
c
e
cursorRight(6)
Left Stack
Right Stack
t
0
cursor
p
0
r
1
a
2
c
3
t
4
i
5
c
6
e
7
Full Text (| = cursor position)
t
|
p
r
a
c
t
i
c
e
cursorRight(6) => "tpract"
Left Stack
Right Stack
t
0
p
1
r
2
a
3
c
4
t
5
cursor
i
0
c
1
e
2
Full Text (| = cursor position)
t
p
r
a
c
t
|
i
c
e
algo
master
.
io
Step:
Initialize TextEditor with empty text and cursor at position 0
0 / 56
Input
LeetCode Example
Simple Edit
Insert Middle
Custom
operations
=
[TextEditor, addText, deleteText, addText, cursorRight, cursorLeft, deleteText, cursorLeft, cursorRight]
,
values
=
[null, leetcode, 4, practice, 3, 9, 4, 7, 6]
0 / 56
algo
master
.
io
Step:
Initialize TextEditor with empty text and cursor at position 0