{ "id": 2892, "name": "check_if_array_is_good", "difficulty": "Easy", "link": "https://leetcode.com/problems/check-if-array-is-good/", "date": "1688774400000", "task_description": "You are given an integer array `nums`. We consider an array **good **if it is a permutation of an array `base[n]`. `base[n] = [1, 2, ..., n - 1, n, n] `(in other words, it is an array of length `n + 1` which contains `1` to `n - 1 `exactly once, plus two occurrences of `n`). For example, `base[1] = [1, 1]` and` base[3] = [1, 2, 3, 3]`. Return `true` _if the given array is good, otherwise return__ _`false`. **Note: **A permutation of integers represents an arrangement of these numbers. **Example 1:** ``` **Input:** nums = [2, 1, 3] **Output:** false **Explanation:** Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. However, base[3] has four elements but array nums has three. Therefore, it can not be a permutation of base[3] = [1, 2, 3, 3]. So the answer is false. ``` **Example 2:** ``` **Input:** nums = [1, 3, 3, 2] **Output:** true **Explanation:** Since the maximum element of the array is 3, the only candidate n for which this array could be a permutation of base[n], is n = 3. It can be seen that nums is a permutation of base[3] = [1, 2, 3, 3] (by swapping the second and fourth elements in nums, we reach base[3]). Therefore, the answer is true. ``` **Example 3:** ``` **Input:** nums = [1, 1] **Output:** true **Explanation:** Since the maximum element of the array is 1, the only candidate n for which this array could be a permutation of base[n], is n = 1. It can be seen that nums is a permutation of base[1] = [1, 1]. Therefore, the answer is true. ``` **Example 4:** ``` **Input:** nums = [3, 4, 4, 1, 2, 1] **Output:** false **Explanation:** Since the maximum element of the array is 4, the only candidate n for which this array could be a permutation of base[n], is n = 4. However, base[4] has five elements but array nums has six. Therefore, it can not be a permutation of base[4] = [1, 2, 3, 4, 4]. So the answer is false. ``` **Constraints:** `1 <= nums.length <= 100` `1 <= num[i] <= 200`", "public_test_cases": [ { "label": "Example 1", "input": "nums = [2, 1, 3]", "output": "false " }, { "label": "Example 2", "input": "nums = [1, 3, 3, 2]", "output": "true " }, { "label": "Example 3", "input": "nums = [1, 1]", "output": "true " }, { "label": "Example 4", "input": "nums = [3, 4, 4, 1, 2, 1]", "output": "false " } ], "private_test_cases": [ { "input": [ 43, 16, 46, 25, 29, 12, 23, 27, 9, 36, 8, 11, 52, 17, 3, 50, 35, 51, 31, 20, 33, 22, 26, 37, 21, 34, 47, 41, 28, 18, 15, 2, 44, 4, 6, 10, 39, 19, 40, 32, 30, 1, 24, 7, 13, 48, 5, 49, 14, 38, 45, 42 ], "output": false }, { "input": [ 5, 1, 2, 4, 3 ], "output": false }, { "input": [ 12, 8, 5, 4, 19, 16, 7, 9, 13, 11, 10, 14, 17, 3, 2, 18, 15, 6, 1 ], "output": false }, { "input": [ 24, 1, 31, 32, 16, 37, 3, 81, 50, 52, 4, 55, 69, 80, 41, 45, 42, 60, 59, 19, 18, 40, 7, 61, 8, 34, 22, 20, 75, 48, 77, 72, 76, 78, 63, 25, 15, 65, 35, 53, 39, 11, 57, 5, 58, 47, 26, 62, 10, 28, 29, 14, 71, 33, 82, 83, 44, 66, 79, 17, 38, 68, 23, 6, 30, 54, 64, 2, 43, 67, 36, 74, 21, 13, 70, 9, 51, 49, 27, 46, 12, 73, 56 ], "output": false }, { "input": [ 2, 85, 84, 18, 65, 63, 23, 19, 81, 5, 49, 60, 26, 9, 7, 61, 39, 62, 35, 4, 21, 76, 44, 73, 54, 69, 47, 11, 59, 55, 89, 80, 50, 83, 33, 57, 25, 3, 68, 75, 64, 16, 22, 42, 1, 29, 17, 31, 37, 40, 45, 51, 13, 43, 86, 30, 52, 41, 82, 10, 53, 14, 38, 15, 32, 28, 72, 77, 56, 58, 34, 79, 70, 90, 88, 24, 87, 48, 20, 12, 66, 78, 27, 91, 71, 6, 8, 67, 36, 74, 46 ], "output": false }, { "input": [ 33, 92, 94, 81, 22, 60, 23, 88, 29, 31, 1, 42, 83, 9, 16, 21, 19, 51, 86, 52, 17, 57, 43, 18, 67, 46, 13, 54, 89, 69, 11, 27, 28, 85, 50, 30, 80, 56, 34, 79, 55, 72, 36, 62, 87, 84, 49, 58, 90, 47, 75, 66, 7, 14, 71, 40, 93, 77, 70, 38, 32, 61, 24, 39, 45, 44, 48, 68, 5, 65, 76, 10, 35, 6, 78, 95, 41, 3, 64, 73, 91, 20, 15, 82, 74, 37, 63, 2, 12, 8, 26, 59, 25, 4, 53 ], "output": false }, { "input": [ 7, 13, 24, 22, 15, 4, 25, 6, 20, 9, 17, 3, 12, 18, 21, 14, 1, 2, 8, 5, 16, 19, 10, 23, 11, 25 ], "output": true }, { "input": [ 12, 3, 4, 8, 16, 17, 2, 9, 13, 7, 18, 1, 11, 14, 5, 10, 6, 15 ], "output": false }, { "input": [ 1, 5, 17, 10, 9, 11, 14, 20, 3, 18, 6, 7, 12, 19, 15, 13, 4, 2, 8, 16 ], "output": false }, { "input": [ 6, 67, 70, 21, 75, 53, 48, 16, 77, 66, 74, 26, 38, 30, 4, 32, 56, 63, 55, 81, 44, 46, 54, 60, 72, 57, 65, 19, 37, 52, 27, 50, 78, 59, 39, 8, 12, 13, 58, 20, 68, 10, 76, 49, 34, 79, 9, 71, 14, 28, 42, 45, 61, 5, 31, 29, 36, 7, 41, 24, 3, 15, 17, 2, 40, 22, 33, 80, 25, 73, 18, 64, 51, 11, 69, 47, 23, 35, 43, 1, 62 ], "output": false } ], "haskell_template": "isGood :: [Int] -> Bool\nisGood nums ", "ocaml_template": "let isGood (nums: int list) : bool = ", "scala_template": "def isGood(nums: List[Int]): Boolean = { \n \n}", "java_template": "public static boolean isGood(List nums) {\n\n}", "python_template": "class Solution(object):\n def isGood(self, nums):\n \"\"\"\n :type nums: List[int]\n :rtype: bool\n \"\"\"\n " }