Sorted Array (problem in takin input)

code link : https://pastebin.com/f3vnPdaY

this is link to my code on my ide I am getting a time out and on the ide provided it is giving no output , I am a bit confused here about the input forma please explain, where I am going wrong

There are 2 problems in your code. Let’s talk about them one by one.

  1. While taking the input in the array, the temp variable is not required, a normal for loop will suffice.
  2. In the isSorted function you are not checking for the cases where the adjacent values are equal. For eg, the input array is 1 1 2 3 4, your code will return false, whereas, the right answer is true. In the line number 11, change a[0] < a[1] && isSorted( a+1, n - 1) to a[0] <= a[1] && isSorted( a+1, n - 1) and your code will work fine.

Hope this helps.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.