Delete Zero Sum Sub-Trees

Given a binary tree, delete any sub-trees whose nodes sum up to zero.

Statement

Given the root of a binary tree, delete any sub-trees whose nodes sum up to zero.

Example

In the binary tree below, we need to delete the sub-tree starting at node 55 as its sum (553322) equals zero.

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.