This is a problem that requires the use of Gay-Lussac's law of combining volumes. Under constant temperature and pressure, the volumes of reacting gases can be expressed as a ratio of simple whole numbers.
The balanced equation for the reaction is:
2H2 + O2 = 2H2O
2 volumes H2 + 1 volume O2 = 2 volumes H2O
From the information given, the limiting reactant is H2, because if you use 25 liters of O2, then you will need 50 liters of H2.
Since you do not have up to 50 liters of H2, all the 40 liters of H2 will be used up before the volume of O2 is used up.
Volume of H2O formed = 40 L H2 x (2 vol H2O / 2 vol H2) = 40 L H2O
Therefore, volume of water vapor formed = 40 liters