Let the first pipe be turned off after x minutes, then work done by (First pipe in x min. + Second pipe in 18 min.) = 1
\(\Rightarrow\) \(\frac{X}{30}\)+ \(\frac{18}{40}\) = 1 \(\Rightarrow\) \(\frac{4X+54}{120}\) = 1
\(\Rightarrow\) 4x + 54 = 120
\(\Rightarrow\) 4x = 66
\(\Rightarrow\) x = \(\frac{66}{4}\) = 16.5 min