Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Longest Palindromic Substring

Medium
stringdynamic-programmingtwo-pointers

Given a string s, return the longest substring of s that is a palindrome. If several have the same length, return the one that appears first.

Input: one line s. Output: the longest palindromic substring.

Example 1
Input:
babad
Output:
bab

"aba" is also valid, but "bab" appears first.

Example 2
Input:
cbbd
Output:
bb

Constraints

  • 1 ≤ s.length ≤ 1000
  • s consists of digits and English letters.
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.