L7. Maximum XOR With an Element From Array | Queries | C++ | Java

Sdílet
Vložit
  • čas přidán 7. 12. 2021
  • Check our Website:
    In case you are thinking to buy courses, please check below:
    Link to get 20% additional Discount at Coding Ninjas: bit.ly/3wE5aHx
    Code "takeuforward" for 15% off at GFG: practice.geeksforgeeks.org/co...
    Code "takeuforward" for 20% off on sys-design: get.interviewready.io?_aff=takeuforward
    Crypto, I use the Wazirx app: wazirx.com/invite/xexnpc4u
    Take 750 rs free Amazon Stock from me: indmoney.onelink.me/RmHC/idje...
    Earn 100 rs by making a Grow Account for investing: app.groww.in/v3cO/8hu879t0
    Linkedin/Instagram/Telegram: linktr.ee/takeUforward
    ---------------------------------------------------------------------------------------------------------------------------------------------------- Pre-requisite: Playlist: • L1. Implement TRIE | I...
    In this video, we discuss the question Maximum XOR With an Element From Array, where we learn the technique of offline queries.
    Please share this channel as much as you can. Also, it's an earnest request to drop a comment "understood" if you are watching this video, so that I get to know you understood from this video.
    SDE-Sheet/Linkedin/Telegram/Instagram: linktr.ee/takeUforward
    -------------------------------------------------------------------------------------------------------------
    Problem Link: bit.ly/2YzYWev
    C++ Code: github.com/striver79/Strivers...
    Java Code: github.com/striver79/Strivers...

Komentáře • 233

  • @takeUforward
    @takeUforward  Před 2 lety +41

    Lets start a new trend, please comment "understood" and hit a like in case you did :)

    • @sejalrai7358
      @sejalrai7358 Před 2 lety

      awesome series as always!

    • @toptnn
      @toptnn Před 2 lety

      I am not understanding why online queries not working here? If it do pls explain

    • @soojaltech6455
      @soojaltech6455 Před 7 měsíci

      understood

  • @shambhavishandilya3490
    @shambhavishandilya3490 Před 2 lety +26

    Thank You so much for this playlist! Really enjoyed learning a new data structure. The teaching style was so impactful, that slowly I too started building the intuition for the solution along with the video. Again, Thanks for your efforts :)

  • @nagatanujabathena6319
    @nagatanujabathena6319 Před 2 lety +6

    UNDERSTOO! Loved the Tries playlist! Really enjoyed learning Tries. Thanks a lot for this!

  • @Dontpushyour_luck
    @Dontpushyour_luck Před 9 měsíci +2

    completed the trie playlist. always thought trie as some advanced stuff. but you made it so simple. thank you for such quality content!

  • @anshugupta1365
    @anshugupta1365 Před rokem +4

    Such a excellent playlist. Structured and good teaching. And yeah bonus point that no teacher goes to the root of dry run to the test cases but this man something else.

  • @bhushankorg5606
    @bhushankorg5606 Před rokem +11

    Thanks for such amazing playlists!
    You are really god for us. Can't imagine DSA without you.

  • @harshtewari4333
    @harshtewari4333 Před rokem +1

    The Playlist was Great and Easy to Understand. The Content was very high quality and well curated

  • @souradeepghosh5273
    @souradeepghosh5273 Před 2 lety

    another wonderful wonderful playlist. You nailed the job of teaching. Made it so easy. Absolutely understood. thanks a hell lot!🙌

  • @AbhishekKumar-qn5uc
    @AbhishekKumar-qn5uc Před 2 lety +2

    Thank you so much, before this playlist I used to afraid of Trie but now I am very confident.

  • @vaibhavagrawal3381
    @vaibhavagrawal3381 Před 2 lety

    Thanks for making this playlist, it really helped me in understanding trie.

  • @AritraChatterjee
    @AritraChatterjee Před 2 lety +1

    Great playlist! Thanks and looking forward for more such stuffs here :)

  • @sukhmanpreetsinghsandhub2042

    Understood with ease. Full playlist was very awesome .

  • @nilesh69420
    @nilesh69420 Před 3 měsíci

    Insanely good playlist. Solved all 7 mostly by myself or just taking a small hint from your intuition and then implemented by myself.

  • @jaiminsolanki5478
    @jaiminsolanki5478 Před 2 lety

    Thankyou so much Raj Bhaiya!!! Trie is Crystal clear now, learned a new data structure, so quick and with such ease with your explanation!

  • @priyajitpaul4190
    @priyajitpaul4190 Před rokem

    Thank you so much for this playlist Striver.Learned a new data structure.
    The way you made the last problem look so easy defines how quality teaching you provide to us❤..

  • @Hustler0109
    @Hustler0109 Před rokem

    Wonderful playlist! Thanks for making such a confusing topic so easy🙏🔥

  • @pranshujain6752
    @pranshujain6752 Před 2 lety

    bro you are the one whom teaching trie in this way ... thank you so much for this playlist.

  • @muskanpoddar7774
    @muskanpoddar7774 Před rokem

    I have understood all the question perfectly. Thank you so much striver for such amazing content.

  • @niyammuliya5787
    @niyammuliya5787 Před 2 lety +1

    understood. Thank you very much for this wonderful trie playlist.

  • @lavanyam3224
    @lavanyam3224 Před 4 měsíci

    Completed the Trie playlist!✅In every video, I was amazed by your talent of explaining every complex concept in a very understandable way. This playlist have definitely increased my confidence in solving Trie problems. Thanks a ton Striver! 💯💯💯🙏

  • @shyren_more
    @shyren_more Před rokem +1

    Enjoyed and understood the entire series thanks!

  • @AshishGupta-bi4rh
    @AshishGupta-bi4rh Před 2 lety

    Enjoyed a lot and learned so many new things, and unique ways to approach a problem statement.

  • @prashantdubey4112
    @prashantdubey4112 Před 2 lety

    Hello Raj bhaiya, just finished your Trie playlist and I would say I absolutely loved it.!! Thank you so much Raj bhaiya we owe you a lot!

  • @TheDivyansh007
    @TheDivyansh007 Před 6 měsíci

    Thank you for the playlist, really enjoyed the way you explained and the approach. understood

  • @manishkarmakar3927
    @manishkarmakar3927 Před měsícem

    No one could have explained this as good as you.. I repeat no one.. thanks 🥰

  • @sagarmittal1898
    @sagarmittal1898 Před 2 lety

    What a well curated playlist for Trie !

  • @aishwarymalviya2336
    @aishwarymalviya2336 Před měsícem

    Enjoyed learning from this tries playlist! One of the best playlist on Tries on CZcams.

  • @shubham320
    @shubham320 Před 2 lety

    Completed! Thank you for this.

  • @AyushKumar-oh6ke
    @AyushKumar-oh6ke Před rokem

    I definitely said that no body can taught likes u in India .. i hates all youtuber that can taught like u can remembered it...thanxx u so mch for this beautiful playlist

  • @architsrivastava7899
    @architsrivastava7899 Před rokem

    Was really helpful. A must watch playlist I would recommend !!!

  • @harshtyagi700
    @harshtyagi700 Před 2 lety +1

    UNDERSTOOD
    Thanks for your efforts in making awesome playlists like these.

  • @satyampande684
    @satyampande684 Před 2 lety +2

    Thanks for this trie series!! your way of teaching made this tough topic very easy.

  • @prachipardhi6324
    @prachipardhi6324 Před rokem

    you are an amazing teacher, I mean watching you at the speed of 2 x, it makes it more interesting.

  • @TheElevatedGuy
    @TheElevatedGuy Před 2 lety +5

    Fully Understood!
    Thank you bhaiya!
    Keep making these videos on these of concepts!
    We are very very lucky to have you!
    Successfully completed the playlist!
    1 doubt ->
    All these trie programs are running successfully on online platforms but in my local VS code & also on DEV C++ it is not giving proper correct output, though the same code is getting accepted on code studio.

  • @yashkumardhawan6961
    @yashkumardhawan6961 Před 2 lety +6

    Thanks a ton for such an amazing content.
    I never thought that just after 7 lectures I will be able to solve even the HARD level problems of trie with ease. The way Striver delivered the content to us was simply extraordinary. Now trie problems are a breeze to me. Thanks again and keep up the good work.
    Also it will be highly appreciable if you could come up with a similar kind of playlist for Algorithms.

  • @mohitgullani6268
    @mohitgullani6268 Před 3 měsíci

    I really enjoyed learning the Trie data structure!

  • @PriyanshuTyagi-ts2uw
    @PriyanshuTyagi-ts2uw Před měsícem

    Thanks a lot, striver, you are really the GOD of DSA!
    A pleasure to learn from you!

  • @utkarsh_108
    @utkarsh_108 Před 2 lety

    understoooooood. thanks for the efforts, now it's our part to perfom :)

  • @gouravkumar7459
    @gouravkumar7459 Před 2 lety

    Really enjoyed the Trie playlist :)

  • @anoopsingh8026
    @anoopsingh8026 Před 9 dny

    understood!! and done with graph, DP, bit manipulation, and now trie series. Thanks alot bhaiya for these helpful set of series.

  • @p38_amankuldeep75
    @p38_amankuldeep75 Před rokem +1

    very valuable playlist; enjoyed it;❤❤

  • @cripz4203
    @cripz4203 Před 3 měsíci +7

    Solution without sorting:
    1. Insert all arr elements into the trie
    2. Proceed with finding maxor as usual by passing both xi and ai with few differences to find the answer (max xor) as follows:
    3 For the answer, we retain xi's bit until and unless we find first set bit and always proceed with 0th node
    4 On finding the first set bit of ai in trie, at this position, go with node with bit opposite of xi for max xor (following same as previous algo) if possible, else continue with the other one. For next bit position in else case, follow below
    5 case ai's bit = 1: follow step (4)
    5 case ai's bit = 0: take 0th bit node as we can't take 1. And repeat this step until we encounter 1 in ai. If we do encounter follow step (4).

  • @priyanshvatsal9791
    @priyanshvatsal9791 Před 6 měsíci +1

    Understood 😇
    We can also keep a MIN at every node
    & when traversing just check if node->get(ch)->min

  • @dharani8871
    @dharani8871 Před rokem

    Thank you.....never thought tries were so beautiful

  • @bikashyadav7660
    @bikashyadav7660 Před 2 lety +2

    Please bro, if you got time ...make video on maximum Sum Rectangle problem also ..would be very beneficial

  • @namanchandak1532
    @namanchandak1532 Před rokem +1

    Good playlist
    I understood tries very well!

  • @bhupendrasingh8412
    @bhupendrasingh8412 Před 2 lety

    Thanks, Brother I have watched this playlist complete.

  • @nitishbyahut25
    @nitishbyahut25 Před 11 měsíci

    It wasnt that hard, as people make it look like ; @Striver bhaiya u really made tries so easy, Thank you!

  • @PravinShankhapal1
    @PravinShankhapal1 Před 2 lety

    It was a good playlist for anyone starting out trie.

  • @vedantagarwal22
    @vedantagarwal22 Před 2 lety

    wonderful series , thankyou !!

  • @vivekraj5254
    @vivekraj5254 Před rokem

    Thanks for this great playlist about Trie

  • @cs26divyanshisachan37
    @cs26divyanshisachan37 Před 4 měsíci

    This playlist was awesome! Thankyou striver

  • @vanshchaudhary8291
    @vanshchaudhary8291 Před 11 měsíci

    US ....Ur explanation is the best i'll come and edit this once i got placed because of u

  • @harshkanani6605
    @harshkanani6605 Před rokem

    amazing playlist striver sir thank you!!!

  • @davidmwangi4312
    @davidmwangi4312 Před 7 měsíci

    Best Trie Series. Having completed DP series as well. Much love from Kenya

  • @ThanosisContemplating
    @ThanosisContemplating Před 10 měsíci

    striver thanks a lot for this amazing explanation. i just had one doubt, how would we dry run and show this to the interviewer on an online platform or even if the interview's offline but they dont give pen and paper

  • @smitrami1757
    @smitrami1757 Před 2 lety

    Watched Whole series Striver !! Loved It :)

  • @MohitKumar-ys8jd
    @MohitKumar-ys8jd Před 23 dny

    Best playlist for Trie!! Thanks a lot striver bhaiya you are the best!! Keep doing the great work

  • @prashantsinghengineering6935

    We can also this using binary search + 2 pointer . Sort all numbers now we know if we got 0 at a bit then 1 will exist at another end , find its lower bound and change your left pointer , if now found that is this bot can never be 1 so move your right pointer and do this for all bit . Trie is classical, nice explanation

  • @hemanthsmarty4234
    @hemanthsmarty4234 Před 2 lety

    It's awesome. Really enjoyed alot

  • @DreamLife-05
    @DreamLife-05 Před 2 lety

    Enjoyable coding with you sir 🔥

  • @mantrarajgotecha3055
    @mantrarajgotecha3055 Před 2 lety

    Enjoyed trie playlist a lot :))

  • @vishalsiddha6637
    @vishalsiddha6637 Před 2 lety +1

    Thanks Striver for this!

  • @anshulgoel1940
    @anshulgoel1940 Před 8 měsíci +1

    Is it possible to solve it in an online manner where we check the bit value of both the numbers and allow only lessers numbers to compute XOR ?

  • @kavitgangar2510
    @kavitgangar2510 Před 2 lety

    You forgot mentioning the time complexity of sorting the original array at the start which will be O(NlogN). Because of this O(NlogN), wont the brute force approach (O(Q*N)) be better since in some cases it might be possible that Q < logN.

    • @sawankumar6355
      @sawankumar6355 Před rokem

      if you properly see constraints then Brute Force will give O(N^2)

  • @bidiptoroy6350
    @bidiptoroy6350 Před 2 lety

    Learnt Trie from 0, thanks a lot;

  • @ayushgautam169
    @ayushgautam169 Před rokem

    understood striver and thank you !!

  • @divyadwivedi1527
    @divyadwivedi1527 Před rokem

    Very nice playlist , but One important question is left out i.e, Implement a Phone Directory , Plz striver make a video on this as well.🙏

  • @codingmickey
    @codingmickey Před 11 měsíci

    thanks alot!! understood clearly

  • @nikunjgarg6636
    @nikunjgarg6636 Před rokem

    Thank you for this amazing playlist

  • @codingp110
    @codingp110 Před měsícem

    Wonderful Playlist!!!

  • @Avinash7381
    @Avinash7381 Před rokem

    Thanks for giving a good contains of trie.

  • @shubhankarsharma154
    @shubhankarsharma154 Před rokem

    Understood.. Thank you so much

  • @abhijeetbasfore6816
    @abhijeetbasfore6816 Před rokem

    Thank you for this series.

  • @manushukla7136
    @manushukla7136 Před 2 lety

    Thanks! Understood Trie!

  • @AdityaKumar-be7hx
    @AdityaKumar-be7hx Před 7 měsíci

    Finished it!!!!!

  • @idealspeaker1377
    @idealspeaker1377 Před rokem +1

    Only one word. Thank You!

  • @Lonewolf-ht8wu
    @Lonewolf-ht8wu Před rokem

    Thanks brother , you are awesome.
    🙌

  • @ankitpunia4722
    @ankitpunia4722 Před 2 lety

    what is the difference between hiring process of a fresher and 2 yr. experienced software engineer

  • @priyanshukoshta2307
    @priyanshukoshta2307 Před rokem

    Best ever Trie playlist on the Internet👍

  • @maheshsonnari8013
    @maheshsonnari8013 Před měsícem

    Understood from start till end without a doubt

  • @AdityaKumar-be7hx
    @AdityaKumar-be7hx Před 7 měsíci

    I think the TC will be O(QlogQ + NlogN) because of sorting

  • @kanchandubeyvlog
    @kanchandubeyvlog Před 2 lety

    Good morning amazing information beautiful sharing 🙏 plz stay connected I love your videos amazing sharing 😍❤️🙏my favourite subject I’m computer engineer 👩‍💻

  • @amishasahu1586
    @amishasahu1586 Před 2 lety

    "UNDERSTOOD". Great Series.

  • @SalimNashedi
    @SalimNashedi Před 2 lety

    Best Trie Playlist !!

  • @NISHKARSHMAITRYRA
    @NISHKARSHMAITRYRA Před 2 lety

    Hii want to know .. Why my application not selecting while applying through company job portal .. i am trying from last 1 year but rarely i get response . from there side ..

  • @vishwasmor9017
    @vishwasmor9017 Před 16 hodinami

    Another approach which can be used for both online and offline queries :-
    1. For each node define an integer variable "mini" which will store the minimum value of all the array elements which pass through it .
    2. Now we can always follow that path which contains its "mini" value lesser than X[i] if we can go both left and right means 0 and 1 then we will choose according to our requirement , if we want to go to right but can't then we try to go to left and vice versa and if we cant go left and right then we return -1 because their "mini" values are not less than X[i].
    Below is the code :---
    #include
    class Trie {
    public:
    class Node {
    public:
    Node* a[2];
    int mini;
    Node(){
    for(int j=0;ja[j] = NULL;
    }
    this->mini = INT_MAX;
    }
    };
    Node* head;
    Trie() {
    head = new Node();
    }
    void insert(int num){
    Node* tmp = head;
    for(int i=30;i>=0;i--)
    {
    int d = (1)&(num>>i);
    if(tmp->a[d] == NULL)
    {
    Node* tmpo = new Node();
    tmp->a[d] = tmpo;
    }
    tmp = tmp->a[d];
    tmp->mini = min(tmp->mini, num);
    }
    return;
    }
    int maxXOR(int num,int p){
    Node* tmp = head;
    int ans = 0;
    for(int i=30;i>=0;i--)
    {
    int d = 1-((1)&(num>>i));
    int left = tmp->a[0] == NULL ? INT_MAX : tmp->a[0]->mini;
    int right = tmp->a[1] == NULL ? INT_MAX : tmp->a[1]->mini;
    if(d == 1)
    {
    if(right

  • @BADASSBLADE
    @BADASSBLADE Před rokem

    understood, so much of knowledge

  • @sumedhvichare1388
    @sumedhvichare1388 Před 2 lety +1

    Thank you for this playlist Striver!

    • @takeUforward
      @takeUforward  Před 2 lety +3

      Thankyou, i will be glad if you can share this playlist across social media ♥️🔥

    • @divyadwivedi1527
      @divyadwivedi1527 Před rokem

      @@takeUforward Plz make a video on Implement a Phone Directory

  • @pavankongara792
    @pavankongara792 Před 2 lety

    Amazing!!!!!!!!!

  • @sumitkevlani5740
    @sumitkevlani5740 Před 2 lety

    All the questions were explained in a very nice manner but unable to understand this one because i am unable to understand that how can we sort 2-d ArrayList.

  • @anchitbhushan6172
    @anchitbhushan6172 Před 4 měsíci

    The offline query approach is 🔥

  • @anunaysharma294
    @anunaysharma294 Před 4 měsíci

    Loved it !!😄

  • @chandrachurmukherjeejucse5816

    Solved count zero request servers, which was long pending with this idea of storing the index with the query and then sorting so that we don't miss out the index. Thanks to the dsa ka heavy driver striver.

  • @nptel1punith929
    @nptel1punith929 Před 15 dny

    Enjoying every other playlist just like this.

  • @UECAshutoshKumar
    @UECAshutoshKumar Před 3 měsíci +1

    Thank you 🙏
    Understood!

  • @shahidkhan-ln8mz
    @shahidkhan-ln8mz Před 2 lety

    Waiting for the upcoming DP series🤩

  • @aryanmaniyar7301
    @aryanmaniyar7301 Před 8 měsíci

    Understood, thanks :)

  • @greedycat9845
    @greedycat9845 Před 2 lety

    understood. though i got this by myself 😄

  • @GauravKumar-ue7nz
    @GauravKumar-ue7nz Před 2 lety

    Awesome, Thank you Striver Bhaiya