Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

46. Longest Palindromic Substring

MediumDay 14 of 60Strings

Given a string s, return its longest substring that reads the same forwards and backwards (a palindrome). If several palindromes share the maximum length, any one of them is accepted.

Example 1
Input: s = "babad"
Output: "bab"
"aba" is also a valid answer.
Example 2
Input: s = "cbbd"
Output: "bb"
Constraints
  • 1 <= s.length <= 1000
  • `s` contains only digits and English letters
Hints
Frequently asked at: Amazon, Microsoft, Google, Adobe, Samsung
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min