Skip to interview prep
Apexed

71. Longest Palindromic Substring

MediumString algorithms

Return the longest substring of s that is a palindrome. If several have the maximum length, return the one that starts first.

Example 1

Input: s = "babad"
Output: "bab"

Example 2

Input: s = "cbbd"
Output: "bb"

Constraints

  • 1 ≤ s.length ≤ 1000

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 4 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Longest Palindromic Substring — coding interview practice — Apexed