I'm trying to determine the maximum final velocity of a body with which it contracts a spring until it touches the wall. It happens only with the presence of maximum energy. So, I've taken the kinetic energy and used the first derivative to obtain the maximum velocity. Is this the right way to solve this problem? It only gives the minimum velocity which is zero..!