Look at the diagram for clarity. Ball2 is thrown upwards with a speed = U m/sec and Ball1 is thrown downwards with a speed of U m/sec. Let Ball1 and Ball2 meet at a height D from ground at t = T sec after the balls are thrown.
Distance traveled by ball1 from height of 40m: 40 - D = U T + 1/2 9.8 T²
40 - D = U T + 4.9 T² -- Equation 1
Distance traveled by ball 2 from ground upwards: D = U T - 1/2 9.8 T²
D = U T - 4.9 T² -- equation 2
Adding two equations, we get: 40 = 2 U T => U T = 20 -- equation 3
So T = 20/U sec.
4.9 T² = 20 - D from equation 2 and 3.
4.9 (20/U)² = 20 - D
D = 20 - 1960/U²
The distance D depends on the value of U. If U is given then we can find D.
If U = 0 m/s , D = 0 m/s
if U = 10.15 m/s D = 1 m
if U = 44.27 m/s , D = 19 m
if U = 14m/s D = 10 m
if U = infinity, D = 20 m