There is more than one way to solve the problem, but that method sounds good to me. One thing to note is that the middle part can be done more easily. Instead of counting characters based on the index, go through the input string and increment the count of each character in that string.