150 principais entrevistasMédio

Substring palindrômica mais longa

Guia detalhado e implementação de Python para o problema de 'Substring palindrômica mais longa'.

Declaração do problema

Médio

Dada uma string s, retorne a substring palindrômica mais longa em s.

Escreva uma função longestPalindrome(s: str) -> str.

Restrições
  • 1 <= len(s) <= 1000
  • s consists of only digits and English letters

Exemplos

Example 1
Input
s = "babad"
Output
"bab"
Explanation

"aba" is also a valid answer.

Example 2
Input
s = "cbbd"
Output
"bb"
Explanation

The longest palindromic substring is "bb".

Need a Hint?
Considere usar estruturas de dados 1D específicas de DP, como conjuntos ou heaps.
Edge Cases to Watch
  • Estruturas de entrada vazias
  • Entradas de elemento único
  • Grandes limites numéricos

Pronto para resolver?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Abrir no Editor
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

Recursos Python recomendados

Expanda seu conhecimento com tutoriais interativos relacionados, folhas de dicas e comparações de código.