Be the first user to complete this post

  • 0
Add to List

Check if array is sorted using recursion

Objec­tive:  Given an array of integers write a recursive solution to check if the array is sorted.

Example:

int [] a = {1,2,3,4};
Output: true

int [] a = {1,2,3,4,2};
Output: false

Approach: This problem can easily be solved in a single iteration by just comparing adjacent elements. The fun part is to write the recursive solution. The code is self-explanatory.

Code:


Output:

true



Also Read: