Let N be a positive integer. Let f be a function from the nonnegative integers <= N to the reals. Let d > 0. What is a computationally efficient way of finding the largest possible k such that there exists M >=0, M + k <=N such that abs(f(x) - f(y)) <= d for all x, y such that x and y are both >= M and <= M + k? I'm also interested in continuous analogies. For example, suppose f is a continuous function defined on a closed interval. How do we find the length of the longest interval I in the domain of f such that abs(f(x) - f(y)) <= d whenever x and y both lie in I.