|
| 1 | +{ |
| 2 | + "problem_name": "palindrome_partitioning", |
| 3 | + "solution_class_name": "Solution", |
| 4 | + "problem_number": "131", |
| 5 | + "problem_title": "Palindrome Partitioning", |
| 6 | + "difficulty": "Medium", |
| 7 | + "topics": "String, Dynamic Programming, Backtracking", |
| 8 | + "readme_description": "Given a string `s`, partition `s` such that every substring of the partition is a **palindrome**. Return *all possible palindrome partitioning of `s`*.", |
| 9 | + "_readme_examples": { |
| 10 | + "list": [ |
| 11 | + { |
| 12 | + "content": "```\nInput: s = \"aab\"\nOutput: [[\"a\",\"a\",\"b\"],[\"aa\",\"b\"]]\n```" |
| 13 | + }, |
| 14 | + { |
| 15 | + "content": "```\nInput: s = \"a\"\nOutput: [[\"a\"]]\n```" |
| 16 | + } |
| 17 | + ] |
| 18 | + }, |
| 19 | + "readme_constraints": "- `1 <= s.length <= 16`\n- `s` contains only lowercase English letters.", |
| 20 | + "readme_additional": "", |
| 21 | + "helpers_imports": "", |
| 22 | + "helpers_content": "", |
| 23 | + "helpers_run_name": "partition", |
| 24 | + "helpers_run_signature": "(solution_class: type, s: str)", |
| 25 | + "helpers_run_body": " implementation = solution_class()\n return implementation.partition(s)", |
| 26 | + "helpers_assert_name": "partition", |
| 27 | + "helpers_assert_signature": "(result: list[list[str]], expected: list[list[str]]) -> bool", |
| 28 | + "helpers_assert_body": " # Sort inner lists and outer list for comparison\n # Note: Inner lists are partitions (lists of strings), order of partitions doesn't matter\n # Order of strings within a partition DOES matter (it must reconstruct s)\n # But wait, the problem says \"partition s\", so the order of substrings must match the order in s.\n # So we only need to sort the outer list of partitions.\n result_sorted = sorted(result)\n expected_sorted = sorted(expected)\n assert result_sorted == expected_sorted\n return True", |
| 29 | + "solution_imports": "", |
| 30 | + "solution_contents": "", |
| 31 | + "solution_class_content": "", |
| 32 | + "test_imports": "import pytest\nfrom leetcode_py import logged_test\nfrom .helpers import assert_partition, run_partition\nfrom .solution import Solution", |
| 33 | + "test_content": "", |
| 34 | + "test_class_name": "PalindromePartitioning", |
| 35 | + "test_class_content": " def setup_method(self):\n self.solution = Solution()", |
| 36 | + "_solution_methods": { |
| 37 | + "list": [ |
| 38 | + { |
| 39 | + "name": "partition", |
| 40 | + "signature": "(self, s: str) -> list[list[str]]", |
| 41 | + "body": " # TODO: Implement partition\n return []" |
| 42 | + } |
| 43 | + ] |
| 44 | + }, |
| 45 | + "_test_helper_methods": { |
| 46 | + "list": [ |
| 47 | + { |
| 48 | + "name": "setup_method", |
| 49 | + "parameters": "", |
| 50 | + "body": "self.solution = Solution()" |
| 51 | + } |
| 52 | + ] |
| 53 | + }, |
| 54 | + "_test_methods": { |
| 55 | + "list": [ |
| 56 | + { |
| 57 | + "name": "test_partition", |
| 58 | + "signature": "(self, s: str, expected: list[list[str]])", |
| 59 | + "parametrize": "s, expected", |
| 60 | + "test_cases": { |
| 61 | + "list": [ |
| 62 | + "('aab', [['a', 'a', 'b'], ['aa', 'b']])", |
| 63 | + "('a', [['a']])", |
| 64 | + "('ab', [['a', 'b']])", |
| 65 | + "('aa', [['a', 'a'], ['aa']])", |
| 66 | + "('abc', [['a', 'b', 'c']])", |
| 67 | + "('aba', [['a', 'b', 'a'], ['aba']])", |
| 68 | + "('aaa', [['a', 'a', 'a'], ['a', 'aa'], ['aa', 'a'], ['aaa']])", |
| 69 | + "('abba', [['a', 'b', 'b', 'a'], ['a', 'bb', 'a'], ['abba']])", |
| 70 | + "('zz', [['z', 'z'], ['zz']])", |
| 71 | + "('efe', [['e', 'f', 'e'], ['efe']])", |
| 72 | + "('xyx', [['x', 'y', 'x'], ['xyx']])", |
| 73 | + "('noon', [['n', 'o', 'o', 'n'], ['n', 'oo', 'n'], ['noon']])" |
| 74 | + ] |
| 75 | + }, |
| 76 | + "body": " result = run_partition(Solution, s)\n assert_partition(result, expected)" |
| 77 | + } |
| 78 | + ] |
| 79 | + }, |
| 80 | + "playground_imports": "from helpers import run_partition, assert_partition\nfrom solution import Solution", |
| 81 | + "playground_setup": "# Example test case\ns = 'aab'\nexpected = [['a', 'a', 'b'], ['aa', 'b']]", |
| 82 | + "playground_run": "result = run_partition(Solution, s)\nresult", |
| 83 | + "playground_assert": "assert_partition(result, expected)" |
| 84 | +} |
0 commit comments