solution to the problem of alternating characters