16 / 19

Explain how to find the longest palindromic substring.

Longest Palindromic Substring

javascript
  1. 1

    Expand-around-center takes O(n²) time in the worst case.

  2. 2

    Auxiliary space is O(1), excluding the returned substring.

  3. 3

    Dynamic programming can also solve the problem in O(n²) time and O(n²) space.

  4. 4

    Manacher's Algorithm solves the problem in O(n) time but is more complex.

  5. 5

    For production code, I would choose the approach based on input size and maintainability requirements.

Difficulty: 4/10

Follow-up Questions

  • How does Manacher's Algorithm achieve O(n)?
  • How would you solve this using dynamic programming?
  • What is the difference between longest palindromic substring and subsequence?