This might help:
You already know how to assign electron configurations to elements. You read the periodic table from left to right, filling in the right number of electrons in the exponent by counting how far you go in the row to reach the element. The electron configuration for oxygen, for example would be: 1s
22s
22p
4.
With, 1s2 2s2 3s2, it would be carbon by virtue of its electron number, assuming a neutral element. The problem is that the orbitals are filled in the wrong order. The 2p orbital is lower energy than the 3s orbital and thus is filled first. Hence the electron configuration for carbon is: 1s
22s
22p
2Similar thing for 1s2 2s2 2p6 3s1 3p1. According to the Aufbau principle, lower energy orbitals are filled before higher energy orbitals. The configuration for Magnesium is therefore 1s
22s
22p
63s
2