Skip to main content
LeetCode 5, Medium. Topics: Two Pointers, String, Dynamic Programming. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 12 parametrized pytest cases, and a playground notebook:

Problem

Given a string s, return the longest palindromic substring in s.

Examples

Explanation: “aba” is also a valid answer.

Constraints

  • 1 <= s.length <= 1000
  • s consist of only digits and English letters.

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

Grind 75, Grind, Blind 75, NeetCode 150, NeetCode 250, NeetCode All.
Last modified on August 25, 2026