Let the emf of the cell be $\mathcal{E}$ and its internal resistance be $r$.
The terminal potential difference ($V$) across a cell is given by $V = \mathcal{E} - Ir$ during discharging (current flowing out of the positive terminal) and $V = \mathcal{E} + Ir$ during charging (current flowing into the positive terminal).
Case 1: Current of 2 A flows through the circuit.
This implies the cell is discharging. Let the current be $I_1 = 2$ A.
The terminal voltage is $V_1 = 20$ V.
So, we have the equation: $20 = \mathcal{E} - (2)r$. (Eq. 1)
Case 2: The direction of the current is reversed.
This implies that an external source is driving current through the cell, i.e., the cell is being charged.
The magnitude of the current is not explicitly stated to be the same, but it's implied by the phrasing "reversed". Let's assume the external circuit is such that the magnitude of current is different. Let it be $I_2$. The text says "potential difference is 30V". It is not stated that the current is still 2A.
However, if the current is reversed, it means the cell is being charged by an external source. Let's assume the current magnitude is still 2A. So, $I_2 = 2$ A.
The terminal voltage is $V_2 = 30$ V.
So, we have the equation: $30 = \mathcal{E} + (2)r$. (Eq. 2)
We now have a system of two linear equations for $\mathcal{E}$ and $r$.
(1) $\mathcal{E} - 2r = 20$
(2) $\mathcal{E} + 2r = 30$
To find $r$, we can subtract Equation 1 from Equation 2:
$(\mathcal{E} + 2r) - (\mathcal{E} - 2r) = 30 - 20$.
$4r = 10$.
$r = \frac{10}{4} = 2.5 \Omega$.