I'm struggling with the following question:
Let $\langle a_0, a_1,\dots,a_n\rangle$ be a sequence of real numbers, and let $ M = \max\{a_0, a_1, .... a_n\} $ and $ m = \min\{a_0, a_1, .... a_n\} $.
a. Prove that there are two numbers in the sequence $x,y$ such that $ |x-y| \leq \frac{M-m}n$.
b. Write an algorithm that finds those numbers in linear time.
I've manage to prove part a, but am struggling with part b. I've tried to find a way to find the two element in the array that have the smallest difference, but couldn't find a way to do it in $\Theta(n)$. It should be something related to select algorithm and medians.