[Naive Approach] Recursive Method - O(n^2) Time and O(h) Space
The idea is to count the number of nodes in the tree. Let count of all nodes be n. Traverse the tree again and for each node, find size of subtree rooted with this node. Let cnt be the size of subtree size. If n-cnt is equal to cnt, then return true. Otherwise recursively check for left and right subtree.
Below is the implementation of the above approach:
Output
True
[Expected Approach] Bottom-Up Manner - O(n) Time and O(h) Space
The idea is to traverse tree in bottom up manner and while traversing, for each node, find the size of the subtree and check if the current node follows the required property.