Back to Practice Dashboard
Competitive ProgrammingEasy

Longest Palindromic Substring

Learn how to solve the 'Longest Palindromic Substring' problem. This detailed resource details brute force and optimized approaches.

Problem Statement

Easy

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

Write a function longestPalindrome(s: str) -> str.

Constraints
  • 1 <= len(s) <= 1000
  • s consists of only digits and English letters

Examples

Example 1
Input
s = "babad"
Output
"bab"
Explanation

"aba" is also a valid answer.

Example 2
Input
s = "cbbd"
Output
"bb"
Explanation

The longest palindromic substring is "bb".

Need a Hint?
Define subproblem states, establish the recurrence relation, and use memoization (top-down) or tabulation (bottom-up).
Edge Cases to Watch
  • Empty list or null input variables
  • Single item lists/arrays
  • Extremely large input bounds causing integer or stack overflow

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor