In worst case scenario this can be solved in ~ N^2 tries.
The faster practical solution (not sure if this is allowed) is to create a hash table and assign each unique letter a number.
Set the letter and envelopes set in ascending order based on the same hash table.
Then this can then be solved in ~k*N trials. (depending on the definition of the problem the problem is slightly vague)
Last fiddled with by Citrix on 20210606 at 05:58
