A new characterization of some alternating and symmetric groups