educative.io

Educative

Error in serialize and deserialize method 2

The deserialize preorder and inorder is skipping one elem:

arr = [100,50,200,25,75,125,350]
root = create_BST(arr)
display_level_order(root)
output1 = open('pre.class', 'wb')
p1 = pickle.Pickler(output1)
serialize_preorder(root, p1)
output1.close()
output2 = open('in.class', 'wb')
p2 = pickle.Pickler(output2)
serialize_inorder(root, p2)
output2.close()
input_pre = open('pre.class','rb')
preorder = deserialize_preorder(input_pre, len(arr))
input_in = open('in.class','rb')
inorder = deserialize_inorder(input_in, len(arr))
print(preorder)
print(inorder)
root2_deserialized = deserialize2(preorder, inorder, 0, 0, len(preorder)-1, len(inorder)-1)
print("Result:")
display_level_order(root2_deserialized)

Result misses one element: 350

100, 50, 200, 25, 75, 125, 350,
[100, 50, 25, 75, 200, 125]
[25, 50, 75, 100, 125, 200]
Result:
100, 50, 200, 25, 75, 125,