Minimize XOR | Leetcode 2429

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

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

  • @RajeevCanDev
    @RajeevCanDev 12 дней назад +5

    slight correction in brute force:- when we linearly traverse we also need to check weather the number of set bits in that number is equal to set bits in num2 and also gives the minimal xor with num1, (great soln)

  • @nayankhanna2367
    @nayankhanna2367 12 дней назад

    Thank you, great explanation!

  • @81_monish_roy74
    @81_monish_roy74 9 дней назад

    Useful sir!!

  • @programming6177
    @programming6177 12 дней назад

    As usual, you did excellent teaching bro.😇

    • @techdose4u
      @techdose4u  12 дней назад

      Appreciate the love! ❤️

  • @samarthpatel2997
    @samarthpatel2997 12 дней назад +1

    Solid explanation, thank you!

  • @dracul_pubg5369
    @dracul_pubg5369 11 дней назад

    nice

  • @phanigaming4887
    @phanigaming4887 12 дней назад +3

    Brother how much is the cost of your program, I will try to join if I can afford?

  • @user-vm8yk9ic2c
    @user-vm8yk9ic2c 12 дней назад

    Thanks for the solution and explanation ;)))))))))))))))))) !!!

  • @YashWankhede-r4m
    @YashWankhede-r4m 12 дней назад

    THANKYOU SO MUCH Sir

  • @sailendrachettri8521
    @sailendrachettri8521 12 дней назад

    Thank you sir :)

  • @MansiMehta-n3v
    @MansiMehta-n3v 12 дней назад +3

    I didn't understand how counting the number of 1 was logN

    • @TheDurwasa
      @TheDurwasa 12 дней назад +3

      If the question is why the `while N {...}` becomes logN (instead of N) then the answer is -- any positive integer N has a maximum of logN + 1 bits in its binary representation (in order to convert a decimal number to binary we do N >> 1 or in other words we divide the problem space into half). The expression (N & (N - 1)) effectively removes one set bit (1) from the binary representation of N in each iteration.
      Combining both the arguments, the number of set bits in a number, which is at most logN + 1 for a number N. Thus the loop is guaranteed to run for almost logN times.
      Example -
      say n is 31 (11111)
      after first iteration - n=n&(n−1)=11111&11110=11110 (30)
      after second iteration n=n&(n−1)=11110&11101=11100 (28)
      after third iteration n=n&(n−1)=11100&11011=11000 (24)
      after fourth iteration n=n&(n−1)=11000&10111=10000 (16)
      after fifth iteration n&(n−1)=10000&01111=00000 (0)
      HTH!

    • @techdose4u
      @techdose4u  12 дней назад +1

      I thought you were asking 😅
      Nice detailed exampled 👌🏽

  • @siddarajhubballi598
    @siddarajhubballi598 12 дней назад

    Good explanation