- In the framework of Kohn-Sham density-functional theory, systems with ground-state densities that are not pure-state $v$-representable (PSVR) in the noninteracting reference system occur frequently. In the present contribution, an algorithm, which allows the solution of such systems, is proposed. It is shown that the use of densities which do not correspond to a ground state of their noninteracting reference system is forbidden. As a consequence, the proposed algorithm considers only noninteracting ensemble $v$-representable densities. The Fe atom, a well-known non-PSVR system, is used as an illustration. Finally, the problem is analyzed within finite-temperature density-functional theory, where the physical significance of fractional occupations is exposed and the question of why degenerate states can be unequally occupied is resolved.