Sorted Array failing 1/3 test case


https://online.codingblocks.com/player/28486/content/4669/4731

@mddanish hey danish your code is falling to handle this case
4
-4 5 0 17
output is true
but it not sorted so it should be false.

Hello @mddanish,

There is a logical error in your code.
Your code will always return true, irrespective of the elements of array.
Also, the following two statements will never execute:

  1. if(arr[n-1]>arr[n]) return false;

  2. if(n==k-1) return true; // returning back

If you wants to know the reason then i would suggest you to dry run your code on any input testcase.

Hope, this would help.
Give a like, if you are satisfied.