This is a question from CodeFights.com:
Given an array of equal-length strings, check if it is possible to rearrange the strings in such a way that after the rearrangement the strings at consecutive positions would differ by exactly one character.
For, the output should beinputArray = ["aba", "bbb", "bab"]; All rearrangements don’t satisfy the description condition. (sic)stringsRearrangement(inputArray) = false
For, the output should beinputArray = ["ab", "bb", "aa"]. Strings can be rearranged in the following way:stringsRearrangement(inputArray) = true."aa", "ab", "bb"
I found an exponential-time algorithm, but is there a polynomial-time algorithm? Is this problem NP-complete?
I know that a closely related problem, the Hamming Salesman Problem (HTSP), is NP-complete, and this problem is certainly reducible to HTSP, but I don’t know if HTSP is reducible to this one.