




Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Making changes in the middle of some data structures is generally harder than changing the front/back of the same data structure.
Can you partition your data structure (text with cursor) into two parts, such that each part changes only near its ends?
Can you think of a data structure that supports efficient removals/additions to the front/back?
Try to solve the problem with two deques by maintaining the prefix and the suffix separately.