Add Binary - Leetcode 67 - Bit Manipulation (Python)

Поділитися
Вставка
  • Опубліковано 8 січ 2025

КОМЕНТАРІ • 22

  • @GregHogg
    @GregHogg  4 місяці тому +1

    Master Data Structures & Algorithms for FREE at AlgoMap.io/

  • @danh9002
    @danh9002 Місяць тому

    Great video! For those of us who used to do assembler, it was a nice trip down memory lane!

  • @tinayu3505
    @tinayu3505 2 місяці тому +3

    how the ampersand left shift trick works is & finds where there is 1 and 1 (the only case that results in carry) and places a 1 to mark the carry, the leftshift applies the carry to the next bit

  • @ghfranklin
    @ghfranklin 4 місяці тому +2

    Hi sir, from Nigeria, really enjoy watching your videos, wanted to make a request for LRU cache

  • @Ellenki_007
    @Ellenki_007 Місяць тому

    On which editor you are explaining sir?

  • @manikmukhija
    @manikmukhija 4 місяці тому

    What language do you think is better for dsa... python or java for future?

    • @binirxn
      @binirxn 4 місяці тому +2

      C++

    • @3lpme
      @3lpme 4 місяці тому

      Java

  • @user-jm6gp2qc8x
    @user-jm6gp2qc8x 3 місяці тому

    Hey gregg! It's time you update the list with some hard level problems or maybe create a new tab and put some hards in them :)

  • @mehrankhan6412
    @mehrankhan6412 4 місяці тому

    Hey Gregg I wanted To ask you for a favour Please make A Video On timeseries Dataset Multivariate with Implementation of PCA-LSTM hybrid approach On It

  • @azimjonalijonov1915
    @azimjonalijonov1915 4 місяці тому

    hI CAN YOU GIVE TIPS HOW TO MASTER ATBACKTRACKIGN PROBLEMS?

  • @shaneastone
    @shaneastone 2 місяці тому

    The solution is invalid. String b can be very large and exceed the capacity of an integer.

    • @xingyuxiang1637
      @xingyuxiang1637 Місяць тому

      I guess the point is to walk through the code and realize that the greedy part is to get all the carriers in one operation. Somehow, the final result matches the correct result. It is hard to prove it wrong mathematically or find a counter-example. A greedy approach, for example, replacing a queue with a priority queue appears in hard problems.
      I think that the good side in this context is to introduce multi-threading, like multiple threads can get the targets all at once. People usually will not do bit-manipulations a lot. So, that part is exercised. I actually would prefer to see the codes that perform additions concurrently because it aligns with maths.
      10^4 does not require greedy approaches most of the time. Clearly, the idea of a greedy approach is harder than DP. Straightforwardly, DP is to list all possible cases by trees, just like a nested for loop, which is actually not needed in the first problem.

  • @alchenerd
    @alchenerd Місяць тому

    What the...
    How do you deal with overflow of the variable `carry`?
    ``` cpp[]
    string addBinary(string a, string b) {
    if (a.size() < b.size()) {
    return addBinary(b, a);
    }
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    bool carry = false;
    string s = "";
    for (int i = 0; i < a.size(); ++i) {
    bool aa = a[i] == '1';
    bool bb = i < b.size() ? b[i] == '1' : false;
    char digit = '0' + (aa ^ bb ^ carry);
    s += digit;
    carry = (carry & (aa | bb)) | (aa & bb);
    }
    if (carry) {
    s += '1';
    }
    reverse(s.begin(), s.end());
    return s;
    }
    ```

  • @ramziddinaliqulov-zg3jt
    @ramziddinaliqulov-zg3jt Місяць тому

    Hello my name is Otabek. I am from Uzbekistan. I am 15 years old.I am going to be member of IOI. But I don't understand DSA.Please help me ?

  • @ramziddinaliqulov-zg3jt
    @ramziddinaliqulov-zg3jt Місяць тому

    Give me roadmap please ?!

  • @shhhrruutii
    @shhhrruutii 3 місяці тому

    Hey thank you. Can you upload more videos on DSA with python. It's really helping me since I'm currently a computer science engineering student and on my way to become a data scientist.

  • @akhilmohnn
    @akhilmohnn Місяць тому

    Can't we just simply do:
    final=bin(int(a,2)+int(b,2))[2:]
    return final

  • @user-jm6gp2qc8x
    @user-jm6gp2qc8x 3 місяці тому +2

    what the

  • @Rupok08
    @Rupok08 4 місяці тому +4

    sir, i am from bangladesh . i am only 16 years old. i have learned c and learning c++.i dream to work in fang companny .what would be my roadmap ? i kindda suck at solving problem but i try. please help me , you are my insperation 😊😊