Grokking LinkedIn Coding Interview
Ask Author
Back to course home

0% completed

Vote For New Content
 Manuel
I dont understand the comparison if (num > x) instead of if (num > x/2)

Manuel

Jan 8, 2025

As you first stated sqrt (x) is in the range 0 - x/2

Then, why are you doing this verification if (num > x) instead of if (num > x/2) ?

Thanks

0

0

Comments
Comments
S
semjase77 a month ago

Because num doesnt refer to the sqrt(x) but to midmidwhere mid is a potential integer value of sqt(x) and num is the square of that value . If num > x it means the value mid is to high to be the integer part of sqrt(x) so we need to keep doing binary search for the ...

On this page