Longest Palindromic Substring

A palindromic substring is a contiguous slice of a string that reads the same forwards and backwards (for example "aba" or "bb"). Given a string s, return the…

A **palindromic substring** is a contiguous slice of a string that reads the same forwards and backwards (for example `"aba"` or `"bb"`). Given a string `s`, return the **longest** palindromic substring of `s`. Use the **expand-around-center** technique: every palindrome is symmetric about a center. There are `2n - 1` centers — one at each index (odd-length palindromes) and one between each pair of adjacent indices (even-length palindromes). From each center, expand two pointers outward while the characters match; the widest match is that center's longest palindrome. Indexing is **0-based**. When more than one palindrome shares the maximum length, return the **leftmost** one (the candidate with the smallest starting index). Scanning centers left to right and replacing the best only for a strictly longer candidate implements that rule. For example, `"babad"` has both `"bab"` and `"aba"` of length 3, so the answer is `"bab"`.

- `1 <= s.length <= 1000` - `s` consists of ASCII letters and digits. - The interactive visualizer accepts at most 20 characters; longer valid judge inputs remain execution-only.

Example 1: input s = "babad"; output bab. Both "bab" and "aba" are length-3 palindromes; "bab" is found first scanning left to right.

Example 2: input s = "cbbd"; output bb. The even center between the two "b"s expands to "bb", the longest palindrome.

Example 3: input s = "aba"; output aba. The whole string is already a palindrome.

Category: Strings. Topic: strings. Difficulty: Medium. Patterns: string-processing.