Problem, as an interviewer would state it:
"Implement diff(oldNode, newNode) for a simple virtual DOM — comparing two vnode trees and producing a minimal, TARGETED set of patches, not a full re-render of everything."
Examples:
diff(oldTree, newTreeWithOneChangedLabel);
// a targeted UPDATE patch deep inside the tree, not a full REPLACE at the root
Clarifying questions expected:
- Should genuinely identical subtrees produce NO patch at all, to avoid unnecessary real DOM work later?
- What should happen when the TAG NAME itself changes between old and new — a targeted update, or a full replace?
- Does the diff need to handle a real, changing number of children, not just changes within existing ones?
Code / implementation expected: Yes — real, direct proof across 5 scenarios: identical trees producing no patch, a targeted nested text update, a targeted props update, a root-level tag-change replace, and the CREATE/REMOVE cases.