Problem
You get a string s. Return the longest substring of s that is a palindrome.
A substring is a part of a string with consecutive characters. A palindrome is a string that reads the same from left to right and from right to left.
If more than one palindrome has the maximum length, you can return any one of them.
Example 1
- Input:
- s = "xabacay"
- Output:
- "aba"
- Explanation:
"aca"is also a correct answer, because it has the same length.
Example 2
- Input:
- s = "levelup"
- Output:
- "level"
Example 3
- Input:
- s = "q"
- Output:
- "q"
- Explanation:
- A string with one character is a palindrome.
Constraints
- 1 <= s.length <= 1000
- s has only digits and English letters.
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Palindromic Substrings
Coding · Dynamic Programming · String · Two Pointers
- Push Dominoes
Coding · Dynamic Programming · String · Two Pointers
- Longest Palindromic Subsequence
Coding · Dynamic Programming · String
- Longest Common Subsequence
Coding · Dynamic Programming · Longest Common Subsequence · String
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 3 records
Netapp
Leetcode 5. Longest Palindromic Substring
Reported Aug 1, 2026 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View sourceSalesforce
Leetcode 5. Longest Palindromic Substring
Reported Apr 25, 2026 · 1 source report
SENIOR
Source snapshot: Nov 12, 2026
View sourceUber
Leetcode 5. Longest Palindromic Substring
Reported Nov 23, 2025 · 2 source reports
SENIOR, STAFF
Source snapshot: Nov 12, 2026
View source
LeetCode company tags · 13 records
Adobe
Longest Palindromic Substring