> For the complete documentation index, see [llms.txt](https://breakpoint-journal.gitbook.io/breakpoint/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://breakpoint-journal.gitbook.io/breakpoint/leetcode/2784.-check-if-array-is-good.md).

# 2784. Check if Array is Good

https\://leetcode.com/problems/check-if-array-is-good/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.

**Constraints:**

* `1 <= nums.length <= 100`
* `1 <= num[i] <= 200`

{% embed url="<https://youtu.be/jrK0nCOAkp0>" %}

{% code title="solution.py" %}

```python
class Solution:
    def isGood(self, nums: List[int]) -> bool:
        x = len(nums) - 1
        m = {}
        for num in nums:
        if num > x:
            return False
        elif num not in m:
            m[num] = 1
        elif num in m:
            m[num] += 1
        
        if num == x:
            if m[num] <= 2:
                continue
            else:
                return False
            elif num != x and m[num] > 1:
                return False
        return m[x] == 2
        
```

{% endcode %}
