As the two capacitors are connected with reverse polarity, So total charge
Qt=Q2−Q1=(2C)(4V)−CV=7CV
After connecting them they are in parallel so total capacity is Ct=C+2C=3C
We know that after connecting the common potential is
Vc=total chargetotal capacity=QtCt=7CV3C=(7/3)V
Heat produced H= energy loss=Ui−Uf
H=Ui−Uf=[12CV2+12(2C)(4V)2]−12CtV2c
=332CV2−12(3C)(7/3V)2=CV2[(33/2)−(49/6)]=(25/3)CV2