Google Cloud interview question

Make tree flat and invert