Leetcode Problem 2784. Check if Array is Good

2784. Check if Array is Good

Leetcode Solutions

Sorting and Validation

  1. Sort the array nums in ascending order.
  2. Check if the length of nums is equal to the maximum element in nums plus one.
  3. Iterate through the sorted array from the beginning to the second-to-last element.
  4. Verify that each element nums[i] is equal to i + 1.
  5. Check if the last two elements in the array are equal and equal to the length of the array minus one.
  6. If all checks pass, return true; otherwise, return false.
UML Thumbnail

Frequency Counting and Validation

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...