PERMPAL Unofficial Editorial

Hello Community!
I wanted to contribute to the community but since I don’t have enough karma points, I want you to upvote only if you like my unofficial editorial on PERMPAL:

My approach:

  1. The answer will be -1 only when the count of any of 26 characters is odd and there exists more than one such character’s example : abbc, here we can see both ‘a’ and ‘c’ have odd count in the given string.
  2. In any other case, we will always find a answer, that is palindrome.
  3. Based on above point, we will deal with two cases :
    (A)When only one character comes with odd count and rest other characters with even count.
    (B)When all the character in the given string are of even count.

Now the question comes How to solve this?

So it is much clear for case 3(A) that the odd count characters should be in the middle of string in order to make it palindrome, eg abbba n(b)=3 i.e odd

Since the ordering of characters won’t matter in case of even count, we will print index one by one from vector<vector> v(26), which I have used this for storing the index of each character(a-z) in the string. In the output I need to just print the even count characters index ,simultaneously from beginning and end.
Keep in mind that the odd count character should be in the middle.

If you give up, you can see my solution here.

All suggestions are welcome!

Thanks Community,
Happy Coding!

4 Likes

Hello friends…I’m quite stuck on this solution since yesterday…I’m a newbie and tried to solve this question…however it’s giving me WA…can you please tell me where I’m wrong in my code?
link to code

Thanks in advance!!

I have updated the formatting of certain things. Hope you didn’t mind.

Btw, Nice Editorial.

This is your ac solution: https://www.codechef.com/viewsolution/17446057

U were trying to insert at position which didnt existed,(U may google about this as i dont often code with python)

Thanks a lot @taran_1407 :slight_smile:

@vivek_1998299 thank you so much…you saved my day!!

https://www.codechef.com/viewsolution/17340080
Please can some one tell me what is wrong with my code??

@veda_19 Hi ! You can check out my solution https://www.codechef.com/viewsolution/17287463
I’ve used Hashing and fast IO. The logic is to get a new string and obtain its mid-point. Then add to the left
and right of that mid-point the alphabets that occur even. For odd alphabets simply put them in between the new
String.

Hope I helped You !

Happy Coding :slight_smile: