Solution for switching the values in an array of characters