Arrays and Hashing Array basics
52. Check Whether an Array Is Sorted
You are given an array of integers nums. Return true if its elements are in non-decreasing order, and
false otherwise.
Non-decreasing order means that every element is greater than or equal to the element just before it. Equal
neighbours are allowed, so [2, 2, 3] is in order. An array with a single element is always in order.
Example 1
Input: nums = [-4, -1, 0, 0, 7]
trueExplanation: Every element is at least as large as the one before it. The two zeros are equal neighbours, and equal neighbours are allowed.
Example 2
Input: nums = [2, 6, 9, 4, 11]
falseExplanation: The 4 comes right after the 9 and is smaller than it. The array starts small and ends large, but that one step down is enough to break the order.
Example 3
Input: nums = [1000000000, -1000000000]
falseExplanation: The largest value allowed comes first and the smallest comes second, so the order goes down.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ nums.length ≤ 105-109 ≤ nums[i] ≤ 109
Clarifying questions
What you would ask an interviewer before writing any code.