Please spot the mistake in my code
question link https://leetcode.com/explore/challenge/card/november-leetcoding-challenge/564/week-1-november-1st-november-7th/3521/
my code link—>
Please spot the mistake in my code
question link https://leetcode.com/explore/challenge/card/november-leetcoding-challenge/564/week-1-november-1st-november-7th/3521/
my code link—>
Hey @coderajay03
else{
high=mid-1;
if(ss>mid)//updated
ss=mid;//updated
}
If this resolves your query then please mark it as resolved 
in one suggestion I saw I could also have just returned low can u tell why so ? bcz that’s also gives correct answer
Yeah because ur loop will work till low<=high
so in last iteration low == high ,here low must satisfy the relation because it it doesn’t then we go low=mid+1 that is high+1 and which means no solution
u can say loop converges to solution
Just see the iterations
i tried the dry run as u said and on last iteration low==high
our divisor was 4.
test–case nums = [1,2,5,9], threshold = 6
and on 4 sum is 1+1+2+3=7>6 so do mid+1(as u said)
that is 4+1=5 and we are returning that 5 only but u said mid+1 no solution
Oh my bad ,we are going towards left after getting a solution so we are not sure if we will get a solution in left ,
In last iterations
There are 2 cases
it satisfy threshold
so ans is low(same as mid) and we do high=mid-1
it doesn’t satisfy
so we do low=mid+1 ,since we are coming from right we know that it must be the correct ans
This is why returning low works
So here for
okay okay got it thankyou !!
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.