In the C.M. frame (which is rigidly attached with the centre of mass of the two cubes) the cubes oscillates. We know that the kinetic energy of two body system equals where μ is the reduced mass and vred is the modulus of velocity of any one body particle relative to other. From the conservation of mechanical energy of oscillation :
Here l0 is the natural length of the spring.
Differenting the above equation w.r.t time, we get :
Hence the natural frequency of oscillation :