At the maximum extension, the velocity of both the blocks will be same.
Let the common velocity of the blocks is v.
From conservation of linear momentum, it can be written as,
(3+6)×v=6×2−3×1
v=1m/s
Let the maximum extension in the spring is x.
From conservation of mechanical energy, it can be written as,
12×3×(1)2+12×6×(2)2=12×200×(x)2+12×9×(1)2
x2=18100
=0.3m
=30cm
Thus, the maximum extension in the spring is 30cm.