Check if array is sorted using recursion

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


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 single iteration by just comparing adjacent elements. Fun part is to write the recursive solution. Code is self explanatory.




Top Companies Interview Questions..-

Google Microsoft Amazon Facebook more..

If you find anything incorrect or you feel that there is any better approach to solve the above problem, please write comment.

You may also like...

%d bloggers like this: