
Input: 'N' = 2, ‘ARR’ = [1, 2, 5, 6]
Output: 1
As we can see that ‘ARR’ is sorted in ascending order so the answer will be 1.
The first line will contain the integer 'T', denoting the number of test cases.
For each test case, the first line will contain ‘N’ the number of elements in array ‘ARR’ and the next line will contain all the elements of ‘ARR’.
For each test case, print 1 of the array is sorted else print 0.
You don't need to print anything. It has already been taken care of. Just implement the given function.
1 <= 'T' <= 10
1 <= 'N' <= 10^3
1 <= ‘ARR[i]’ <= 10^9
Time Limit: 1 sec
For each element except for the first, check if it is greater than or equal to the previous element. If it is then the array is sorted else not.
Algorithm :
Bool isSortedRec( int ARR[], int I, int LAST, int N)`
//where ‘LAST’ is the last element, ‘ARR[]’ is the array and ‘I’ is a current index, and ‘N’ is array size:
Bool isSorted(int ARR[], int N)
// where ‘ARR’ is the initial array and ‘N’ is the size of the array.
For each element except for the first check if it is greater than or equal to the previous element.