0

input - "sasank" output - {'s', 'a', 'n', 'k', 'aa', 'ss', 'sas', 'asa' ,'saas', 'assa','aka', 'ana', .......}

we can select characters from any position of a string and combine to form a palindromic string.I have solved palindromic substring problem but unable to develop a logic for this program.

  • 1
    Well how would you do it by hand? Start there and see where it leads you. – NathanOliver Mar 03 '16 at 14:20
  • Do consider that you will have to produce permutations of the input strings characters, but you can eliminate some permutations based on how many of the letter there are: Any palindrome has at most ONE single occurrence of a particular letter. So track how many times each letter occurs in the input string, and based on that, produce your permutations. Problem solved. – Mats Petersson Mar 03 '16 at 14:31
  • Some values are missing (`"ana"`, `"aka"`, ...), else I don't understand from where `"saas"` and `"assa"` come. – Jarod42 Mar 03 '16 at 14:59
  • @Jarod42 - Yeah!! I edited my question output .... {"ana',"aka"...} should be in output. – AB Hi Shek Mar 03 '16 at 15:25
  • @MatsPetersson - Thanks for the explaination.I got some idea. Let me try to write the code first. – AB Hi Shek Mar 03 '16 at 15:31

0 Answers0