L9. Divide Two Integers without using Multiplication and Division Operators | Bit Manipulation

preview_player
Показать описание

Рекомендации по теме
Комментарии
Автор

Best playlist over bit manipulation on entire youtube, I have completed it in just 1 day and its still 5 pm and i started on 9 am. The content was very enjoyable and gave me new ways to think using xor and many others . Thank you a lot for providing such a amazing content for FREE.❤❤❤

NaveenBeniwal-cz
Автор

The question requires not to use multiplication operator, but it is used in the last line:
n = n - (d * (1 << cnt))
How can it be handled?

EDIT: just do n = n - (d << cnt)

ayushmamgain
Автор

Hello Striver
Thank you for Bit manipulation Series
Please make String Problems Solving series soon :)

bhagyashreeaher
Автор

little modification requires for java : then it will pass all use case;
long n = Math.abs((long)dividend); // Convert to long to handle Integer.MIN_VALUE
long d = Math.abs((long)divisor); // Convert to long to handle Integer.MIN_VALUE

udayshankar-ev
Автор

string matching algorithms would also help. Please make a playlist on that too.

sujalgupta
Автор

We can start our cnt from 32 (declared outside) and that way we won't have to increment it uptill 32, 31, 30... in order to find the point where ((d << cnt) > n) each time as the outer while loop iterates.
This way we can simply keep decrementing cnt it until 0. Time complexity: O(32) which is as good as constant.

areeb
Автор

Thank you so so much.... I was eagerly waiting for the bit manipulation series.

shwetanshusinha
Автор

this question is so bad, what does this even test? your mugging up skills?

shreyxnsh.
Автор

LGTA HAI RAJ BHAI AAJ HI BIT MANUPULATION KHATAM KR DENGE 😂😂😂😂😂😂😂😂. BUT SIR I HAVE MAD RESPECT FOR YOU 😊😊🫡🫡

utube
Автор

small doubt
why did we checked that quotient == 1<<31 and not quotient >= 1<<31

foziezzz
Автор

amazing playlist..
its a humble request to bring a new stack & queue playlist as well

shrutikumbhare
Автор

Thank you so much Striver you are motivating us to learn new topics by your videos. You are really doing great work!!

viratlover
Автор

we were not supposed to use multiplication, then how is this solution valid?

shreyxnsh.
Автор

Thanks I will complete till here by tomorrow

Codebond
Автор

i didnt expect i wound complete this bit manipulation tipic in 4 hts in one sitting .. thank you sooo muchhh

balajisadhu
Автор

Complete CPP Code:


class Solution {
public:
int divide(int dividend, int divisor) {
if(dividend==divisor)
return 1;
bool sign = true;
if((dividend<0 && divisor>0) || (divisor<0 && dividend>=0))
sign = false;
unsigned int n = abs(dividend);
unsigned int d = abs(divisor);
unsigned int ans = 0;
while(n>=d){
short count=0;
while(n > (d<<(count+1)))
count++;
ans += (1<<count);
n = n - (d*(1<<count));
}
if(ans == (1<<31) and sign)
return INT_MAX;
return (sign?(ans):(-1*(ans)));
}
};

shreyxnsh.
Автор

bro y did u delete the old string, heap, and other videos untill u upload new videos pls let the old one be there a kind ly request from ur student community pls understand us

limitless
Автор

Understood, btw, innner while loop was O(1) as max is 32 only and it doesn't increase with size.

shashankgsharma
Автор

Please continue the bit manipulation series 🙏

riteshbisht
Автор

Great content 😁💯 waiting for string matching algorithms

krityranjanpanda