Let us suppose the volume of the tank is V litres.
I pipe can fill the tank in x-2 hrs.
So, volume filled in by I pipe in 1 hr, Vin = V/x-2
II pipe can empty the tank in x+2 hrs.
So, volume emptied out by II pipe in 1hr, Vout= V/x+2
So, if the 2 pipes are turned on together
In 1 hour the total volume of the tank will be = Vin-Vout = [V/x-2 -V/x+2]
In 24 hrs the total volume of the tank will be = 24[V/x-2 -V/x+2]
Since the tank is filled totally in 24 hrs so in 24 hr volume becomes equal to V
Hence 24[V/x-2 -V/x+2]=V
Or, x2-4 = 96
Hence time taken by II pipe to empty the tank becomes x+2, =10+2 = 12 hrs.