According to the Molecular Orbital Theory (MOT),
For O2 (16 electrons):
The configuration is σ1s2,σ∗1s2,σ2s2,σ∗2s2,σ2pz2,(π2px2=π2py2),(π∗2px1=π∗2py1)
Oxygen has two unpaired electrons in the degenerate antibonding π∗ orbitals. Thus, it is paramagnetic.
For O22− (Peroxide ion, 18 electrons):
The configuration is σ1s2,σ∗1s2,σ2s2,σ∗2s2,σ2pz2,(π2px2=π2py2),(π∗2px2=π∗2py2)
All electrons are paired. Thus, it is diamagnetic.
For C2 (12 electrons):
The configuration is σ1s2,σ∗1s2,σ2s2,σ∗2s2,(π2px2=π2py2)
All electrons are paired. Thus, it is diamagnetic.
For N2 (14 electrons):
The configuration is σ1s2,σ∗1s2,σ2s2,σ∗2s2,(π2px2=π2py2),σ2pz2
All electrons are paired. Thus, it is diamagnetic.