When solving this problem, we must first observe how word1 becomes word2. Taking Example1 as an example, the lower left figure lists the distance from “horse” to “ros”.
This problem asks us to calculate the total number of all possible paths from the top-left corner to the bottom-right corner. We can observe that to go from the top-left corner to the bottom-right corner, the robot can only go right or down.
This problem asks us to list all possible combinations, so we can use backtracking to find them. However, we must avoid finding duplicated combinations.
We must first understand what the competitive subsequence in the problem is. When a is more competitive than b, this means that the letters of a are smaller than the letters of b at the same position.