706. Check if Array is Sorted (Recursive)

EasyRecursionRecursion

Given an integer array nums, determine whether it is sorted in non-decreasing order (each element is less than or equal to the next). Return true if it is, false otherwise. You must check this recursively, without loops.

Input: An integer array nums.

Output: Return a boolean: true or false (lowercase).

Examples

Example 1
Input: [1,2,3,4,5]
Output: true
Explanation: Each element <= next -> sorted.
Example 2
Input: [5,4,3,2,1]
Output: false
Explanation: 1 > 2 fails immediately.
Example 3
Input: [1,1,1,1]
Output: true
Explanation: Equal elements are allowed in non-decreasing order.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →