K is an metal from the first group on the periodic table, while S is a nonmetal from the 16th group.
The K atom can easily lose one electron, so its valence orbital stays with no electrons.
S is similar to O, it only needs two electrons to complete its valence orbital, so it can easily attract two electrons.
Thus, the atom K will form a cation K⁺ while the atom S will form an anion S²⁻.
When putting them together, they will form an ionic compound, and it has to have a neutral charge. Since K is 1+ and S is 2-, we will need 2 K for each S, so the compound formed will be: