Implemented find_minima_and_maxima function