Recall that
v² - u² = 2 a ∆x
where u and v are initial and final velocities, respectively; a is acceleration; and ∆x is the change in position.
We can use this formula to determine the launch speed of the ball. In the vertical direction, the ball has acceleration g in the downward direction, where g = 32.2 ft/s². At its maximum height, the ball has 0 vertical velocity. So we have
0² - u² = 2 (-32.2 ft/s²) (40 ft)
==> u ≈ 50.75 ft/s
Now, the ball's height y at time t is given by
y = u t - 1/2 g t²
Find at which time t the ball covers the first 20 ft of its trajectory:
20 ft = (50.75 ft/s) t - 1/2 g t²
==> t ≈ 0.462 s
(there is a second solution, t ≈ 2.69 s, which corresponds to the time it takes for the ball to return to this height as it's falling back down)
During this first interval, the ball's horizontal position x is
x = (20 mph) t ≈ (29.33 ft/s) t
so that at the moment the ball reaches a height of 20 ft, it will have moved
x = (29.33 ft/s) (0.462 s) ≈ 13.5 ft
to the right. (So we've take the right to be positive and the left to be negative.)
In the upper half of its trajectory, when the wind changes direction, the ball's horizontal position is given by
x = 13.5 ft - (29.33 ft/s) t
Note that t = 0 here means we now take the ball's current position to be the "initial" one. So the time we found earlier for when the ball has a height of 20 ft as it's falling back down is actually t = 2.69 s - 0.462 s ≈ 2.23 s. At this point, the ball's horizontal position is
x = 13.5 ft - (29.33 ft/s) (2.69 s - 0.462 s) ≈ -51.8 ft
or about 51.8 ft to the left of where it started.
The wind changes direction again, so that the ball's position at time t is now
x = -51.8 ft + (29.33 ft/s) t
Solving y = 0 for t gives the time when the ball reaches the ground:
0 = (50.75 ft/s) t - 1/2 g t²
==> t ≈ 3.15 s
Again, this is the time it takes for the ball to reach the ground since it was launched, while the position function takes t = 0 to refer to the moment the ball is 20 ft above the ground. So once it hits the ground, it will be
x = -51.8 ft + (29.33 ft/s) (3.15 s - 2.69 s) ≈ -38.3 ft
which means the ball lands on the ground about 38.3 ft to the left of where it started.