simple but clean code of tree basic problem