Electron affinity and ionisation energy are co related. I explained the concept using ionisation energy.
Write down the electronic configurations of these elements.
1) Boron and Beryllium
Boron (At.No.5) 1s2 2s2 2p1
Beryllium (At.no.4) 1s2 2s2
Boron has an unfilled orbital and hence can easily lose an electron to attain stability where as in beryllium having the full filled configuration, the energy required would be much higher to remove an electron from 2s.
2) Oxygen and Nitrogen
Oxygen (At.No.8) 1s2 2s2 2p4
Nitrogen(At.No.7) 1s2 2s 2p3
Now here's the golden rule :- Half filled and full filled orbitals are generally more stable than unfilled or vacant atomic orbitals. As nitrogen has a half filled configuration it's ionization enthalpy is more than oxyegn.
The rest can be answered using the same concept of Half filled and full filled stability.