Calculates the optimal path to transform one string to another and applies it.