How to determine whether inversion takes place?
A) is $\mathrm{S_N2}$ due to the secondary $\ce{C}$ and the sufficiently good nucleophile $\ce{I-}$. So inversion takes place.
B) is $\mathrm{S_N1}$ due to the tertiary $\ce{C}$. The solvent is also more polar than in A). So the stereochemical information would be lost.