Two Pointers
3302. Find the Lexicographically Smallest Valid Sequence
Greedy from the left wins here, but with a gate: I take the current index of word1 for the current character of word2 the moment the letters agree, and I'm willing to burn my one allowed edit on an early index — but only when the rest of word2 can still be matched exactly by what remains of word1.
Loading…