Le migliori 150 intervisteMedio

Sottostringa palindromica più lunga

Guida dettagliata e implementazione Python per il problema della "sottostringa palindromica più lunga".

Dichiarazione del problema

Medio

Data una stringa s, restituisce la sottostringa palindromica più lunga in s.

Scrivi una funzione longestPalindrome(s: str) -> str.

Vincoli
  • 1 <= len(s) <= 1000
  • s consists of only digits and English letters

Esempi

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?
Prendi in considerazione l'utilizzo di strutture dati specifiche per DP 1D come set o heap.
Edge Cases to Watch
  • Strutture di input vuote
  • Ingressi a elemento singolo
  • Grandi limiti numerici

Pronto a risolvere?

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

Apri nell'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

Risorse Python consigliate

Espandi le tue conoscenze con tutorial interattivi, foglietti illustrativi e confronti di codici correlati.