We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
issue with permute_recursive
### What would you like to share?

Your code looks mostly correct, but there's one issue in the `permute_recursive` function due to the modification of the `nums` list. Lists in Python are mutable, and when you use `nums.pop(0)`, it modifies the original `nums` list. This can lead to incorrect results and even an infinite loop.

To fix this, you should pass a copy of the `nums` list to the recursive function. Here's the corrected `permute_recursive` function:


def permute_recursive(nums: list[int]) -> list[list[int]]:
    """
    Return all permutations.

    >>> permute_recursive([1, 2, 3])
    [[3, 2, 1], [2, 3, 1], [1, 3, 2], [3, 1, 2], [2, 1, 3], [1, 2, 3]]
    """
    result: list[list[int]] = []
    if len(nums) == 0:
        return [[]]
    for _ in range(len(nums)):
        n = nums.pop(0)
        permutations = permute_recursive(nums[:])  # Make a copy of nums
        for perm in permutations:
            perm.append(n)
        result.extend(permutations)
        nums.append(n)
    return result
```

With this modification, your code should work correctly for both `permute_recursive` and `permute_backtrack`.

### Additional information

_No response_

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `data_structures/arrays/permutations.py`
Content:
```
1 def permute_recursive(nums: list[int]) -> list[list[int]]:
2     """
3     Return all permutations.
4 
5     >>> permute_recursive([1, 2, 3])
6     [[3, 2, 1], [2, 3, 1], [1, 3, 2], [3, 1, 2], [2, 1, 3], [1, 2, 3]]
7     """
8     result: list[list[int]] = []
9     if len(nums) == 0:
10         return [[]]
11     for _ in range(len(nums)):
12         n = nums.pop(0)
13         permutations = permute_recursive(nums)
14         for perm in permutations:
15             perm.append(n)
16         result.extend(permutations)
17         nums.append(n)
18     return result
19 
20 
21 def permute_backtrack(nums: list[int]) -> list[list[int]]:
22     """
23     Return all permutations of the given list.
24 
25     >>> permute_backtrack([1, 2, 3])
26     [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 2, 1], [3, 1, 2]]
27     """
28 
29     def backtrack(start: int) -> None:
30         if start == len(nums) - 1:
31             output.append(nums[:])
32         else:
33             for i in range(start, len(nums)):
34                 nums[start], nums[i] = nums[i], nums[start]
35                 backtrack(start + 1)
36                 nums[start], nums[i] = nums[i], nums[start]  # backtrack
37 
38     output: list[list[int]] = []
39     backtrack(0)
40     return output
41 
42 
43 if __name__ == "__main__":
44     import doctest
45 
46     res = permute_backtrack([1, 2, 3])
47     print(res)
48     doctest.testmod()
49
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/data_structures/arrays/permutations.py b/data_structures/arrays/permutations.py
--- a/data_structures/arrays/permutations.py
+++ b/data_structures/arrays/permutations.py
@@ -10,7 +10,7 @@
         return [[]]
     for _ in range(len(nums)):
         n = nums.pop(0)
-        permutations = permute_recursive(nums)
+        permutations = permute_recursive(nums.copy())
         for perm in permutations:
             perm.append(n)
         result.extend(permutations)
@@ -43,6 +43,6 @@
 if __name__ == "__main__":
     import doctest
 
-    res = permute_backtrack([1, 2, 3])
-    print(res)
+    result = permute_backtrack([1, 2, 3])
+    print(result)
     doctest.testmod()

{"golden_diff": "diff --git a/data_structures/arrays/permutations.py b/data_structures/arrays/permutations.py\n--- a/data_structures/arrays/permutations.py\n+++ b/data_structures/arrays/permutations.py\n@@ -10,7 +10,7 @@\n         return [[]]\n     for _ in range(len(nums)):\n         n = nums.pop(0)\n-        permutations = permute_recursive(nums)\n+        permutations = permute_recursive(nums.copy())\n         for perm in permutations:\n             perm.append(n)\n         result.extend(permutations)\n@@ -43,6 +43,6 @@\n if __name__ == \"__main__\":\n     import doctest\n \n-    res = permute_backtrack([1, 2, 3])\n-    print(res)\n+    result = permute_backtrack([1, 2, 3])\n+    print(result)\n     doctest.testmod()\n", "issue": "issue with permute_recursive\n### What would you like to share?\n\nYour code looks mostly correct, but there's one issue in the `permute_recursive` function due to the modification of the `nums` list. Lists in Python are mutable, and when you use `nums.pop(0)`, it modifies the original `nums` list. This can lead to incorrect results and even an infinite loop.\r\n\r\nTo fix this, you should pass a copy of the `nums` list to the recursive function. Here's the corrected `permute_recursive` function:\r\n\r\n\r\ndef permute_recursive(nums: list[int]) -> list[list[int]]:\r\n    \"\"\"\r\n    Return all permutations.\r\n\r\n    >>> permute_recursive([1, 2, 3])\r\n    [[3, 2, 1], [2, 3, 1], [1, 3, 2], [3, 1, 2], [2, 1, 3], [1, 2, 3]]\r\n    \"\"\"\r\n    result: list[list[int]] = []\r\n    if len(nums) == 0:\r\n        return [[]]\r\n    for _ in range(len(nums)):\r\n        n = nums.pop(0)\r\n        permutations = permute_recursive(nums[:])  # Make a copy of nums\r\n        for perm in permutations:\r\n            perm.append(n)\r\n        result.extend(permutations)\r\n        nums.append(n)\r\n    return result\r\n```\r\n\r\nWith this modification, your code should work correctly for both `permute_recursive` and `permute_backtrack`.\n\n### Additional information\n\n_No response_\n", "before_files": [{"content": "def permute_recursive(nums: list[int]) -> list[list[int]]:\n    \"\"\"\n    Return all permutations.\n\n    >>> permute_recursive([1, 2, 3])\n    [[3, 2, 1], [2, 3, 1], [1, 3, 2], [3, 1, 2], [2, 1, 3], [1, 2, 3]]\n    \"\"\"\n    result: list[list[int]] = []\n    if len(nums) == 0:\n        return [[]]\n    for _ in range(len(nums)):\n        n = nums.pop(0)\n        permutations = permute_recursive(nums)\n        for perm in permutations:\n            perm.append(n)\n        result.extend(permutations)\n        nums.append(n)\n    return result\n\n\ndef permute_backtrack(nums: list[int]) -> list[list[int]]:\n    \"\"\"\n    Return all permutations of the given list.\n\n    >>> permute_backtrack([1, 2, 3])\n    [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 2, 1], [3, 1, 2]]\n    \"\"\"\n\n    def backtrack(start: int) -> None:\n        if start == len(nums) - 1:\n            output.append(nums[:])\n        else:\n            for i in range(start, len(nums)):\n                nums[start], nums[i] = nums[i], nums[start]\n                backtrack(start + 1)\n                nums[start], nums[i] = nums[i], nums[start]  # backtrack\n\n    output: list[list[int]] = []\n    backtrack(0)\n    return output\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    res = permute_backtrack([1, 2, 3])\n    print(res)\n    doctest.testmod()\n", "path": "data_structures/arrays/permutations.py"}], "after_files": [{"content": "def permute_recursive(nums: list[int]) -> list[list[int]]:\n    \"\"\"\n    Return all permutations.\n\n    >>> permute_recursive([1, 2, 3])\n    [[3, 2, 1], [2, 3, 1], [1, 3, 2], [3, 1, 2], [2, 1, 3], [1, 2, 3]]\n    \"\"\"\n    result: list[list[int]] = []\n    if len(nums) == 0:\n        return [[]]\n    for _ in range(len(nums)):\n        n = nums.pop(0)\n        permutations = permute_recursive(nums.copy())\n        for perm in permutations:\n            perm.append(n)\n        result.extend(permutations)\n        nums.append(n)\n    return result\n\n\ndef permute_backtrack(nums: list[int]) -> list[list[int]]:\n    \"\"\"\n    Return all permutations of the given list.\n\n    >>> permute_backtrack([1, 2, 3])\n    [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 2, 1], [3, 1, 2]]\n    \"\"\"\n\n    def backtrack(start: int) -> None:\n        if start == len(nums) - 1:\n            output.append(nums[:])\n        else:\n            for i in range(start, len(nums)):\n                nums[start], nums[i] = nums[i], nums[start]\n                backtrack(start + 1)\n                nums[start], nums[i] = nums[i], nums[start]  # backtrack\n\n    output: list[list[int]] = []\n    backtrack(0)\n    return output\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    result = permute_backtrack([1, 2, 3])\n    print(result)\n    doctest.testmod()\n", "path": "data_structures/arrays/permutations.py"}]}