Single Number II | Multiple Approaches | GOOGLE, AMAZON | META | Leetcode-137 | Explanation

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 พ.ย. 2024

ความคิดเห็น • 133

  • @raisanjeeb42
    @raisanjeeb42 ปีที่แล้ว +14

    Loved the way you approached the Question
    And Such a beautiful explanation

  • @AnkitYadav-kz2ei
    @AnkitYadav-kz2ei ปีที่แล้ว +12

    You are born to be a teacher. 😇

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      Wow. You made my day 😇❤️
      Thank you Ankit

  • @codestorywithMIK
    @codestorywithMIK  ปีที่แล้ว +9

    Please note that this will work for -ve numbers as well.
    Negative numbers are represented in two's compliment manner.
    So if nums is {-3, -3, -3, 1, 1, 1, 2}
    This will also work because in 2's compliment
    -3 will be represented as - '1111111111111101'
    And same will happen for other -3 in nuts.
    So anyways it will work.

    • @tanumittal899
      @tanumittal899 ปีที่แล้ว

      in python, this is failing for negative nos...

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      Hmm strange. Apologies as i have less visibility on python. Would you kindly share if you found the issue in Python ?

    • @tanumittal899
      @tanumittal899 ปีที่แล้ว +1

      @@codestorywithMIK not yet, will share soon.

    • @tanumittal899
      @tanumittal899 ปีที่แล้ว +2

      this is accurate running code for python to handle negative no
      class Solution:
      def singleNumber(self, nums: List[int]) -> int:
      result = 0
      is_neg = 0
      for k in range(0, 32):
      temp = (1

  • @souravjoshi2293
    @souravjoshi2293 ปีที่แล้ว +6

    The way you made Graph easy for me, same way you make Bit manipulation a cake walk for me.
    Thank you so much for such a neat explanation.

  • @AbhijeetMuneshwar
    @AbhijeetMuneshwar 5 หลายเดือนก่อน +1

    Respected MIK Sir,
    The way you start explaining from basic (e.g. Left Shift) is so helpful even for beginner. Your video is made for all kind of viewers right from beginner level to advance level viewer. This helps beginner to progress to advance level.
    Thank you so much for making our life easier 🙏🏼

  • @amansrivastava1360
    @amansrivastava1360 ปีที่แล้ว +3

    bhai mtlb maza agya ekdm

  • @anuppatankar4294
    @anuppatankar4294 ปีที่แล้ว +2

    Great Explanation 😍

  • @sarfrajansari1758
    @sarfrajansari1758 5 หลายเดือนก่อน +1

    everybody just giving their fancy solutions and they are not explaining it well. Thank you explaning in so simple detailed way.

  • @rohitsoni5491
    @rohitsoni5491 8 หลายเดือนก่อน +2

    Bahut saare video dekhe but samajh nahi aarha tha but this video is more clear than crystal

  • @AnjuGupta-sz1uk
    @AnjuGupta-sz1uk 11 หลายเดือนก่อน +2

    I learnt one new approach of doing this Problem...really helpful

    • @codestorywithMIK
      @codestorywithMIK  11 หลายเดือนก่อน +1

      Glad to hear that 😇🙏

  • @sahilgupta9622
    @sahilgupta9622 ปีที่แล้ว +1

    Very well explained ❤

  • @prad2003
    @prad2003 5 หลายเดือนก่อน +1

    thank you for this amazing explanation, hands down the best DSA teacher.

  • @aadarsh9719
    @aadarsh9719 8 หลายเดือนก่อน +1

    Amazing explanation please never stop uploading

  • @ravneetsingh1922
    @ravneetsingh1922 5 หลายเดือนก่อน +1

    best solution so far on this

  • @NachiketRakhonde
    @NachiketRakhonde 4 หลายเดือนก่อน +1

    bhai kya explain kiya hai 🙇‍♂

  • @rpc3340
    @rpc3340 ปีที่แล้ว +1

    great explanation

  • @vedbhanushali608
    @vedbhanushali608 ปีที่แล้ว +1

    loved your explanation thanks.

  • @aadityaDeshmukh0109
    @aadityaDeshmukh0109 ปีที่แล้ว +1

    sir your teaching style is brilliant. all concepts cleared related to the bit manipulation,thank you, sir, 😊

  • @shalinisrivastava762
    @shalinisrivastava762 13 วันที่ผ่านมา

    class Solution {
    public:
    int singleNumber(vector& nums) {
    unordered_map map;
    for (int i = 0; i < nums.size(); i++){
    map[nums[i]]++;
    }
    int ans=0;
    for (auto x : map){
    if(x.second==1) ans=x.first;
    }
    return ans;
    }
    };

  • @xiaoshen194
    @xiaoshen194 ปีที่แล้ว +3

    Very clever of them to repeat it thrice instead of twice (cuz u know... If they had given twice, u could just xor the entire array to get that unique number)

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +1

      Absolute ❤️❤️

    • @xiaoshen194
      @xiaoshen194 ปีที่แล้ว +2

      ​@@codestorywithMIKbtw is O( 31 * n) is bigger than O (n * logn) ?

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +1

      @@xiaoshen194 Let's say that n = INT_MAX in worst case.
      i.e. n = 2147483647
      Now, n*logn = n* log(2147483647) = n*31 approximately

  • @mohithadiyal6083
    @mohithadiyal6083 ปีที่แล้ว +1

    Best explanation 😊

  • @UmeshBisht-ik4li
    @UmeshBisht-ik4li ปีที่แล้ว +2

    Bhaiya third apporch is really good ❤

  • @tanujarora4906
    @tanujarora4906 ปีที่แล้ว +1

    Swaad aagya bhai kya hi explanation !💕

  • @prabhkiratsingh8793
    @prabhkiratsingh8793 ปีที่แล้ว +3

    You are an artist bro ❤🔥

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +1

      Thank you so much Prabhkirat ❤️❤️❤️

  • @ajit287
    @ajit287 ปีที่แล้ว +1

    Nice Concept Explanation !!!

  • @NarendraYadav-hf3ul
    @NarendraYadav-hf3ul ปีที่แล้ว +1

    Very good explanation🔥✨

  • @dikshantyadav1110
    @dikshantyadav1110 ปีที่แล้ว +1

    nice explanation ;)

  • @toptecher1633
    @toptecher1633 10 หลายเดือนก่อน +1

    Thanks sir for explanation ,now let me code it on my own without looking at your code.

  • @Vipulghadi
    @Vipulghadi ปีที่แล้ว +1

    nice sir

  • @AlishaKhan-ww3io
    @AlishaKhan-ww3io ปีที่แล้ว

    The cleanest explanation i saw till now for this problem ❤

  • @tutuimam3381
    @tutuimam3381 ปีที่แล้ว +1

    Thanks a lot

  • @wearevacationuncoverers
    @wearevacationuncoverers ปีที่แล้ว +1

    This is insanely well explained.
    You are amazing

  • @rohitshah8904
    @rohitshah8904 10 หลายเดือนก่อน

    Awesome explanation ❤

  • @harshitgarg2820
    @harshitgarg2820 11 หลายเดือนก่อน +1

    It was a different solution than other standard solutions but it was brilliantly explained. It doesn't use any complex logic but it's a slow solution because of the time complexity of O(32*n) and beats only 25% of people. In my opinion, it's still better to use a slow simple solution rather than cramming a difficult solution so Hats off. More power to you🚀🚀

    • @codestorywithMIK
      @codestorywithMIK  11 หลายเดือนก่อน +1

      Means a lot. Thank you so much 🙏❤️

  • @DevOpskagyaan
    @DevOpskagyaan 10 หลายเดือนก่อน

    Masterpiece 🔥

  • @UtkarshPatel-v9o
    @UtkarshPatel-v9o ปีที่แล้ว +1

    wow

  • @ridj41
    @ridj41 9 หลายเดือนก่อน

    I think sorting in worst case takes O(NlogN),where logN

  • @NikhilRaj-wv6nf
    @NikhilRaj-wv6nf ปีที่แล้ว +2

    just now I solved this question by hashmap and your notification popped up:(

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      Not a problem Nikhil.
      I am so glad you tried brute force approach as well.
      It's always a good thing to learn more approaches

  • @ayusharyan473
    @ayusharyan473 9 หลายเดือนก่อน

    thank you sir , best way of explenation can you make one video on backtracking

  • @saiyamjain5079
    @saiyamjain5079 2 หลายเดือนก่อน

    kth bit can also be found out by doing right shift by K times and then & 1 to get the bit as 1 or 0

  • @freefuree2345
    @freefuree2345 ปีที่แล้ว

    Sir u are Just awesome, can u make video on... Like taking 32 bit why.. And also where to use it....As in most of the concept.. We are using.. It.. Taking upto 2^32...checking up to it.. Whole concept... ✨please make video on this!!!

  • @raunakmishra8403
    @raunakmishra8403 ปีที่แล้ว +6

    such a nice explanation sirrr . i just can't share my feelings with words. you are 💎 . Thank uh so much.

  • @thekindspill
    @thekindspill ปีที่แล้ว

    This is lit bro 🔥 . Loved the simplicity of the explanation

  • @AnkitSingh-tm5dp
    @AnkitSingh-tm5dp ปีที่แล้ว +2

    👏👏🔥

  • @sakshammisra189
    @sakshammisra189 4 หลายเดือนก่อน

    W solution

  • @manishkumar-uw5mw
    @manishkumar-uw5mw ปีที่แล้ว +1

    🔥🔥🔥🔥

  • @sauravbiswajit8091
    @sauravbiswajit8091 ปีที่แล้ว +1

    Thanks a lot sir...
    Can you please make a dedicated video on bitmasking or say bit manipulation (if possible) and how to apply them on questions...it will be very helpful for us

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      Sure thing.
      Thanks a lot Saurav ❤️❤️

    • @sauravbiswajit8091
      @sauravbiswajit8091 ปีที่แล้ว

      @@codestorywithMIK yes thanks a lot again.. waiting for the video ..the way u are explaining...uff I am just getting addicted to your explanation

  • @Akashkumar_12
    @Akashkumar_12 5 หลายเดือนก่อน +1

    for checking set bit (number>>k)&1==1 then kth bit of number is set . this is true always or not please tell me thank you sir

  • @shabananoor9423
    @shabananoor9423 10 หลายเดือนก่อน

    🔥🔥👍👍

  • @souravjoshi2293
    @souravjoshi2293 10 หลายเดือนก่อน +2

    This is today's GFG POTD (4th Jan, 2024) as well.

  • @abhishekverma7604
    @abhishekverma7604 10 หลายเดือนก่อน

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

  • @codeandtalk6
    @codeandtalk6 ปีที่แล้ว +1

  • @ugcwithaddi
    @ugcwithaddi ปีที่แล้ว

    LEGEND

  • @doomhead9109
    @doomhead9109 ปีที่แล้ว +1

    if((num & temp) == 0) zcnt++;
    else ocnt++;
    if((num & temp) == 1) ocnt++;
    else zcnt++;
    Sir what is the difference between above two codes because first one giving the right answer while the second one is giving the wrong answer why ??
    And Thanks for the amazing explanation❤❤

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +3

      (num & temp) will not be equal to 1 always.
      (num & temp) can be 000100 as well which is not 1.

    • @doomhead9109
      @doomhead9109 ปีที่แล้ว +1

      @@codestorywithMIK Okay sir understood Thanks a lot sir extremely happy that I found your channel thanks sir for replying

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      Thank you so much ❤️❤️❤️

  • @rajshiromani727
    @rajshiromani727 6 หลายเดือนก่อน +2

    aisi aadat lag gyi h ki koi question serach krta hu is channel ka nam apne aap hi lga deta hu 😂😂
    btw great explaination as always!!
    aap college student h kya??

  • @aizad786iqbal
    @aizad786iqbal 5 หลายเดือนก่อน

    strangely I used the xor instead of or and result was same ... :D

  • @priyadarshanghoshhazra7648
    @priyadarshanghoshhazra7648 ปีที่แล้ว +1

    Sincere request Bhaiya can u bring a playlist on game theory since your explanation is op❤

  • @SumitKumar-mx4zr
    @SumitKumar-mx4zr ปีที่แล้ว

    Why we are calculating countZero if not using later?

  • @tauquirahmed1879
    @tauquirahmed1879 ปีที่แล้ว +1

    Bhaiya i saw another approach in the discuss section where the person solved this by doing XOR with the numbers and running a single loop. Although i didn't understand the approach.
    // here is the code
    int one = 0;
    int two = 0;
    for(auto num: nums)
    {
    one = (one^num) | ~two;
    two = (two^num) | ~one;
    }
    return one;
    If possible please make a video and explain this approach.

    • @wearevacationuncoverers
      @wearevacationuncoverers ปีที่แล้ว

      Yeah I also saw it but they are so bad at explanation. I didn't get those.

    • @nidhimishra2436
      @nidhimishra2436 ปีที่แล้ว

      @@wearevacationuncoverers from where you saw video?

    • @nidhimishra2436
      @nidhimishra2436 ปีที่แล้ว

      yess if possible then explain this code as well !

    • @wearevacationuncoverers
      @wearevacationuncoverers ปีที่แล้ว

      @@nidhimishra2436 No I didn't see any video on that. I just tried to understand from the explanation they provided in Discuss section. But couldn't understand

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +1

      I am aware of this approach but this is too tricky. It's not intuitive at all.
      It’s basically a very tricky approach. However my 3rd approach is Generalized approach.
      But I can make a video on this approach as well. But it's difficult to apply it in other problems

  • @ultimatequora
    @ultimatequora ปีที่แล้ว +1

    i am in tier-3 5th sem going to start .please advise me if I should revise love babbar sheet or should do I more questions?will love babbar sheet be enough

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      Hi there,
      If you are a fresher,
      I will suggest you to build your basics and practice more qns on each topic.
      Any sheet will be helpful if it covers multiple qns from each topic

  • @adarsh-g3r
    @adarsh-g3r ปีที่แล้ว +1

    I tried doing this
    for(int num:nums){
    if((num & temp)==1){
    ones++;
    }

    if(ones%3==1){
    result=(result | temp);
    }
    }
    and it didn't work . Since we are not using the count of zeros so we removed it , instead i checked for 1 like if that number had one in our 1

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +1

      Because (num & temp) will not be equal to 1 always.
      (num & temp) can be 000100 as well for example which is not equal to 1.

    • @adarsh-g3r
      @adarsh-g3r ปีที่แล้ว +1

      @@codestorywithMIK Thanks

  • @abhishekrai3
    @abhishekrai3 9 หลายเดือนก่อน

    bhaiya concept playlist kab aayegi (Bit Manipulation ka )

  • @aizad786iqbal
    @aizad786iqbal 5 หลายเดือนก่อน

    thanks
    the runtime for strange reasons was high
    so i checked other solutions
    class Solution {
    public int singleNumber(int[] nums)
    {
    int ones = 0;
    int twos = 0;
    for(int num : nums)
    {
    ones = ones ^ (num & ~twos);
    twos = twos ^ (num & ~ones);
    }
    return ones;
    }
    }
    are u aware about this approach ?
    seems interesting ..

  • @SudhanshuGupta-jb1lo
    @SudhanshuGupta-jb1lo 4 หลายเดือนก่อน

    can u do this in O(N) and no space

  • @floatingpoint7629
    @floatingpoint7629 ปีที่แล้ว +1

    thanks for the explanation it was help btw i do not think this is a good interview question as it depends upon a trick but its good that now i know it 🤣

  • @AkashSingh-vl6pq
    @AkashSingh-vl6pq ปีที่แล้ว

    bahiya by using map for -ve numbers answere is not correct.if possible then how.

  • @rishukumarsingh3926
    @rishukumarsingh3926 ปีที่แล้ว +1

    How negative numbers are handled?

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว +2

      Good qn.
      Please note that this will work for -ve numbers as well.
      Negative numbers are represented in two's compliment manner.
      So if nums is {-3, -3, -3, 1, 1, 1, 2}
      This will also work because in 2's compliment
      -3 will be represented as - '1111111111111101'
      And same will happen for other -3 in nuts.
      So anyways it will work.

    • @rishukumarsingh3926
      @rishukumarsingh3926 ปีที่แล้ว +1

      @@codestorywithMIK Thanks! Got it...

    • @codestorywithMIK
      @codestorywithMIK  ปีที่แล้ว

      Glad I could help 🙏

  • @tejaspatel2212
    @tejaspatel2212 ปีที่แล้ว

    hey i found this code, but didnt understand how it works. Can you please make a detailed video on this and explain?
    class Solution {
    public int singleNumber(int[] nums) {
    int ones = 0, twos = 0;
    for(int num : nums) {
    ones = (ones ^ num) & ~twos;
    twos = (twos ^ num) & ~ones;
    }
    return ones;
    }
    }

  • @dayashankarlakhotia4943
    @dayashankarlakhotia4943 10 หลายเดือนก่อน

    public int singleNumber (int[]arr,int n){
    int ones=0,twos=0;
    for(int i=0;i

  • @kennyackerman5429
    @kennyackerman5429 7 หลายเดือนก่อน

    Map complexity ONlogn not ON

  • @mohithadiyal6083
    @mohithadiyal6083 ปีที่แล้ว

    Can some one explain me why this code is not working for python

    • @tanumittal899
      @tanumittal899 ปีที่แล้ว

      same here, if you have found the solution in python, please share

  • @HoppyGamer
    @HoppyGamer ปีที่แล้ว

    Wrote this in python, failing for negative inputs, can anyone solve the problem?
    class Solution:
    def singleNumber(self, nums: List[int]) -> int:
    res = 0
    for k in range(32):
    count0 = count1 = 0
    temp = 1

    • @tanumittal899
      @tanumittal899 ปีที่แล้ว

      if you have found the solution in python, please share

    • @tanumittal899
      @tanumittal899 ปีที่แล้ว +1

      class Solution:
      def singleNumber(self, nums: List[int]) -> int:
      result = 0
      is_neg = 0
      for k in range(0, 32):
      temp = (1

    • @tanumittal899
      @tanumittal899 ปีที่แล้ว +1

      this is accurate code for python to handle -ve nos as well

    • @HoppyGamer
      @HoppyGamer ปีที่แล้ว

      @@tanumittal899 thanks