You can refer the editorial.
So I went through your code, and I was confused with the approach. The approach could have been like this.
- Take the sum of the entire array. if the sum is odd that means it is an odd length string and if the sum is even then it is an even length string.
- Count the number of odd character string.
- Two different odd characters should be paired up. aaa and bbb should be converted to even aaaaaa now it will be useful for making pallindrome
- If the string length is odd then the odd character after pair up should be 1 because there needs to be a odd character in the middle of the string FOR EG acbca
- If the string length is even then the odd character after pair up should be 0 because there needs to be 0 characters in the middle of the string FOR EG acca
Really appreciate your answer! I think that I did not really get the logic, so messed up the code too…
Thanks for your reply!