A sort can hide a tie.
transcript
Envelopes nest in size. Width and height both rise. A careless sort breaks it. Let me show you. The sort decides the answer.
Two envelopes share a width. Neither fits inside the other. Shorter first makes the heights rise. Taller first makes them fall. Answer one. The tie is easy to miss. Test it every time.
Sort by width, smallest first. For equal widths, put the taller first. Then find the longest rising run of heights. Then use the strict bound. Use the strict bound. Skip any step, and ties break it.
Keep the smallest tail for each length. Replace the first tail not below the height. Equal heights replace, never extend. Both rules prevent a false chain.
A hundred thousand envelopes. Seventeen steps for each height. One sort, then one pass. Many solutions miss this tie.
Sort carefully. Taller first on ties. Test equal widths. Full breakdown in the lecture.