2892. Check if Array is Good
My accepted Python solution to LeetCode problem 2892, Check if Array is Good, running in 4ms.
- Difficulty: Easy
- Python
- Runtime 4ms
- Memory 17.5MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 4ms, memory 17.5MB, accepted 2026-01-01.
class Solution:
def isGood(self, nums: List[int]) -> bool:
n = len(nums) - 1 # n for base[n]
if n < 1:
return False
# Expected: [1, 2, ..., n-1, n, n]
# Check if sorted nums matches expected
nums.sort()
for i in range(n - 1):
if nums[i] != i + 1:
return False
# Last two elements should both be n
return nums[n - 1] == n and nums[n] == n