String•Pattern: Expand Around Center•Medium

Longest palindromic substring

Problem Intuition & Objective

Find the longest contiguous palindromic substring in a string.

Time ComplexityO(n²)
Optimal
Space ComplexityO(1)
Memory Bounds
Optimal Algorithmic Approach

Expand-around-center: 2n-1 possible centers, O(n) each in worst case.

Core Invariants & Edge Cases

  • Expand-around-center: for each index expand both odd and even centers
  • Track best start and length seen
  • DP is O(n²) time & space; expansion is O(n²) time O(1) space
Previous ProblemDesign an LRU CacheNext Problem Encode and decode strings (no delimiter in charset)

System Design & Architecture Roadmap

Coding interviews are only 50% of the bar. Master High-Level Design, distributed systems, and Object-Oriented LLD.