The puzzle
Given a set of numbers $\{1,2,\ldots,n\}$ and an expression of inequalities, e.g., $ x_1 > x_2 < \cdots > x_n$. Prove that there always exists a solution such that $x_i \in \{1,2,\ldots,n\}$ and that each $x_i$ is distinct. Can you design an algorithm which always provides a correct solution in polynomial time?
I will not take credit for this problem. It was originally posed by Jim Tanton here.
In less "mathy" terms:
You are given a string of $>$ and $<$ symbols ($n$ of them in total). Insert the numbers from $1$ to $n+1$ between them, so that all the inequalities are true. Find a general solution that works for any string of symbols of any length, and doesn't take exponentially longer when the string of symbols is longer.
Example
You are given < > >
.
You must insert the numbers from $1$ to $4$ between the symbols so that all the inequalities are true:
$1<4>3>2$