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

Поделиться
HTML-код
  • Опубликовано: 3 дек 2024

Комментарии • 148

  • @IamGroot455
    @IamGroot455 4 месяца назад +17

    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.❤❤❤

  • @bhagyashreeaher7429
    @bhagyashreeaher7429 8 месяцев назад +34

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

    • @md_seraj786_
      @md_seraj786_ 5 месяцев назад

      yes, please make String problem series 🙏

  • @thoughtsofkrishna8963
    @thoughtsofkrishna8963 8 месяцев назад +154

    Waiting for strings playlist

  • @udayshankar-e6v
    @udayshankar-e6v 7 месяцев назад +16

    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

  • @sujalgupta6100
    @sujalgupta6100 8 месяцев назад +20

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

  • @ayushmamgain9040
    @ayushmamgain9040 3 месяца назад +6

    The question requires not to use multiplication operator, but it is used in the last line:
    n = n - (d * (1

  • @areeb6703
    @areeb6703 6 месяцев назад +1

    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 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.

  • @shwetanshu13
    @shwetanshu13 8 месяцев назад +4

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

  • @shrutikumbhare2009
    @shrutikumbhare2009 8 месяцев назад +2

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

  • @utube4026
    @utube4026 8 месяцев назад +9

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

  • @balajisadhu8510
    @balajisadhu8510 8 месяцев назад +4

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

  • @viratlover6206
    @viratlover6206 8 месяцев назад +4

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

  • @Codebond7
    @Codebond7 8 месяцев назад +5

    Thanks I will complete till here by tomorrow

  • @akashpurbia4390
    @akashpurbia4390 8 месяцев назад +1

    Thanks for this amazing playlist!

  • @shreyxnsh.14
    @shreyxnsh.14 7 месяцев назад +8

    Complete CPP Code:
    class Solution {
    public:
    int divide(int dividend, int divisor) {
    if(dividend==divisor)
    return 1;
    bool sign = true;
    if((dividend0) || (divisor=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

  • @HitheshB-m8w
    @HitheshB-m8w 8 месяцев назад +11

    bro CAN U START STRING SERIES AS WELL PLZZZZZZZZZZZZZZZZZZZZZZZZZ

  • @NiveditaKar-xj6ew
    @NiveditaKar-xj6ew 8 месяцев назад

    Amazing explaination Striver

  • @madhavmurari3875
    @madhavmurari3875 10 дней назад

    Best ever explanation ,Thank you Bhaiya .

  • @krityranjanpanda6259
    @krityranjanpanda6259 8 месяцев назад +1

    Great content 😁💯 waiting for string matching algorithms

  • @stith_pragya
    @stith_pragya 7 месяцев назад +1

    Thank You So Much for this wonderful video.....🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @knowthrvdo
    @knowthrvdo 8 месяцев назад

    add this link to a to z dsa sheet so that students can easily get it and thanks for uploading lectures

  • @kushagrasahay
    @kushagrasahay 8 месяцев назад +1

    thanks for such amazing playlist

  • @limitless6189
    @limitless6189 8 месяцев назад +6

    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

  • @RiddhiMS-l5g
    @RiddhiMS-l5g 8 месяцев назад

    Heyy striver,
    I have been learning from your videos and they are very nice.
    I would request you to start string series please.

  • @shreyxnsh.14
    @shreyxnsh.14 7 месяцев назад +4

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

  • @riteshbisht94
    @riteshbisht94 7 месяцев назад +1

    Please continue the bit manipulation series 🙏

  • @sarder681
    @sarder681 4 месяца назад

    Thank you striver from bangladesh.

  • @017_indrasen9
    @017_indrasen9 8 месяцев назад

    Thank you @Striver respect++

  • @foziezzz1250
    @foziezzz1250 7 месяцев назад +4

    small doubt
    why did we checked that quotient == 1

    • @vaibhavrawat8633
      @vaibhavrawat8633 27 дней назад +1

      same doubt

    • @Keshav2005a
      @Keshav2005a 23 дня назад +2

      Have any answer or not please tell I am also stuck here

    • @ujohnwesly1874
      @ujohnwesly1874 9 часов назад

      Because it should strictly equal to 2^31 or 2^-31

  • @riteshbisht94
    @riteshbisht94 8 месяцев назад +1

    Great video 🔥

  • @shashankgsharma0901
    @shashankgsharma0901 4 месяца назад

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

  • @Yogamindmastery
    @Yogamindmastery 4 месяца назад

    Very good explaination thanks a lot Sir

  • @harshith1424
    @harshith1424 8 месяцев назад

    Most wanted topic❤

  • @AdityaKumar-be7hx
    @AdityaKumar-be7hx 5 месяцев назад

    This one works with 32 bit integers and is similar to Strivers solution:
    class Solution {
    public:
    int divide(int dividend, int divisor) {
    if(dividend == divisor)
    return 1;
    if (dividend == INT_MIN && divisor == -1) return INT_MAX;
    int sign = 1;
    if(dividend>=0 and divisor=d){
    int cnt=0;
    while(n>d

  • @UECAshutoshKumar
    @UECAshutoshKumar 8 месяцев назад +1

    Thank you 😊

  • @shreyxnsh.14
    @shreyxnsh.14 8 месяцев назад +12

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

  • @AfzalAsar
    @AfzalAsar 8 месяцев назад +2

    Bhaiyaa please upload stack queue asap as well please 🥺

  • @sashibhushanarajput1194
    @sashibhushanarajput1194 2 месяца назад +1

    Bro though this is good but the main gist of the problem is implemenation as well within the rules after knowing the logic, and by using long that rule has been broken

  • @U2011-n7w
    @U2011-n7w 4 месяца назад +1

    best video

  • @karthik-varma-1579
    @karthik-varma-1579 Месяц назад

    class Solution {
    public int divide(int dividend, int divisor) {
    if(dividend == divisor) return 1;
    boolean sign = true;
    if(dividend0) sign = false;
    if(dividend>0 && divisor=d){
    int count = 0;
    while(n>=(d

  • @mounikap4492
    @mounikap4492 7 месяцев назад

    Please include 1915. Number of Wonderful Substrings, and it would be nice to cover the concept of masking in bit_manipulation series. Thanks.

  • @AkashKumar-qb6sc
    @AkashKumar-qb6sc 3 месяца назад +1

    Awsm

  • @himanshukaushik9223
    @himanshukaushik9223 8 месяцев назад +2

    Bhaiya a2z sheet pa code and article ka link upload kar do binary search tree pa bhi kuch questions pa nahi hai ??

  • @masteredultrainstinct8840
    @masteredultrainstinct8840 17 дней назад

    There is another Math solution you can use. TC : LogN
    Use binary serach in range [1,N/2], pick mid and keep checking -> if mid*division

  • @sumitsharma-ss2xr
    @sumitsharma-ss2xr 8 месяцев назад

    Bhaiya sliding window v jldi lana i know apki schedule busy h but fir v wait kr rha hu 😅 Koi or playlist se pdh rha tha but waiting for yours sliding window playlist

  • @shaikkhizar8133
    @shaikkhizar8133 8 месяцев назад +1

    Thankyou sir

  • @Algorithmswithsubham
    @Algorithmswithsubham 8 месяцев назад +2

    sir how to write good quality code uspe ak video banaya

  • @khalasianiket816
    @khalasianiket816 4 месяца назад

    understood ❤

  • @Learnprogramming-q7f
    @Learnprogramming-q7f 7 месяцев назад

    Thank you Bhaiya

  • @nisanduathsara5242
    @nisanduathsara5242 8 месяцев назад

    hey striver need a full combinatorics playlist...

  • @karthik-varma-1579
    @karthik-varma-1579 Месяц назад

    Java Solution:
    class Solution {
    public int divide(int dividend, int divisor) {
    if(dividend == divisor) return 1;
    boolean sign = true;
    if(dividend0) sign = false;
    if(dividend>0 && divisor=d){
    int count = 0;
    while(n>=(d

  • @janardhan2jordan
    @janardhan2jordan 8 месяцев назад

    is this the end of the playlist??
    as there are some advance maths questions there in bit manipulation

  • @SuvradipDasPhotographyOfficial
    @SuvradipDasPhotographyOfficial 5 месяцев назад

    Striver bhai bit manipulation over, please do strings. It's very important, many questions are getting stuck in string. Please bhai🙏🙏

  • @kunal5077
    @kunal5077 4 месяца назад

    Please start with string playlist sir
    HUMBLE REQUEST TO YOU

  • @mohitsingh7793
    @mohitsingh7793 8 месяцев назад

    More efficient than Striver's code :
    T.C: O(1)
    S.C : O(1)
    int divideTwoInteger(int dividend, int divisor) {
    long q=0,sign=-1;
    if((dividend0))
    sign=1;
    long d1=abs(dividend), d2=abs(divisor),temp=0;
    for(int i=31;i>=0;i--)
    {
    if((temp+(d2

    • @TheHariPutraOfficially
      @TheHariPutraOfficially 3 месяца назад

      Bhai mujhe English samajne me dikkat ho rahi ..and striver fails to say what he wants to do..like..in this..start ne bolte .. multiplication means continuous subtraction
      I give up with DSA..kitna rough hai...
      Best development haiii

  • @govindlohar6816
    @govindlohar6816 6 месяцев назад

    very nice

  • @rishijen7363
    @rishijen7363 8 месяцев назад +1

    Pls string playlist ❤❤❤

  • @udaychaudhary3636
    @udaychaudhary3636 8 месяцев назад +1

    waiting for the string playlist

  • @rushidesai2836
    @rushidesai2836 8 месяцев назад

    Below one slightly modified.
    public int divide(int dividend, int divisor) {
    // Check for edge cases
    if (dividend == 0) return 0;
    if (divisor == 0) throw new ArithmeticException("Division by zero");
    if (divisor == -1 && dividend == Integer.MIN_VALUE) return Integer.MAX_VALUE;
    // Determine the sign of the result
    boolean isNegative = (dividend < 0) ^ (divisor < 0);
    // Convert dividend and divisor to positive values
    long absDividend = Math.abs((long) dividend);
    long absDivisor = Math.abs((long) divisor);
    long quotient = 0;
    while (absDividend >= absDivisor) {
    long temp = absDivisor;
    long shift = 1;
    // Shift the divisor left until it becomes greater than the dividend
    while ((temp

  • @ss_shruti10
    @ss_shruti10 2 месяца назад

    Please upload String Playlist also :)

  • @shaiksoofi3741
    @shaiksoofi3741 5 месяцев назад +1

    understood

  • @akashkumaryadav1827
    @akashkumaryadav1827 3 месяца назад +1

    🔥

  • @Rahul-rp5hk
    @Rahul-rp5hk 8 месяцев назад

    Can be easily done in O(logn) too

  • @deepakkumar13204
    @deepakkumar13204 8 месяцев назад

    First view from my sids 😊

  • @jaydabhi5539
    @jaydabhi5539 7 месяцев назад

    Thanks striver.
    I understand the solution but i just want to ask will it help in any other problems if i know this solution?Anyone? Your reply is appreciated.

  • @Sumanth_Siddareddy
    @Sumanth_Siddareddy 5 месяцев назад

    Understood

  • @thanuja.07
    @thanuja.07 8 месяцев назад

    Can anyone tell me, where is the link to the problem and notes, as i couldn't figure out where is day8 in the link given in description

  • @the_ved11
    @the_ved11 8 месяцев назад

    On the 2nd while condition, why does it not as n>= (d*(1

    • @ckrakle
      @ckrakle 8 месяцев назад

      same as n >= (d

    • @akworld2739
      @akworld2739 7 месяцев назад +1

      check his first video of bit manipulation in left shift

  • @ankitpradhan2499
    @ankitpradhan2499 5 месяцев назад +1

    can anyone plzz tell why this code is not working -->
    int division(int given, int divisor){
    bool sign = true; // sign is positive
    if(given < 0 && divisor > 0) sign = false; // sign is negative
    if(given > 0 && divisor < 0) sign = false; // sign is negaitve
    long given1 = abs(given);
    long divisor1 = abs(divisor);
    long ans = 0;
    int cnt = 0;
    while( given1 - ( divisor1

  • @mimansatripathi
    @mimansatripathi 8 месяцев назад

    please start string series 🥺🥺🥺🥺🥺🥺

  • @abhimanyuthapliyal5823
    @abhimanyuthapliyal5823 5 месяцев назад

    isnt TC better for appr 1 , then why is appr 2 reqd ?

  • @Chhooso
    @Chhooso 6 месяцев назад

    striver please drop the strings playlist

  • @MohitKumar-uw1pz
    @MohitKumar-uw1pz 3 месяца назад

    MAIN HOON MOHIT

  • @ritesh_kr
    @ritesh_kr 8 месяцев назад

    what if our d is INT_MIN ?
    ps : i didnt watch the whole lecture 😅

  • @VisibleNasir
    @VisibleNasir 8 месяцев назад

  • @ketonesgaming1121
    @ketonesgaming1121 8 месяцев назад

    Java Solution : public class Solution {
    public static int divideTwoInteger(int dividend, int divisor) {
    if (dividend == divisor)
    return 1;

    boolean sign = true;
    if (dividend > 0 && divisor < 0)
    sign = false;
    if (dividend < 0 && divisor > 0)
    sign = false;

    int n = Math.abs(dividend);
    int d = Math.abs(divisor);
    int ans = 0;

    while (n >= d) {
    int count = 0;
    while (n >= (d

  • @257divyanshu
    @257divyanshu 7 месяцев назад +1

    I have a question, why are the we removing the largest possible first I mean why are we removing 12 first and then 6 and then 3...... we could have removed 3 and then 6 and then 12 (doing so will reduce the need to find what's the maximum that can be returned)............ after removing 3 (3 * 2^0) our n will 19, then we see that 6 (3 * 2^1) can be removed so we will remove 6, after removing 6 n becomes 13.... then we see that 12 (3 * 2^2) can be removed so we remove 12, then our n becomes 1, now the next thing that should be removed is 24 (3 * 2^3) .... but this cannot so we will return the sum of 1, 2 and 4 which is 7..... I tried this approach on the leetcode question 29, but it's giving TLE...... can someone please explain why..... I just reversed the order, right? this shouldn't cause TLE

    • @HaamroNotes
      @HaamroNotes 6 месяцев назад

      // Online C compiler to run C program online
      #include
      int main() {
      int n;
      int d;
      scanf("%d %d",&n,&d);
      int sum=0;
      int count=0;
      int ans=0;
      while(sum

    • @pBERA0_0
      @pBERA0_0 2 месяца назад

      same doubt :/
      @257divyanshu

  • @AbhishekKumar-lh2pt
    @AbhishekKumar-lh2pt 7 месяцев назад

    🙇🙇🙌

  • @sanjaykatta6499
    @sanjaykatta6499 5 месяцев назад

    we didn't completely get away from using multiplication even with this code.

  • @SudhirKumar-ge5nv
    @SudhirKumar-ge5nv 8 месяцев назад

    I just want to believe if the shift operators are used anywhere... 😢😢😢

    • @akworld2739
      @akworld2739 7 месяцев назад

      yes it is too confuesing😅

  • @sword013
    @sword013 Месяц назад

    the overflow part is still not that clear

  • @ayushojha4607
    @ayushojha4607 8 месяцев назад

    start heap playlist

  • @paarthkumar3787
    @paarthkumar3787 4 месяца назад

    C++ Solution -
    #include
    using namespace std;
    class Solution {
    public:
    int divide(int dividend, int divisor) {
    if (dividend == divisor) return 1;
    if (dividend == INT_MIN && divisor == -1) return INT_MAX;
    int sign = 1;
    if ((dividend >= 0 && divisor < 0) || (dividend 0)) {
    sign = -1;
    }
    long n = labs(dividend); // Use labs for long absolute value
    long d = labs(divisor); // Use labs for long absolute value
    long ans = 0;
    while (n >= d) {
    int cnt = 0;
    while (n >= (d

  • @prajwalrai2596
    @prajwalrai2596 8 месяцев назад

    Waiting for string

  • @ayushraj5672
    @ayushraj5672 8 месяцев назад

    Bhaiya, actually i want to start this DSA playlist but don't know from which video should i start as you have made playlists topicwise. It would really be helpful if you would create a new playlist and add all videos in order, else you can upload a seperate video regarding roadmap for this particular playlist, like from where one should start then what, then what, then next what....
    --Thank you
    Please reply asap:⁠-⁠)

  • @akshatgoel149
    @akshatgoel149 5 месяцев назад +1

    There is no need for nested loops
    TC - O(log2N)
    class Solution {
    public:
    int divide(int dividend, int divisor) {
    long c = 0;
    int sign = 0;
    if(dividend0) sign = 1;
    if(dividend>0 && divisor

  • @RahulRai-vw3dw
    @RahulRai-vw3dw Месяц назад

    when i run this code it gives tle

    • @xdjqye
      @xdjqye 17 часов назад

      same issue

  • @abdealimuneem4968
    @abdealimuneem4968 5 месяцев назад

    could have also used binary search, amirite//

  • @zaffarzeshan1308
    @zaffarzeshan1308 6 месяцев назад

    2nd test case failed

  • @Lucifer0872
    @Lucifer0872 8 месяцев назад

    hail mary

  • @slayer-x2f
    @slayer-x2f 3 месяца назад +2

    could have been better

  • @tanishjain1643
    @tanishjain1643 6 месяцев назад

    These code is working in cpp but not in java
    Greeting tle

  • @ckrakle
    @ckrakle 8 месяцев назад

    taking long long 1LL menas ans += (1LL passed
    if(ans > INT_MAX && sign == 0) return INT_MAX;
    if(ans > INT_MAX && sign == 1) return INT_MIN;
    code 2 => not passed
    if(ans >= INT_MAX && sign == 0) return INT_MAX;
    if(ans >= INT_MAX && sign == 1) return INT_MIN;
    code 3 => not passed
    if(ans >= (1 (1

  • @sanjanareddy2696
    @sanjanareddy2696 8 месяцев назад

    Please stop wearing red and try other colors. Its boring now

    • @tousifjaved3485
      @tousifjaved3485 8 месяцев назад

      Red increases attention and engagement of audience
      Maybe that's why he always wears red for video making

  • @amitdahiya7425
    @amitdahiya7425 8 месяцев назад +2

    So I wrote the code same as yours , got runtime error due to corner cases , Checked the solution 99% of solution have used long long which is violation of the question rules
    and then checked the LEE215 solution but it was working well in past not now , so can anyone provide me the solution which works well and follows the question rules too
    Edit : Got the solution here it is 👇👇
    class Solution {
    public:
    int divide(int dividend, int divisor) {
    if (dividend == INT_MIN && divisor==-1) return INT_MAX;
    if(dividend==divisor)return 1;
    unsigned int n=abs(dividend),d=abs(divisor);
    bool neg=false;
    if(dividend =0)neg=true;
    else if(dividend >=0 && divisor=d){
    short count=0;
    while(n > (d

    • @the_ved11
      @the_ved11 8 месяцев назад

      On the 2nd while condition, why does it not as n>= (d*(1

    • @takeUforward
      @takeUforward  8 месяцев назад

      it is not possible, did not see any solution working with using int, you can use signed int, but that is violation as well

  • @aryansinha1818
    @aryansinha1818 19 дней назад

    The question requires not to use multiplication operator, but it is used in the last line:
    n = n - (d * (1

  • @SibiRanganathL
    @SibiRanganathL 4 месяца назад +1

    Understood

  • @rohanagarwal4290
    @rohanagarwal4290 8 месяцев назад +1

    waiting for strings playlist

  • @Rahulyadav-sd3oj
    @Rahulyadav-sd3oj 8 месяцев назад

    Thank u sir

  • @hardikpatel352
    @hardikpatel352 5 месяцев назад

    understood