you're my go-to source for algos. I'm trying to go through your entire playlist of algos. So far you've taught me so much. Thanks a ton the quality vidoes and explanation!
This channel should be renamed to Amazing Whiteboard because this is one of the best algorithmic explanations i've seen lmao (even for such a simple question!). Really hope you can keep these videos coming :)
Remember that if no midpoint ends up being the square root, we're going to return left - 1 (left and right will be the same in that case, so returning right - 1 would also work), meaning that the number left and right end up on is one greater than it should be. The only way this would work is if we don't automatically eliminate the midpoint by making right one less than it. We have to leave open the possibility that the midpoint is the number we're eventually going to have to subtract one from.
Well explained! Three suggestions: - left = 2 (since we're already not going to consider 0 or 1) - right = x / 2 (since the square root will never be greater than half of x) - mid = Math.floor((left + right) / 2) (simpler equation)
Thanks for the video. The solution overflows for big int numbers, at least in C#. I worked around that by working with longs instead of ints and then casting the long to int before returning.
One thing to do to avoid integer overflow for other languages, compare mid with mid / x like " mid < mid / x" or "mid > mid / x". Thanks for the explanation.
Why not start the input array with N/3. We logically know that in N/2, the number near to the middle element of the array can never be the answer. Unless its 4 or -4.
I don't understand why after eliminating the numbers to the right, you still keep the midpoint but when eliminating numbers to the left, you get rid of it.. why the disparity
If there are any videos you'd like me to make or if you have any ideas on how to optimize this solution, let me know!
Played so many videos on the same problem, until I stopped here and understood finally. Awesome!!
Glad to hear. Thanks!
why don't we use mid as Math.floor((right+left)/2) just like the formula for finding average
you're my go-to source for algos. I'm trying to go through your entire playlist of algos. So far you've taught me so much. Thanks a ton the quality vidoes and explanation!
Good to hear!
This channel should be renamed to Amazing Whiteboard because this is one of the best algorithmic explanations i've seen lmao (even for such a simple question!). Really hope you can keep these videos coming :)
Haha. Thanks.
Well you went far, you have so much patience to do that for something so simple xD! GG Liked.
Thanks!
Thanks for the easiest explanation, just for doubt why we don't use right = mid - 1 but we used left = mid + 1
Remember that if no midpoint ends up being the square root, we're going to return left - 1 (left and right will be the same in that case, so returning right - 1 would also work), meaning that the number left and right end up on is one greater than it should be. The only way this would work is if we don't automatically eliminate the midpoint by making right one less than it. We have to leave open the possibility that the midpoint is the number we're eventually going to have to subtract one from.
@@TerribleWhiteboard Thanks :)
@@TerribleWhiteboard I think it should have more sense to eliminate always the midpoint to avoid confusion
you're the best. keep making these type of videos. thank you so much for taking the time in creating all this amazing content
Thanks!
Thanks for you video! Good explanation.
Probably Math.floor in line 14 is not necessary because integers are always rounded to floor by default?
No problem! You're right that in Java, integers are rounded down, but my videos are in Javascript.
@@TerribleWhiteboard Yep, i got it later haha thank you!
good video keep making more on leetocdes
Thanks!
Well explained!
Three suggestions:
- left = 2 (since we're already not going to consider 0 or 1)
- right = x / 2 (since the square root will never be greater than half of x)
- mid = Math.floor((left + right) / 2) (simpler equation)
before finishing the video, I clicked like because I liked your explanation
Love you!! You explained it so clearly & simple, thanks a lot
Thanks for the video. The solution overflows for big int numbers, at least in C#. I worked around that by working with longs instead of ints and then casting the long to int before returning.
One thing to do to avoid integer overflow for other languages, compare mid with mid / x like " mid < mid / x" or "mid > mid / x". Thanks for the explanation.
I think you can remove the "if(mid * mid === x)" statement on line 16 and make the while loop "while (left
such a good explanation. bro you are the best
very simple explanation, hope you will upload more leetcode problems.
THANK YOU FOR SPEAKING NON INDIAN ENGLISH! 🙏
Thanks for the explanation.., we can initialize right = x/2 bcz sqrt will never be b/w x/2 to x.
Why not start the input array with N/3. We logically know that in N/2, the number near to the middle element of the array can never be the answer. Unless its 4 or -4.
Why midpoint is not -> (left+right)/2
I don't understand why after eliminating the numbers to the right, you still keep the midpoint but when eliminating numbers to the left, you get rid of it.. why the disparity
I think you should rebrand to "Terrific Whiteboard"
Can't we make right x/2 since the square root of a number can't ever be bigger than half the number?
thank uu :)
but if i was programming in C++ i had RE, because i had int overflow (
You are f- awesome!
Nice
Thanks!
Hey, which app are you using to give an explanation?
let me give you a much easier solution
var mySqrt = function(x) {
let i = 1;
while(i*i
His solution is O(log(n)), yours is O(sqrt(n))