Code is passing sample testcase but failing all the tescases on submission

Link to the code : https://ide.codingblocks.com/s/232895
Pls help me to debug the code and let me know where I am wrong. Thanks!

@18bcs036
Change line 20 to long long int start = book[n-1];

1 Like

Waoh! Thank you so much. I was struck on this qs from a long time. Starting from book[n-1] is a more optimal solution just wondering why it’s not working if I start from 0 ?

@18bcs036
If you take start as 0, for some testcase your mid might go below book[n-1] and checkconfig might return true in such case. Your ans will be wrong in such case.
Consider this testcase
1
4 4
1 2 3 5
output should be β€œ5” but if you start with start=0, ans will be β€œ1”

Please mark it as resolved if you got the logic.