All problems
Piece Table Materialize
Problem
Materialize text from a piece table.
original is the original string, added is the appended buffer, and pieces is a list of [source, start, length] triples where source 0 selects original and 1 selects added.
Return the concatenated text.
Hint
Each piece is a slice of one of the two source strings.
Test cases
case 1
in: ["abc","XY",[[0,0,2],[1,1,1],[0,2,1]]]
expected: "abYc"
case 2
in: ["","",[]]
expected: ""
case 3
in: ["hello","",[[0,1,3]]]
expected: "ell"
case 4
in: ["a","bc",[[0,0,1],[1,0,2],[0,0,1]]]
expected: "abca"
Starter codePython
def piece_table_materialize(original, added, pieces):
# Your code here
pass4 test cases · run your code against them in the editor