CoolFace
Datasetpublic

TheRealSamuel/LeetCodeProblem

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes564downloads
1{2    "id": 2785,3    "name": "semi_ordered_permutation",4    "difficulty": "Easy",5    "link": "https://leetcode.com/problems/semi-ordered-permutation/",6    "date": "2023-05-28 00:00:00",7    "task_description": "You are given a **0-indexed** permutation of `n` integers `nums`. A permutation is called **semi-ordered** if the first number equals `1` and the last number equals `n`. You can perform the below operation as many times as you want until you make `nums` a **semi-ordered** permutation: Pick two adjacent elements in `nums`, then swap them. Return _the minimum number of operations to make _`nums`_ a **semi-ordered permutation**_. A **permutation** is a sequence of integers from `1` to `n` of length `n` containing each number exactly once. **Example 1:** ``` **Input:** nums = [2,1,4,3] **Output:** 2 **Explanation:** We can make the permutation semi-ordered using these sequence of operations: 1 - swap i = 0 and j = 1. The permutation becomes [1,2,4,3]. 2 - swap i = 2 and j = 3. The permutation becomes [1,2,3,4]. It can be proved that there is no sequence of less than two operations that make nums a semi-ordered permutation. ``` **Example 2:** ``` **Input:** nums = [2,4,1,3] **Output:** 3 **Explanation:** We can make the permutation semi-ordered using these sequence of operations: 1 - swap i = 1 and j = 2. The permutation becomes [2,1,4,3]. 2 - swap i = 0 and j = 1. The permutation becomes [1,2,4,3]. 3 - swap i = 2 and j = 3. The permutation becomes [1,2,3,4]. It can be proved that there is no sequence of less than three operations that make nums a semi-ordered permutation. ``` **Example 3:** ``` **Input:** nums = [1,3,4,2,5] **Output:** 0 **Explanation:** The permutation is already a semi-ordered permutation. ``` **Constraints:** `2 <= nums.length == n <= 50` `1 <= nums[i] <= 50` `nums is a permutation.`",8    "public_test_cases": [9        {10            "label": "Example 1",11            "input": "nums = [2,1,4,3]",12            "output": "2 "13        },14        {15            "label": "Example 2",16            "input": "nums = [2,4,1,3]",17            "output": "3 "18        },19        {20            "label": "Example 3",21            "input": "nums = [1,3,4,2,5]",22            "output": "0 "23        }24    ],25    "private_test_cases": [26        {27            "input": [28                7,29                18,30                21,31                5,32                24,33                10,34                1,35                12,36                17,37                2,38                9,39                8,40                20,41                15,42                22,43                23,44                6,45                16,46                13,47                4,48                3,49                19,50                14,51                1152            ],53            "output": 2454        },55        {56            "input": [57                10,58                15,59                7,60                11,61                13,62                14,63                3,64                2,65                16,66                5,67                12,68                4,69                8,70                9,71                1,72                673            ],74            "output": 2075        },76        {77            "input": [78                3,79                5,80                4,81                1,82                283            ],84            "output": 585        },86        {87            "input": [88                30,89                5,90                2,91                6,92                28,93                26,94                21,95                32,96                18,97                27,98                8,99                24,100                16,101                34,102                14,103                19,104                37,105                4,106                23,107                7,108                11,109                1,110                31,111                20,112                35,113                33,114                36,115                17,116                29,117                25,118                13,119                22,120                10,121                12,122                3,123                9,124                15125            ],126            "output": 40127        },128        {129            "input": [130                25,131                6,132                11,133                10,134                1,135                32,136                14,137                39,138                35,139                15,140                20,141                4,142                33,143                22,144                24,145                31,146                37,147                34,148                19,149                23,150                8,151                26,152                36,153                12,154                27,155                21,156                16,157                7,158                9,159                29,160                3,161                2,162                18,163                5,164                38,165                13,166                28,167                30,168                17169            ],170            "output": 35171        }172    ],173    "haskell_template": "semiOrderedPermutation :: [Int] -> Int\nsemiOrderedPermutation nums ",174    "ocaml_template": "let semiOrderedPermutation (nums: int list) : int =  ",175    "scala_template": "def semiOrderedPermutation(nums: List[Int]): Int = { \n    \n}",176    "java_template": "class Solution {\n    public int semiOrderedPermutation(int[] nums) {\n        \n    }\n}",177    "python_template": "class Solution(object):\n    def semiOrderedPermutation(self, nums):\n        \"\"\"\n        :type nums: List[int]\n        :rtype: int\n        \"\"\"\n        "178}