Central idea is, consider the cavity as negative a mass and apply the superposition of gravitational potential.
Consider the cavity formed in a solid sphere as shown in the figure.
The gravitational potential at infinite distance,
V=r−GM
⇒V(∞)=0

According to the question, we can write potential at an internal point P due to complete solid sphere,
Vs=−2R3GM[3R2−(2R)2]
=2R3−GM[3R2−4R2]
=2R3−GM[411R2]=8R−11GM
Mass of removed part
=34×πR3M×34π(2R)3=8M
The potential at a point P due to removed part
VC=2−3×R(8GM)=8R−3GM
Thus, potential due to the remaining part at the point P,
VP=Vs−Vc=8R−11GM−(−8R3GM)
8R(−11+3)GM=R−GM
