The valence electrons determine how many electrons an atom is willing to give up or how many spaces need to be filled in order to satisfy the rule of octet.
Lithium (Li), Sodium (Na) and Potassium (K) all have an electron configuration that ends as s1. Each of these atoms would readily release this electron to have a filled valence shell and become stable as Li+1,Na+1 and K+1. Each element having an oxidation state of +1
Oxygen (O) and Sulfur (S) all have an electron configuration that ends as s2p4.
Each of these atoms would readily take on two electrons to have a filled valence shell and become stable as O−2, and S−2.
Each element having an oxidation state of - 2.
There are exceptions to the rules and the transition metals usually have more than one oxidation state.