You are given a binary tree and a target binary tree. Your task is to find the minimum number of operations needed to transform the original tree into the target tree.
The allowed operations are:
- Delete a node: Remove a leaf node from the tree.
- Insert a node: Add a new leaf node to the tree.
- Change node value: Modify the value of an existing node.
Complete the implementation of the min_operations
function in tree_transformer.py
that calculates the minimum number of operations required to transform the original tree into the target tree.
- Each node in the tree has a value between 1 and 1000.
- The number of nodes in each tree is between 1 and 100.
- The solution should have optimal time and space complexity.
Original Tree:
1
/ \
2 3
/
4
Target Tree:
1
/ \
2 5
/ \
4 6
The minimum operations required would be 2:
- Insert node with value 6 as right child of node 2
- Change node value from 3 to 5
Run the tests to verify your solution:
python test_tree_transformer.py
Your solution will be evaluated based on:
- Correctness
- Time and space complexity
- Code quality and readability
- Edge case handling
Good luck!