Ad
  • Default User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    @Me2loveit2 Unless if there is an n log n algorithm for finding palindromes in substrings, the worst case should always be n^2. You can do a bunch of micro-optimizations that will make it slightly faster, but nothing to change the worst case.

    PS: Your solution is very jumbled. Couldn't really be bothered to follow it through to the end to figure out the time complexity. But iterating twice over the string with capture matches to find the center of palindromes is already n^2. Then you go through that list and find the centers inside the original string... Why even match them in the first place, if you are just going to find them again? It would make sense that you would time out because you have a bunch of redundancies that are completely unnecessary.