Top 150 Interview簡単

Palindrome Partitioning

Detailed guide and Python implementation for the 'Palindrome Partitioning' problem.

問題提起

簡単

Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible palindrome partitioning of s.

Implement a function partition(s: str) -> list.

制約
  • 1 <= s.length <= 16
  • s contains only lowercase English letters

Example 1
Input
"aab"
Output
[["a","a","b"],["aa","b"]]
Explanation

"a","a","b" are all palindromes. "aa" is a palindrome and "b" is a palindrome. These are the only two valid partitions.

Example 2
Input
"a"
Output
[["a"]]
Explanation

A single character is always a palindrome.

Need a Hint?
Consider using Backtracking-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

解決する準備はできましたか?

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

エディタで開く
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

推奨される Python リソース

関連するインタラクティブなチュートリアル、チートシート、コード比較で知識を深めてください。