Brownian motion and random walk perturbed at extrema