|
| 1 | +{ |
| 2 | + "problem_name": "permutations", |
| 3 | + "solution_class_name": "Solution", |
| 4 | + "problem_number": "46", |
| 5 | + "problem_title": "Permutations", |
| 6 | + "difficulty": "Medium", |
| 7 | + "topics": "Array, Backtracking", |
| 8 | + "tags": ["grind-75"], |
| 9 | + "readme_description": "Given an array `nums` of distinct integers, return all the possible permutations. You can return the answer in any order.", |
| 10 | + "readme_examples": [ |
| 11 | + { |
| 12 | + "content": "```\nInput: nums = [1,2,3]\nOutput: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]\n```" |
| 13 | + }, |
| 14 | + { "content": "```\nInput: nums = [0,1]\nOutput: [[0,1],[1,0]]\n```" }, |
| 15 | + { "content": "```\nInput: nums = [1]\nOutput: [[1]]\n```" } |
| 16 | + ], |
| 17 | + "readme_constraints": "- 1 <= nums.length <= 6\n- -10 <= nums[i] <= 10\n- All the integers of nums are unique.", |
| 18 | + "readme_additional": "", |
| 19 | + "solution_imports": "", |
| 20 | + "solution_methods": [ |
| 21 | + { |
| 22 | + "name": "permute", |
| 23 | + "parameters": "nums: list[int]", |
| 24 | + "return_type": "list[list[int]]", |
| 25 | + "dummy_return": "[]" |
| 26 | + } |
| 27 | + ], |
| 28 | + "test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution", |
| 29 | + "test_class_name": "TestPermutations", |
| 30 | + "test_helper_methods": [ |
| 31 | + { "name": "setup_method", "parameters": "", "body": "self.solution = Solution()" } |
| 32 | + ], |
| 33 | + "test_methods": [ |
| 34 | + { |
| 35 | + "name": "test_permute", |
| 36 | + "parametrize": "nums, expected", |
| 37 | + "parametrize_typed": "nums: list[int], expected: list[list[int]]", |
| 38 | + "test_cases": "[([1, 2, 3], [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]), ([0, 1], [[0, 1], [1, 0]]), ([1], [[1]])]", |
| 39 | + "body": "result = self.solution.permute(nums)\n # Sort both result and expected for comparison since order doesn't matter\n result_sorted = [sorted(perm) for perm in result]\n expected_sorted = [sorted(perm) for perm in expected]\n result_sorted.sort()\n expected_sorted.sort()\n assert len(result) == len(expected)\n assert result_sorted == expected_sorted" |
| 40 | + } |
| 41 | + ], |
| 42 | + "playground_imports": "from solution import Solution", |
| 43 | + "playground_test_case": "# Example test case\nnums = [1, 2, 3]\nexpected = [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]", |
| 44 | + "playground_execution": "result = Solution().permute(nums)\nresult", |
| 45 | + "playground_assertion": "# Check that we have the right number of permutations\nassert len(result) == len(expected)\n# Sort for comparison since order doesn't matter\nresult_sorted = [sorted(perm) for perm in result]\nexpected_sorted = [sorted(perm) for perm in expected]\nresult_sorted.sort()\nexpected_sorted.sort()\nassert result_sorted == expected_sorted" |
| 46 | +} |
0 commit comments