743. Check if the Array is Sorted I

Given an array arr of size n, the task is to check if the given array is sorted in (ascending / Increasing / Non-decreasing) order. If the array is sorted then return True, else return False.

Example 1:

Input: n = 5, arr = [1,2,3,4,5]

Output: True

Explanation: The given array is sorted i.e Every element in the array is smaller than or equals to its next values, So the answer is True.

Example 2:

Input: n = 5, arr = [5,4,6,7,8]

Output: False

Explanation: The given array is Not sorted i.e Every element in the array is not smaller than or equal to its next values, So the answer is False. Here element 5 is not smaller than or equal to its future elements.

Now Your Turn!

Pick the correct output for the given input

Input: n = 5, arr = [5,4,3,2,1]

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 ≤ n ≤ 106
  • - 109 ≤ arr[i] ≤ 109

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

0
class Solution {
public:
bool arraySortedOrNot(int arr[], int n) {
 
}
};
 
Test Case

Input:

Nums