Given a sorted dictionary of words, find order of precedence of letters
Let's denote the words by $w[1],\ldots,w[n]$. Suppose that $i &lt; j$ and that $w[i],w[j]$ first differ on the $t$th coordinate. In symbols, $w[i]_{&lt;t} = w[j]_{&lt;t}$ but $w[i]_t &lt; w[j]_t$ (I hope the notation is obvious).

I first claim that $w[k]_{&lt;t} = w[k+1]_{&lt;t}$ for all $k \in \{i,\ldots,j-1\}$. Indeed, suppose that $w[k]_{&lt;t} &lt; w[k+1]_{&lt;t}$ for some $k \in \{i,\ldots,j-1\}$. Then $w[i]_{&lt;t} \leq w[k]_{&lt;t} &lt; w[k+1]_{&lt;t} \leq w[j]_{&lt;t}$, contradicting the assumption $w[i]_{&lt;t} = w[j]_{&lt;t}$.

Call an index $k \in \{i,\ldots,j-1\}$ special if $w[k]_t &lt; w[k+1]_t$. Let the special indices be $k_1,\ldots,k_m$. Then
$$
w[i]_t = w[k_1]_t &lt; w[k_1+1]_t = w[k_2]_t &lt; w[k_2+1]_t \cdots w[k_m]_t &lt; w[k_m+1]_t = w[j]_t.
$$
This shows that $w[i]_t &lt; w[j]_t$ follows from $w[k_1]_t &lt; w[k_1+1]_t,\ldots,w[k_m]_t &lt; w[k_m+1]_t$ by transitivity. (Here we are using the fact, proved earlier, that $w[k_r]_{&lt;t} = w[k_r+1]_{&lt;t}$ for $r \in \{1,\ldots,t\}$.)