Your Input:
6 1 1 1 2 1 1
2
Expected output is -1
Seems like the program in expected output is wrong
Your Input:
6 1 1 1 2 1 1
2
Expected output is -1
Seems like the program in expected output is wrong
Your test case is wrong
The array is in non decreasing order.
Also, the array can have duplicate values.
Let me know, if I am clear to you.
Happy coding !!