Answer
$f=10\;\rm cm$
Work Step by Step
Since the same lens was used in both cases, so we have the same magnification factor $m$.
$$m=\dfrac{-d_i}{d_o}$$
In the first case, case (a), [the magnification here is positive]
$$m=\dfrac{-d_{i1}}{d_{o1}}=\dfrac{-d_{i1}}{5}$$
Thus,
$$d_{i1}=-5m\tag 1$$
In the second case, case (b), [the magnification here is negative]
$$-m=\dfrac{-d_{i2}}{d_{o2}}=\dfrac{-d_{i2}}{15}$$
Thus,
$$d_{i2}= 15m\tag 2$$
Divide (2) by (1);
$$\dfrac{d_{i2}}{d_{i1}}=\dfrac{ 15m}{-5m}=-3$$
Thus,
$$d_{i2}=-3d_{i1}\tag 3$$
Now we need to use the formula of thin lenses;
$$\dfrac{1}{f}=\dfrac{1}{d_o}+\dfrac{1}{d_i}$$
And since we are using the same lens,
$$\dfrac{1}{f}=\dfrac{1}{d_{o1}}+\dfrac{1}{d_{i1}}=\dfrac{1}{d_{o2}}+\dfrac{1}{d_{i2}}$$
Plugging from (3) and plugging the known;
$$ \dfrac{1}{5}+\dfrac{1}{d_{i1}}=\dfrac{1}{15}+\dfrac{1}{-3d_{i1}}$$
Solving for $d_{i1}$;
$$ \dfrac{1}{d_{i1}}+\dfrac{1}{3d_{i1}}=\dfrac{1}{15}-\dfrac{1}{5}$$
$$ \dfrac{4}{3d_{i1}}= -\dfrac{2}{15}$$
So,
$$d_{i1}=\color{red}{\bf -10}\rm\;cm$$
Therefore, from (3);
$$d_{i2}=-3d_{i1}=-3\times -10=\color{red}{\bf 30}\rm\;cm$$
Now we can find the focal length of the lens which is given by
$$ f =\left[\dfrac{1}{d_o}+\dfrac{1}{d_i}\right]^{-1}$$
Plugging the known for any case, a or b,
$$ f =\left[\dfrac{1}{5}+\dfrac{1}{-10}\right]^{-1}=\color{red}{\bf 10}\rm\;cm$$