1829. Maximum XOR for Each Query | C++ | Leetcode

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

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

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

    why k is alwsay 2^(maxBit)-1 because if k is 4 and the xor of array is 6 then 6 xor 9 gives maxAnswer than 6xor15 right

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

      No k is not always 2^(maxbit) - 1. We are calculating it in two steps. First maintaing a prefix vector which have XOR of elemnt till the current index. And the to find K value we have to XOR it with the number ranging from 0 to 2^(maxbit) which is 2^maxBit . And how to come up with knowing how only 2^maxBit giving the right K answer at the end we have to dry run the code manually.

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

    Mam, can you explain that "K'' i mean in example cases how that K is calculated ? 😭

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

      K is the maximum of XOR of all numbers after removing last element in each step and then do XOR with the maxBit ranging from 0 to 2^maxBit...as stated in question. Try doing dry run of the code you will understand it better.