L6. Single Number II | Bit Manipulation

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

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

  • @yashwanthyerra2820
    @yashwanthyerra2820 2 месяца назад +20

    | will be used to set
    ^ will be used to toggle
    & will be used to check
    &~ will be used to clear

  • @shivanggour440
    @shivanggour440 Месяц назад +2

    I haven't commented any of your video, but this bucket method has pushed me to comment.
    Glad to have a teacher like you.

  • @charansaianisetti5436
    @charansaianisetti5436 9 месяцев назад +14

    mind blowing explanation, i love how in depth you are teaching the concepts.

  • @JIHYELEE-h2m
    @JIHYELEE-h2m 4 месяца назад +10

    26:22 Thanks for waking me up. So difficult to understand that part.......

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

    amazing explanation, it took me some time to grasp the concepts of buckets but finally I understood every step. 😅😅

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

    Excellent explanation. Really loved the Bucket method

  • @Mohit_Q
    @Mohit_Q 9 месяцев назад +3

    kyaaa pyaar solution tha bucket wala loving ittttt

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

      WILL THE BUCKET WORK IF THE NO,S ARE NOT IN CLUSTERS

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

      @@ArkojyotiDeyOfficial Yes, Works for every possible arrangment of the elements.

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

    Please Update A2Z DSA Course/Sheet for this series, it helps a lot in revision

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

    19:18 its so amazing 😮😮 . The way of thinking damnn..

  • @AkOp-bf9vm
    @AkOp-bf9vm 6 месяцев назад +8

    i never imagine that a question can have that many solutions😂😂

  • @AneeshPal-t7y
    @AneeshPal-t7y 2 месяца назад +1

    "You don't deserve to be here"was personal 😂

  • @RK-Sonide4vr
    @RK-Sonide4vr 8 месяцев назад +2

    class Solution {
    public:
    int singleNumber(vector& nums) {
    int ans = 0;
    for(int bitIndex = 0; bitIndex

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 9 месяцев назад +2

    public int singleNumber (int[]nums){
    int ones=0,twos=0;
    for(int num:nums){
    ones=ones^(num&~twos);
    twos=twos^(num&~ones);
    }
    return ones;
    }

  • @AshwaniKumar-ew1cn
    @AshwaniKumar-ew1cn Месяц назад

    Second solution after the brute force { Bitwise Manipulation } is not working for negative numbers. Thank you for lovely explanations!

  • @_The_-_worst_
    @_The_-_worst_ 9 месяцев назад +47

    Make playlist or videos for Competitive programming because I have completed your dsa series 😊

    • @parasjeeprep3206
      @parasjeeprep3206 9 месяцев назад +3

      how much time did it took to complete the playlist and how many videos were you watching everyday

    • @QuickNews999
      @QuickNews999 8 месяцев назад +22

      Bro there is competative programming sheet also, if you have finished that do a deep dive in stl if c++ or collections if in Java, then do math a lot, remember no tutorial can prep you for competitive programming it is just you and you have to go deep dive in it and eventually you will learn ,from some who is 2000 on Codeforces. Best of luck

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

      Mastering Segment tree, BIT,dp and graph will surely put you cm or master level but surely it's gonna take a lot of time and effort.

    • @AK-nj1je
      @AK-nj1je 6 месяцев назад +1

      @@QuickNews999 bro how you counter questions from the topic that you didn't covered, does that mean you have to first cover all the dsa topics and then start cp,
      btw congo bro, i respect your rating!!

    • @noone-nt1cp
      @noone-nt1cp 5 месяцев назад

      What about string , from where it should be learnt

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

    thanks for another great video, made this mind boggling question easy to understand

  • @Sanju-o6l2g
    @Sanju-o6l2g 7 месяцев назад +1

    For those who not understand bucket concept , forget about bits and try with numbers only to understand concept .
    we want to check (ones == twos)but we don't want to lose value of ones there for using ( & ~ twos )

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

    The bucket concept was❤

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

    Thank you sir 😁

  • @raj.dpatel1162
    @raj.dpatel1162 3 месяца назад +1

    legend

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

    Understood bhai

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

    1 doubt !
    How `~twos` was induced
    because "not present in twos" cannot directly interpreted as `~twos`
    as `twos` is holding result accumulated of various numbers XORed !!
    What is hypothesis that `~twos` will for sure work as "not present in twos" !!?

  • @ssh3v
    @ssh3v 9 месяцев назад +2

    ohh, i love naive solutions

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

    Last algorithm can only be visualized ❤

  • @DeepakKumar-nq4td
    @DeepakKumar-nq4td 3 месяца назад

    Maja aa gaya bhaiya ji

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

    The sudo code at 10:45 will not work for below example [555666444]
    Expected ans: 0
    But returning: 3

  • @GoluKumar-sb2si
    @GoluKumar-sb2si 6 месяцев назад +1

    at 17:20 if we take this example after sorting [ 1,1,1,2,3,3,3,4,4,4] then according to code it will give 2 and 3 as a ans ,, but ans should be only 2 so how this code is true .Can anyone explain?

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

      loop will not go ahead after finding 2....2 will be returned

    • @AkOp-bf9vm
      @AkOp-bf9vm 6 месяцев назад

      no it only return ans==2 for every index we are checking we will use
      if(arr[i] != arr[i-1]) return arr[n-1];
      it will return n-1 index value

  • @modiji8706
    @modiji8706 9 месяцев назад +10

    at 7:54 he is more serious then my carrer

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

    Bitwise Not (ie ~), merely gives the bitwise negation of that group's XOR value, which doesn’t relate to the membership of individual elements.
    How does this step of ANDing (~groupX) works here (hypothetically) ??

  • @AkashGautam-k2u
    @AkashGautam-k2u 8 месяцев назад

    Thank you bhaiya.

  • @kale-lb5pr
    @kale-lb5pr 8 месяцев назад +2

    i have one question like i was doing dry and run on array [5,5,5,6,4,4,4] after when array element first 4 comes if we take xor with what ones contains so it technically has 6 bcoz it occured ones then when we xor 6^4 it will not remain 6 pls tell me what im doing wrong something is off i cant pinpoint pls help guys!!

    • @AkOp-bf9vm
      @AkOp-bf9vm 6 месяцев назад +1

      this is not wrong the answer will be (6^4)&(~two). ones will change here but if you completely traverse whole array the ones will contain 6

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

    could someone explain the 2nd solution?
    i dont understand why having a non-multiple occurences of 1 in an index allows the answer to have 1 in that index

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

    at 26:35 i feel you wrote and spoke correctly but earlier in rules you stated point number two as it will go to twos, if it is in ones! please confirm striver.

    • @AkOp-bf9vm
      @AkOp-bf9vm 6 месяцев назад +1

      both are correct because that line is used to execute the point "num[i] will go to twos if it is in ones" .
      lets consider the the array be arr={2,2,2,3}
      step 1: ones=2 and twos=0
      step 2: num[i]==2 and ones is also 2 which means we have to delete 2 from ones.
      now ones==0
      if it the first occurrence of 2 then it should be present in ones but it is not (because ones==0) which means it is the second occurrence of 2 which means 2 is now added in twos that why we use the condition that ***it should not be present in ones*** by ~ones.

  • @darshbothra007
    @darshbothra007 9 месяцев назад +1

    First one to comment! Excited ❤

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

      Congratulations bro🎉🎉🎉

    • @modiji8706
      @modiji8706 9 месяцев назад +1

      kl rashtrapati bhavan aa jana prize lene

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

      @@modiji8706 😂😂😂😂😂😂

  • @vaibhavjindal3144
    @vaibhavjindal3144 18 дней назад

    Do lots of dry run.. You will have better understanding of bucket method..

  • @A_Myth963
    @A_Myth963 8 месяцев назад +3

    For 2nd Bucket - will go to twos if it is in ones
    - I think there will be a correction here
    that - it will go to twos if not in ones

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

      Same Thought Bro

    • @AshishSingh-he2qo
      @AshishSingh-he2qo 3 месяца назад +3

      If not in one then how can u know it already appeared, that's why it will check if it is in one then go to 2nd bucket and delete from 1st bucket ❤

  • @Keshav2005a
    @Keshav2005a Месяц назад +1

    Not able to understand bucket method

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

    Thank sir 🤩🤩

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

    for num it should add to twos if its in ones this make sense but add to twos if its not in ones don't

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

    can this solution of checking bits work in case of negative numbers as well?

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

    Understood

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

    can any anyone clear my doubt the 2nd approach count the bit and set the ith bit of the number works for -ve number ??

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

    UNDERSTOOD;

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

    I discovered this channel, and this guy is Arnab Goswami ka bhai 😀

  • @SHEETALIMAITY-s7d
    @SHEETALIMAITY-s7d 3 месяца назад

    17:26

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

    Nice explanation. However I am not able to understand the bucket method yet...Does it work only for the sorted array?

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

      Ya similar doubt, I think the array should be sorted....

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

      No it works for unsorted array as well

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

    Thank you

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

    Can it be explained in easy way ? plz

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

    hello, I think your "better" approach does not work with lists containing negative numbers. however, your "optimal" approach does.

  • @chirag71269
    @chirag71269 13 дней назад

    OG STRIVER

  • @abhinay.k
    @abhinay.k 3 месяца назад

    thanks

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

    UNABLE TO UNDERSTAND BUCKET METHOD !

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

    Thank You!!!!!!!

  • @charansaianisetti5436
    @charansaianisetti5436 9 месяцев назад +1

    i have gone through the dsa sheet but unable to find the notes, can anyone guide me where the notes exactly is

    • @modiji8706
      @modiji8706 9 месяцев назад

      not update yest..

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

    I have a doubt regarding bucket method. suppose list = [3,2,2,2] initially in first loop ones = 3 and twos = 0, then in second loop we face (3^2)& ~0 will it not create a sort of ambiguity🤔🤔🤔

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

      it will create but he says that all things are working on bit level , so in last desired ans will come .......we can understand it like when there a lot of numbers in which all numbers are appearing twice excepting one , and when we applied xor operation on all of them , then only one who appear ones is come in ans

  • @amanverma5912
    @amanverma5912 9 месяцев назад +1

    The question and notes links are not available in the dsa sheet. Please update it!!

    • @AkOp-bf9vm
      @AkOp-bf9vm 6 месяцев назад

      bro i am also searching for it 🤣🤣

  • @Mohd-12335
    @Mohd-12335 4 месяца назад

    I didnt understand how the last code will work with none sorted lists

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

    didn't understand bucket method brother try so much

  • @ManishKumar-dk8hl
    @ManishKumar-dk8hl 9 месяцев назад +1

    yehi too chahiye tha

  • @yash2275
    @yash2275 8 месяцев назад +3

    Can any one please tell When I am doing dry run on [1,2,3,2,3,2,3] It is giving random ans and not the desired output then how at hardware level this is giving correct answer the method was nice but why it didn't prove it's correctness in dry run ????

    • @AkOp-bf9vm
      @AkOp-bf9vm 6 месяцев назад

      it will give desired output after the complete traversal of array may be you done some error in your calculation
      #include
      using namespace std;
      int main()
      {
      vector arr={1,2,3,2,3,2,3};
      int ones=0,twos=0;
      int n=arr.size();
      for(int i=0;i

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

    understood

  • @KUMARSAURABH-s5i
    @KUMARSAURABH-s5i 5 месяцев назад +1

    Bucket Method😍

  • @kale-lb5pr
    @kale-lb5pr 8 месяцев назад

    pls tell me why in system im getting correct result even if the array is unsorted but while im doing dry and run why im just getting some random result which i dont want pls help me unveil tell me the bit manipulation trick which maybe im not able to see through my naked eyes im not able to pinpoint the mistake pls help guys!!

    • @AkOp-bf9vm
      @AkOp-bf9vm 6 месяцев назад

      i think we add the number and also delete it if it is duplicate thats why only unique element will remain in ones

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

    Scary!

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

    nah not able to understand last method

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

    Bucket method not clear

  • @kale-lb5pr
    @kale-lb5pr 8 месяцев назад

    pls help me im not getting answer while im doing dry nd run

    • @AkOp-bf9vm
      @AkOp-bf9vm 6 месяцев назад

      it will give desired output after the complete traversal of array may be you done some error in your calculation.
      #include
      using namespace std;
      int main()
      {

      vector arr={1,2,3,2,3,2,3};
      int ones=0,twos=0;
      int n=arr.size();
      for(int i=0;i

    • @AkOp-bf9vm
      @AkOp-bf9vm 6 месяцев назад

      suggestion for you:: you can also try to get answer from chatgpt . most of the time it will find error in your code . It will save your lot of time.

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

    🔥🔥🔥

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

    Sir i guess at 10:45 , you have used 2 for loops , first goes from i to 31 and second goes from j to n , which is i guess wrong because according to this we are counting the bits row wise but we have to count it colum wise so our loop should be like i to n and j to 31, correct me if im wrong

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

      no, the way in the video is correct. we want to count the number of 1's in each bit position. so we need to iterate through each bit position first, and then each number from the array to count how many 1's there are. hopefully that makes sense

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

    kuch samja nahi

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

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

    I sometimes wonder why he is in not from IITs, he should have a permanent seat there

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

    bhai yr aisi english mt bolo ki smgh hi na aye kuch chota sa concept smjhne me itni mehnt lg gyi

    • @AkOp-bf9vm
      @AkOp-bf9vm 6 месяцев назад

      😂😂 ha bhai sach m kabhi kabhi samjh m aana band ho jata h ,,bhai ki english to nxt lvl hai

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

    don't shout bro

  • @kale-lb5pr
    @kale-lb5pr 8 месяцев назад +1

    #include
    using namespace std;
    int singleNumII(vector a,int n)
    {
    int ones=0,twos=0;
    int i;
    for(i=0;i

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

      U need to take all elements thrice except one element. If u change 6 to 4.. you'll get the correct output.

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

    Understood

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

    Thank you bhaiya

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

    Understood

  • @SitaRam-m1i
    @SitaRam-m1i Месяц назад

    Understood