Assume E is emf of each cell.
and R = resistance of the circuit.
Since, I=VR
When x cells are wrongly connected then
Enet=12E−2xE
When cells and battery aid each other
Then, 3=12E−2xE+2ER.....(1)
When they oppose each other
2=12E−2xE−2ER........(2)
Solving equation (1) and (2),
32=14−2x10−2x
x=1