I am trying to prove the following result.
Suppose $f: [a,b] \to \mathbb{R}$ is continuous and $v \in \mathrm{Im}(f)$. There exist largest and smallest values of $x \in [a,b]$ such that $f(x) = v$. This result fails if $[a,b]$ is replaced by $(a,b)$.
Here is my attempt.
Let $S := \{x \in [a,b] \mid f(x) = v\}$. As $v \in \mathrm{Im}(f)$, $S$ is nonempty, and as $S \subset [a,b]$, which is bounded, $S$ is bounded, so $\alpha := \inf S$ and $\beta := \sup S$ exist. I claim, first, that $f(\alpha) = S$. Fix $\epsilon > 0$. By continuity of $f$ at $\alpha$, we can find $\delta > 0$ such that for any $t \in [a,b] \cap \left(\alpha - \delta, \alpha + \delta \right)$, we have $|f(\alpha) - f(t)| < \epsilon$. As $\alpha - \delta < \alpha$, there exists $s \in S$ such that $\alpha - \delta \leq s \leq \alpha$, i.e., $s \in S \cap \left(\alpha - \delta, \alpha + \delta\right)$, so we have $|f(\alpha) - f(s)| = |f(\alpha) - v| < \epsilon$. If $f(\alpha) \neq v$, then $|f(\alpha) - v| = \beta$ for some $\beta > 0$. Picking $\epsilon = \frac{\beta}{2}$, we obtain $\beta < \frac{\beta}{2}$, which is a contradiction, so $f(\alpha) = v$, so $\alpha \in S$, so $\alpha$ is the largest value of $x \in [a,b]$ such that $f(x) = v$. That is, $\alpha = \max S$. \smallskip
Next, I claim that $f(\beta) = v$. Fix $\epsilon > 0$. By continuity of $f$ at $\beta$, there exists $\delta > 0$ such that for any $t \in [a,b] \cap \left(\beta - \delta, \beta + \delta\right)$, we have $|f(\beta) - f(t)| < \epsilon$. As $\beta + \delta > \beta$, $\beta + \delta$ is not a lower bound of $S$, so there exists $s \in S$ such that $\beta + \delta > s \geq \beta$, so $s \in S \cap \left(\beta - \delta, \beta + \delta\right)$, so we have $|f(\beta) - f(s)| = |f(\beta) - v| < \epsilon$. As $\epsilon > 0$ was arbitrary, this implies $f(\beta) = v$, so $\beta \in S$, so $\beta$ is the smallest value of $x \in [a,b]$ such that $f(x) = v$, and we have $\beta = \min S$.