If root is a leaf node and it 's level is less than k then   remove this node.   This goes up and check for the ancestor nodes also for the   same condition till it finds a node which is a part of other   path(s) too.
if ( node . left == null && node . right == null && level < k ) { return null ; }