L7. Maximum XOR With an Element From Array | Queries | C++ | Java
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...
Lets start a new trend, please comment "understood" and hit a like in case you did :)
awesome series as always!
I am not understanding why online queries not working here? If it do pls explain
understood
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 :)
UNDERSTOO! Loved the Tries playlist! Really enjoyed learning Tries. Thanks a lot for this!
completed the trie playlist. always thought trie as some advanced stuff. but you made it so simple. thank you for such quality content!
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.
Thanks for such amazing playlists!
You are really god for us. Can't imagine DSA without you.
The Playlist was Great and Easy to Understand. The Content was very high quality and well curated
another wonderful wonderful playlist. You nailed the job of teaching. Made it so easy. Absolutely understood. thanks a hell lot!🙌
Thank you so much, before this playlist I used to afraid of Trie but now I am very confident.
Thanks for making this playlist, it really helped me in understanding trie.
Great playlist! Thanks and looking forward for more such stuffs here :)
Understood with ease. Full playlist was very awesome .
Insanely good playlist. Solved all 7 mostly by myself or just taking a small hint from your intuition and then implemented by myself.
Thankyou so much Raj Bhaiya!!! Trie is Crystal clear now, learned a new data structure, so quick and with such ease with your explanation!
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❤..
Wonderful playlist! Thanks for making such a confusing topic so easy🙏🔥
bro you are the one whom teaching trie in this way ... thank you so much for this playlist.
I have understood all the question perfectly. Thank you so much striver for such amazing content.
understood. Thank you very much for this wonderful trie playlist.
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! 💯💯💯🙏
Enjoyed and understood the entire series thanks!
Enjoyed a lot and learned so many new things, and unique ways to approach a problem statement.
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!
Thank you for the playlist, really enjoyed the way you explained and the approach. understood
No one could have explained this as good as you.. I repeat no one.. thanks 🥰
What a well curated playlist for Trie !
Enjoyed learning from this tries playlist! One of the best playlist on Tries on CZcams.
Completed! Thank you for this.
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
Was really helpful. A must watch playlist I would recommend !!!
UNDERSTOOD
Thanks for your efforts in making awesome playlists like these.
Thanks for this trie series!! your way of teaching made this tough topic very easy.
Thanks for recommending this series!!
you are an amazing teacher, I mean watching you at the speed of 2 x, it makes it more interesting.
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.
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.
I really enjoyed learning the Trie data structure!
Thanks a lot, striver, you are really the GOD of DSA!
A pleasure to learn from you!
understoooooood. thanks for the efforts, now it's our part to perfom :)
Really enjoyed the Trie playlist :)
understood!! and done with graph, DP, bit manipulation, and now trie series. Thanks alot bhaiya for these helpful set of series.
very valuable playlist; enjoyed it;❤❤
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).
Can u share the code for this?
good answer
Understood 😇
We can also keep a MIN at every node
& when traversing just check if node->get(ch)->min
Good idea, will try implementing this
Thank you.....never thought tries were so beautiful
Please bro, if you got time ...make video on maximum Sum Rectangle problem also ..would be very beneficial
Good playlist
I understood tries very well!
Thanks, Brother I have watched this playlist complete.
It wasnt that hard, as people make it look like ; @Striver bhaiya u really made tries so easy, Thank you!
It was a good playlist for anyone starting out trie.
wonderful series , thankyou !!
Thanks for this great playlist about Trie
This playlist was awesome! Thankyou striver
US ....Ur explanation is the best i'll come and edit this once i got placed because of u
amazing playlist striver sir thank you!!!
Best Trie Series. Having completed DP series as well. Much love from Kenya
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
Watched Whole series Striver !! Loved It :)
Best playlist for Trie!! Thanks a lot striver bhaiya you are the best!! Keep doing the great work
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
Thanks for this approach!
It's awesome. Really enjoyed alot
Enjoyable coding with you sir 🔥
Enjoyed trie playlist a lot :))
Thanks Striver for this!
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 ?
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.
if you properly see constraints then Brute Force will give O(N^2)
Learnt Trie from 0, thanks a lot;
understood striver and thank you !!
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.🙏
thanks alot!! understood clearly
Thank you for this amazing playlist
Wonderful Playlist!!!
Thanks for giving a good contains of trie.
Understood.. Thank you so much
Thank you for this series.
Thanks! Understood Trie!
Finished it!!!!!
Only one word. Thank You!
Thanks brother , you are awesome.
🙌
what is the difference between hiring process of a fresher and 2 yr. experienced software engineer
Best ever Trie playlist on the Internet👍
Understood from start till end without a doubt
I think the TC will be O(QlogQ + NlogN) because of sorting
Good morning amazing information beautiful sharing 🙏 plz stay connected I love your videos amazing sharing 😍❤️🙏my favourite subject I’m computer engineer 👩💻
"UNDERSTOOD". Great Series.
Best Trie Playlist !!
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 ..
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
understood, so much of knowledge
Thank you for this playlist Striver!
Thankyou, i will be glad if you can share this playlist across social media ♥️🔥
@@takeUforward Plz make a video on Implement a Phone Directory
Amazing!!!!!!!!!
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.
The offline query approach is 🔥
Loved it !!😄
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.
Enjoying every other playlist just like this.
Thank you 🙏
Understood!
Waiting for the upcoming DP series🤩
Understood, thanks :)
understood. though i got this by myself 😄
Awesome, Thank you Striver Bhaiya