pyassistant

Choose k strings that can be arranged into a palindromic concatenation

Given a list of strings words and an integer k, determine whether it's possible to choose exactly k strings from words (each string may be used at most once) and arrange them in some order so that the concatenation of the chosen strings is a palindrome. Return True if possible, otherwise False. A concatenation of selected strings S1+S2+...+Sm is a palindrome iff for every i, Si equals the reverse of S_{m+1-i}. That means strings must be paired with their reverses; one unpaired palindromic string may be placed in the center if m is odd.

Example:

Input:
(["ab", "ba", "aa", "bb", "aa"], 5)
Output:
True

Make sure you return your solution, don't print!

AI

Bot

Trying to solve my challenge? Ask if you must, or press the purple button so I can analyze your code.