Do two strings differ by N or less characters?
Recently I saw a very nice interview question: given two strings, can you tell quickly whether they differ by no more than one character? The two-pointers approach works well for this question. However, when we expand the problem to ask "do two given strings differ by no more than N characters?" then it becomes problematic with the two-pointers approach. The problem is that for a case like this one: String 1: abc8 String 2: a123456bc7 N: 8 The answer is "yes", because you can remove all the numbers (8 numbers in total) and the two remaining strings will match. But if you're operating with pointers then when you get to the first mismatched element ('b' and '1') which pointers do you move? The first, second, or both? If you go this route recursively chances are you'll end up with an exponential solution. One way to solve this problem is using Dynamic Programming . The idea requires solving the problem for smaller strings and use that...