Leetcode 338. Counting Bits | Bit Manipulation | Brute Force to Optimal | 2 Solutions with full code

Sdílet
Vložit
  • čas přidán 28. 02. 2022
  • Connect with me on LinkedIn : / alisha-parveen-80579850
    Check out our other playlists:
    Dynamic Programming:
    • Dynamic Programming
    Trees:
    • Trees
    Heaps and Maps:
    • Heaps and Maps
    Arrays and Maths:
    • Arrays and Maths
    Bit Manipulation:
    • Bit Manipulation
    Greedy Algorithms:
    • Greedy Algorithms
    Sorting and Searching:
    • Sorting and Searching
    Strings:
    • Strings
    Linked Lists:
    • Linked Lists
    Stack and Queues:
    • Stacks and Queues
    Two Pointers:
    • Two pointers
    Graphs, BFS, DFS:
    • Graphs, DFS, BFS
    Backtracking:
    • Backtracking
    Non- DSA playlists:
    Probability:
    • Probability
    SQL-Basic Join functions:
    • SQL - Basic JOIN Funct...
    SQL-Basic Aggregate functions:
    • SQL-Basic Aggregate Fu...

Komentáře • 19

  • @probabilitycodingisfunis1

    vectorans(n+1,0);
    for(int i=0;i

  • @satvikarya569
    @satvikarya569 Před rokem +5

    Can you please tell me how the binary value of a number is getting assigned to the variable 'num'?

  • @onkarsangale6222
    @onkarsangale6222 Před 10 měsíci +1

    This makes much more sense
    instead of % 2 we can use &1 which return 1 if bit is 1 and 0 when bit is 0;
    and we can right shift num by 1
    class Solution {
    public:
    vector countBits(int n) {
    vector ans;
    for(int i=0;i>1;
    }
    ans.push_back(sum);
    }
    return ans;
    }
    };

  • @JaJa-tp9ck
    @JaJa-tp9ck Před 2 lety

    Awesome job Alisha. I just found out about this channel and I'm definitely here to stay.

  • @shikha2121
    @shikha2121 Před rokem

    Yours is the simpleest explanation I found

  • @piyush2750
    @piyush2750 Před 2 lety

    Thankyou for super easy explanation

  • @saikrishna-cy2tr
    @saikrishna-cy2tr Před 9 měsíci

    the way you explained the solution was awesome dear

  • @manideep7148
    @manideep7148 Před rokem

    Excellent Explanation Alisha. Subscribed ;)

  • @AMITKUMAR-xv2ny
    @AMITKUMAR-xv2ny Před 5 měsíci

    Awesome ...

  • @kunalkheeva
    @kunalkheeva Před rokem

    ty

  • @sreeharia2356
    @sreeharia2356 Před 2 lety

    Nice explanation 🔥

  • @babushaikh6582
    @babushaikh6582 Před 2 lety

    Nice explanation 🎇

  • @commandermsv3329
    @commandermsv3329 Před rokem

    Good Work

  • @Rajat_maurya
    @Rajat_maurya Před 2 lety

    Thanks

  • @prashantshukla7477
    @prashantshukla7477 Před rokem

    thanks

  • @sahityaraj9417
    @sahityaraj9417 Před rokem

    Op❤

  • @dhananjoydey1337
    @dhananjoydey1337 Před 2 lety +1

    N is given in decimal but when we are iterating over N how we can find 1 and 0s?

  • @khushil9988
    @khushil9988 Před měsícem

    how diving the num by 2 removing 1 value from the unit place i think it's done by dividing it by 10
    1011/2 = 505
    1011/10 = 101 and that's what we want here

  • @n1111shant
    @n1111shant Před 10 měsíci

    yrr aap muche kaat leti