Longest Palindromic Substring
Medium Two Pointers AI round
s is a string of letters and digits.
A palindrome reads the same from left to right as from right to left. A substring is a stretch of s taken without gaps, at least one character long. An upper case letter and its lower case are different characters.
Return the longest substring of `s` that is a palindrome. When several are equally long, any of them is right.
Example 1
Input: s = "xracecarbz"
One right answer: "racecar"
racecar reads the same both ways, and no longer stretch of s does.
Example 2
Input: s = "noonday"
One right answer: "noon"
Example 3
Input: s = "Kayak"
One right answer: "aya"
Constraints
1 ≤ s.length ≤ 5000sholds only English letters, upper and lower case, and digits
Practice this in an AI round
30 minutes on this problem with an AI agent beside your code, then a report on your solution and how you used the agent.
Your first AI round is free.
Watch the explanation
More Two Pointers
- Trapping Rain WaterAI round · Hard
- 3SumAI round · Medium
- Container With Most WaterAI round · Medium
- Find the Duplicate NumberAI round · Medium
- Sort ColorsAI round · Medium