Not submitting every test case

You weren’t sorting the array and checking condition was also incorrect, so I corrected your code.
Please take a look https://ide.codingblocks.com/s/240145

The input is given as a sorted array.

Oh sorry I missed that part.