Skip to content
DeepForgeby svx
All problems
HardData Structuresds-243

Piece Table Delete

Problem

Simulate delete operations on a piece table and return the final text.

original is the immutable original text and operations contains ["delete", pos, count] with 0-based positions; deletions longer than the remaining text are clipped. Each delete splits pieces at its boundaries and drops the covered region.

Return the materialized text after all operations.

Hint

Clipping the delete count against the remaining text prevents out-of-range slices.

Test cases

case 1
in: ["abcdef",[["delete",2,2]]]
expected: "abef"
case 2
in: ["abcdef",[["delete",0,3],["delete",0,1]]]
expected: "ef"
case 3
in: ["",[["delete",0,5]]]
expected: ""
case 4
in: ["abc",[["delete",1,10]]]
expected: "a"
Starter codePython
def piece_table_delete(original, operations):
    # Your code here
    pass

4 test cases · run your code against them in the editor