When the two way key is switched off, then The current flowing in the resistors R and X is
I=1A......(i)
When the key between the terminals 1 and 2 is plugged in, then
Potential difference across
R=IR=kl1.........(ii)
where k is the potential gradient across the potentiometer wire.
When the key between the terminals 1 and 3 is plugged in, then Potential difference across
(R+X)=I(R+X)=kl2........(iii)
From equation (ii), we get
R===kl1Ω..........(iv)
From equation (iii), we get
R+X===kl2 (Using (i))
X=kl2−R=kl2−kl1=k(l2−l1)Ω (Using (iv))