beyondgrader.com Logo
DemoBrowseAboutTeamLogin

Binary Tree Count Children Sum to Negative

Geoffrey Challen // 2021.4.0

Create a method named countChildSumToNegative that accepts a single BinaryTree<Int>? and counts the number of nodes in the tree where the values of node's children sum to a negative number. You should not count nodes that don't have at least one child, but some nodes may only have one child. Keep in mind that not every node has a right or left child, so you'll need to check for null carefully. However, you can assume that all the values in the tree are Ints.

For reference, cs125.trees.BinaryTree is defined like this: