maxheight recursive function