why getting worng ans…link http://www.codechef.com/viewsolution/1702622
10 8 7 5 2 13 7 15 3 1 10 2 2
The answer is 0 while you return -1.