I would like to characterize the set $S$ of continuous functions $f \colon I \to \mathbb R$ such that for any $n \ge 0$ and for any polynomial $P$ of degree $n$, the equation $f(x) = P(x)$ has at most $n+1$ solutions. Here $I$ is a generic non-degenerate interval of $\mathbb R$, i.e. two functions in $S$ might be defined on different intervals.
In order to do so, I found it useful to recall the following:
Lemma. Let $g \colon I \to \mathbb R$ be continuously differentiable. If $g'$ has at most $n$ zeros in $I$, then $g$ has at most $n+1$ zeros in $I$.
Proof: Since $g'$ has at most $n$ zeros, there exists $m \le n$ and there exist $m+1$ intervals $[x_0 = \inf I, x_1], [x_1, x_2], \dotsc, [x_m, x_{m+1} = \sup I]$ such that $g'$ keeps the same sign in any $[x_i, x_{i+1}]$. Therefore, $g$ is monotonic in each $[x_i, x_{i+1}]$, and thus has at most one zero in each $[x_i, x_{i+1}]$.
What I have found so far about $S$:
If $f \in S$, then $f$ is injective (and so monotonic). Proof: Let $y \in \mathbb R$. Since $P(x) = y$ is a polynomial of degree $0$ and $f \in S$, the equation $f(x) = y$ has at most $1$ solution.
If $f$ is injective and $f' \in S$, then $f \in S$. Proof: Let $P$ be a polynomial of degree $n > 0$. Since $P'$ has degree $n-1$ and $f' \in S$, then $f'(x) - P'(x)$ has at most $n$ zeros, so by the lemma $f(x) - P(x)$ has at most $n+1$ zeros.
$e^x \in S$. Proof: By induction on $n$. The case $n = 0$ follows by injectivity. Let $n > 0$ and $P(x)$ be a polynomial of degree $n$. By the inductive hypothesis, $e^x - P'(x)$ has at most $n$ zeros, so by the lemma $e^x - P(x)$ has at most $n+1$ zeros.
$\ln x \in S$. Proof: Let $n \ge 0$ and $P(x)$ be a polynomial of degree $n$. Then $1 - x P'(x)$ is a polynomial of degree $n$ and therefore has at most $n$ zeros, and so $\frac 1 x - P'(x)$ also has at most $n$ zeros. Again, by the lemma it follows that $\ln x - P(x)$ has at most $n+1$ zeros.
If $f \in S$ and $g(x) = a f(x) + b$ for some $a, b \in \mathbb R$ with $a \neq 0$, then $g \in S$.
If $f \in S$ and $g(x) = f(a x + b)$ for some $a, b \in \mathbb R$ with $a \neq 0$, then $g \in S$.
Clearly, no polynomial belongs to $S$. Also, $\arcsin x$, $\arccos x$, and $\arctan x$ don't belong to $S$.
Is there a simple characterization of $S$?
I don't mind restricting $S$ to differentiable or even smooth functions if it proves necessary to provide a simple characterization.