LC 3800 - Minimum Cost to Make Two Binary Strings Equal
Approach This seems to be a greedy like problem, and I tried to walk the algorithm by-hand. For a simple case, cross and swap operations can be done by two flips. Therefore, if the cost for cross or swap is larger than two flips, we simply replace it with two flips cost. Then, we check when we need to use swap operation. Let’s say we have two sequence as follows s = 1 .. 0 t = 0 .. 1 If we want to eliminate the first difference by swapping, we need to find another (0, 1) pair to swap, since swapping with (0, 0) and (1, 1) did not change anything, this is just moving the difference backwards. So the greedy method is that we eliminate all the (1, 0) and (0, 1) pairs by swapping. ...