Add Binary

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

Let me know how I can help you guys!!! Also if there's anything else you guys would want to see on this channel, leave it in the comments!

KevinNaughtonJr
Автор

Hi Kevin, I love to watch your videos daily with a cup of coffee, and afterwards trying myself in different problems. Please, keep doing all the tutorials as they are a great source of inspiration and motivation towards a better future. :)

pyxelr
Автор

I know this is an old video but I have watched just about every video I can find on this problem over the last few days trying to wrap my head around it and this is by far the clearest and easiest to follow of all of them. Thank you!

MrFrawsty
Автор

Each iteration, you are shifting O(max(a, b)) chars to the right. It's max(a, b)^2 operation. Better to sb.reverse().toString() at the end, that's linear operation.

mym
Автор

It is important to note that /2 also deals well with the case of sum == 3. That is, if the previous calculation forced a carry, and we are adding 1 and 1, we will have sum = 3, where (int)(3/2) = 1 and we get the right carry.
Another way to do this, which might be more obvious to a code-reviewer, would be to use ` carry = sum > 1 ? 1 : 0; `

nickdrouin
Автор

You are awesome!!! After following you for one month, I got to write the code exactly the style as yours. I am sooo happy haha.

littlesunshine
Автор

Love your videos. Great help. Its fascinating to see you solving problems.

ahamza
Автор

Kevin, although it works but explanation at time 6:50 for line#17 is not complete. We can have either (0, 1, 2 or 3 as well). We can have 3 if carry is 1 and we have both the bits as 1. So 1+1+1 = 3. Similarly for line#18, carry would be 1 for 2 cases (if sum is 2 or sum is 3, i.e 2/2=1 and 3/2 = 1). BDW, great and neat solution.

shahnawazalam
Автор

You can solve this by implementing a half adder circuit. Sum bit is a XOR b, carry bit is a AND b.

chinmoykanjilal
Автор

Hey Kevin, let me tell you, you are one of the best you tubers and instructors for these algorithm and data structures problems. Thank you for everything

ericzorn
Автор

this is awesome buddy, I wrote almost 130 lines of code to solve this easy (after your explanation) problem...good job.

lapujain
Автор

You explained the concept very well Sir.Love to see your Coding Videos.

RiteshKumar-qbuz
Автор

Hi Kevin, shout out for your channel! I am currently preparing for the interview. Your content helps me a lot, if you would have any time to chat and advice me for the interview and learning process please let me know! Kuddos!

olaz
Автор

I have a doubt, the while condition will exit if any one of the string terminates, then won't we have to add the remaining char to our final ans?

nakuldeshmukh
Автор

Hey, just what I needed bro :) gonna try this problem before I watch the vid! Love the intro too btw haha

TheNickcharlie
Автор

Definitely a good video! Maybe one suggestion would be to say / list a few problems that are solved similarly? I know that the array and Linked List version of this problem are also available and use almost the exact same method. Maybe one other to mention would be why use a StringBuilder (in python I have to emulate it with an array of chars, but some operations like insert at 0 would be expensive)

martinszauer
Автор

Facebook has been known to ask this but without using the + operator. You would have to use bit manipulation in that case

varunrao
Автор

We can convert binary strings to its relevant integer and then do addition. After addition we can convert from integer to binary string.

jaimitgandhi
Автор

how do you guys come up with the %2 and /2 thing I would have never thought of that. :(

shashanksetty
Автор

This is my 5th day, and I try my best to come up with solutions. But still end up finding solutions online. Is this common or am I not cut off?

prithvimd