solve binary tree problem