Maximum XOR for Each Query - Leetcode 1829 - Python

Поділитися
Вставка

КОМЕНТАРІ • 27

  • @freecourseplatformenglish2829
    @freecourseplatformenglish2829 19 днів тому +54

    I really came here to underastand the problem description.

  • @123gostly
    @123gostly 19 днів тому +6

    It feels like the author of the problem first came up with the solution and then drafted a problem for the solution.

  • @mosestrosin
    @mosestrosin 18 днів тому +2

    that's a relief to see so many people confused, I'm neither a native English speaker nor a computer genius, I heavily questioned my entire life while reading this problem

  • @galaxybeat4057
    @galaxybeat4057 19 днів тому +13

    Let's say the current xor is 101010 and the mask is 001111. Wouldn't appending (xor ^ mask) to the results array give [100101] instead of [0101].
    I feel like the more appropriate statement should be res.append((xor ^ mask) & mask) Since it only appends the last 4 bits.
    Or maybe i'm just trippin idk.

    • @two697
      @two697 19 днів тому +2

      The problem constrains say that the mask is always greater than the lasted possible value in nums

    • @ASK-d3f
      @ASK-d3f 19 днів тому +2

      if we apply mask , it actually works differently by taking only required bits, in your case its last 4 bits and omitting the other bits in the result, it doesn't works using traditional xor rules here if we use mask, it takes last 4 bits only and appends to answer array

    • @balasriramdharmavarapu7024
      @balasriramdharmavarapu7024 19 днів тому

      U are correct, but here in this problem constraints it's mentioned that nums[i] < 2**maxBit. So it works out fine

    • @NeetCodeIO
      @NeetCodeIO  19 днів тому +3

      Good point, I forgot to mention the constraint others comments above me mentioned.
      The example you're referring to wouldn't actually exist, I should've used a different example.

    • @homyakMilashka
      @homyakMilashka 19 днів тому

      I had a solution for the general case but it included strings and vudu and I had the same question as you did =)))

  • @jody4210
    @jody4210 19 днів тому +4

    i came here to understand the question but im still confused its over for me

  • @codewithven9391
    @codewithven9391 18 днів тому

    Simpler solution
    It's just easier to go in the forward and keep track of the xor result. Then xor that with kMax and append to answer. You return the reverse of the answer list
    def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]:
    kMax = 2**maximumBit - 1
    ans = [nums[0] ^ kMax]
    currXor = nums[0]
    for i in range(1, len(nums)):
    currXor = currXor ^ nums[i]
    ans.append(currXor ^ kMax)
    return ans[::-1]

  • @albin_joby
    @albin_joby 19 днів тому

    I first came here to understand the problem description, and then I came here to understand the solution😁

  • @omargamal5648
    @omargamal5648 19 днів тому +6

    Bro u hacking them or wut

  • @ben94_
    @ben94_ 19 днів тому

    thank you. what a confusing problem description

  • @khushiipall
    @khushiipall 19 днів тому

    Now I understand what the problem is... i mean Wow 😵‍💫

  • @shivanshshekhar
    @shivanshshekhar 17 днів тому

    You are a legend

  • @nikenuke
    @nikenuke 19 днів тому

    thank you for the explanation!

  • @dusvn1484
    @dusvn1484 18 днів тому

    Brut force solution got time limited exceeded :D

  • @balasriramdharmavarapu7024
    @balasriramdharmavarapu7024 19 днів тому

    Your explanation is extremely elegant, but this solution only works if all the elements in nums are < 2**maxBit, which is the case in this problem. Which wasn't clear from your video, why that is the case

  • @princeakhil208
    @princeakhil208 19 днів тому +1

    I am kneeling 🙏🏻

  • @ssuriset
    @ssuriset 19 днів тому +1

    Neetcode!!!!!!!

  • @devmahad
    @devmahad 19 днів тому

    thanks :)

  • @the_doctor4616
    @the_doctor4616 19 днів тому +2

    is we have a same daily problem in leetcode?

  • @romi._.
    @romi._. 18 днів тому

    Bits problems sucks ! 👺

  • @AlfredPros
    @AlfredPros 19 днів тому +1

    The compact version and the true O(1) space solution of NeetCode's.
    def getMaximumXor(self, nums: List[int], maximumBit: int) -> List[int]:
    max_num = (1