Check If Array Is Sorted - aloalgo

Check If Array Is Sorted

Very Easy

You are given an array of integers nums.

Your task is to determine if the array is sorted in non-decreasing order.

You may assume that:

  • The array contains at least one element.

Return true if the array is sorted in non-decreasing order, otherwise return false.

Example 1

Input
[1, 2, 3, 4, 5]
Output
True
Explanation:

The array is sorted in ascending order.

Example 2

Input
[1, 3, 2, 4, 5]
Output
False
Explanation:

The element 3 is greater than 2, so the array is not sorted.

Example 3

Input
[1, 1, 1, 1]
Output
True
Explanation:

All elements are equal, which counts as non-decreasing order.

Loading...
Input
[1, 2, 3, 4, 5]
Output
True

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!