FrontendInterviews.dev

Loading problem…

63. Longest Palindromic Substring

Medium•
Acceptance: 70.00%
•
🔓3/3 Pro unlocks today

You're building a text analysis feature that needs to find the longest palindromic substring. This is useful for text processing, pattern matching, and string analysis.

Given a string s, return the longest palindromic substring in s.

A palindrome is a string that reads the same backward as forward.

Requirements

1. Basic Functionality

  • Find longest palindromic substring
  • Handle odd and even length palindromes
  • Return the substring itself
  • Handle edge cases (single character, no palindrome)

Example Usage

longestPalindrome("babad"); // "bab" or "aba"
longestPalindrome("cbbd");  // "bb"
longestPalindrome("a");     // "a"

Real-World Context

This problem models real text processing scenarios:

  • Text analysis: Find longest palindrome
  • Pattern matching: Palindrome detection
  • String processing: Substring analysis
  • Algorithm design: Expand around centers

Constraints

  • 1 <= s.length <= 1000
  • s consist of only digits and English letters
  • Return longest palindromic substring