How should I approach this? I understand visually that it makes sense, but I have no idea how to use math regarding supremum and infimum. In general, I am also struggling with these type of proofs because the worse thing is I have no idea where to start, how can I improve?
The following is the previous parts of the question, which may be useful:

The main problem actually is I cannot substitute definition of supremum and infimum with definition of max and min, otherwise this problem is easy.

Hint: Assume $f$ is not constant. Take two sequences $x_n$ and $y_n$ such that $f(x_n) \to \sup f$ and $f(y_n) \to \inf f$. Then $$f(x_n) - f(y_n) = |f(x_n) - f(y_n)| \le |g(x_n) - g(y_n)| \le\sup g-\inf g$$