solution for nsteps problem