CB scholarship binary search

3 test cases are showing wrong answer

the logic of your code is correct. But it is failing for large values of variables.

The problem is with the multiplication:
mid * y and (n-mid)*x;

Here the operands x, y and mid are of integer data type.

If you multiply two integer values, the result will be an integer value.

But the actual result of multiplication is coming out in a range greater than that of integer.
So, this code returns wrong value of multiplication(because here you have integer overflow).

Solution:
long long int mid;

As we have changed the type of mid to long long int, so now the result will be of long long int type. Hence, integer overflow his been handled.

Hope, this would help.
Give a like if you are satisfied with my answer.:wink:

thank you, that was a detailed answer!