Random walk on two strings to get the lexicographically smallest string. Detailed question commented inside.