Now I can say my Nonlinear Data structure journey has been started with Anuj Bhaiya 🙏🙏🙏🙏🙏 Thank You Sir ❣❣❣❣.
@raghunath42802 жыл бұрын
Nice solution. But i found out a little bit optimization for the above solution. Consider d= horizontal diameter of the tree. Building Treemap takes o(dlogd). Instead of TreeMap use HashMap and maintain two static variables i.e., min and max and update the min and max values as min=Math.min(min,temp.hd); max=Math.max(max,temp.hd); for every iteration. Now traverse the HM from min to max and add those values to a new ArrayList. This will reduce the time complexity from O(n+dlogd) to O(n)
@GhostRider....2 жыл бұрын
Bro please provide full solution
@yhlive8023 Жыл бұрын
You're right i been thinking the same bro , use min max and hashmap
@grossHumiliation Жыл бұрын
bro this is correct? void topView(Node *root, int x, map &m) { if (root == NULL) return; if (m.find(x) == m.end()) { m.insert(make_pair(x, root->data)); } topView(root->left, x - 1, m); topView(root->right, x + 1, m); }
@jerrykodes7 ай бұрын
Nice one!
@abdullahirfan30782 жыл бұрын
Never knew that this medium level topic is going to be so easy for me Thank yoy
@Jitendrachouhan19992 жыл бұрын
You are Such as Good Mentor 🥰 i really inspired your video when did I watch ❤
@Ladder2Corporate7 ай бұрын
, vertical order, top view, bottom view, what an explanation ☺☺☺
@RepublicDay20232 жыл бұрын
You are genious dude…!!! Applauses 👌👌👌
@udaychandu39252 жыл бұрын
Very Clean and Neat Explaination,Sir!
@ANJALIGUPTA-vq1cv2 жыл бұрын
awesome bhaiya, thanks for making coding easier
@MindsetMotivation752 жыл бұрын
Thank you bhaiya , best explanation ever.
@amanrathour31762 жыл бұрын
So easily explained 😍. Thanku.
@shreysom20602 жыл бұрын
Great explaination
@anandjaiswal6588 Жыл бұрын
Maaza aa gaya 😁
@GhostRider....2 жыл бұрын
Nice explanation bhaiya
@saritaprasad4295 Жыл бұрын
amazing with most difficult topic
@xerOnn352 жыл бұрын
Thanks Sir !
@harshvardhansingh7802 жыл бұрын
Thank you so much bhaiya mai yhi same glti kar rha tha.... thank you
@prannoyroy53122 жыл бұрын
Thanks Anuj! Great job bro! 👌
@pinkkitty6553 Жыл бұрын
Thank you bhaiya
@jeeveshsinghroa3218 Жыл бұрын
Good Solution!
@militaryink3192 жыл бұрын
Thanks bhya . I am following you
@Rorschach_ind Жыл бұрын
This video was helpful!
@lokendrasingh97802 жыл бұрын
Thank You Bhaiya🙏👌
@hangover2.08 ай бұрын
for implementing the queue method we can define three variables in class third one to store level and in the if condition we will check using or operator that if the level of incoming node is lesser than the already existing node it will replace the node. Please tell me if something is wrong with this approach . Open to other suggestions.
@tech_wizard93152 жыл бұрын
Can you please provide a 60roamdap of important topics for DSA beginner to crack tech giant's like Microsoft linkedin etc
@AnujBhaiya2 жыл бұрын
This is next in line.. will be coming out soon 😄 stay tuned
@prateekchauhan53762 жыл бұрын
loveddddd it
@ShivamVerma-gq2sm2 жыл бұрын
wonderful
@anuj_abh2 жыл бұрын
Few days ago, bhaiya you suggested a youtube channel for learning java from scratch (u told, u also learnt from there) please give that channel link again, I forget that channel name. 🙏🏻
@King-xs4tq2 жыл бұрын
Malum pada bhai
@anuj_abh2 жыл бұрын
@@King-xs4tq ni bhai, agr pta chale to btana
@King-xs4tq2 жыл бұрын
@@anuj_abh Nahi bhai maine to bhaiya ke course se hi pada tha java lekin beginners ke liye utna fayde ka nahi h. Agar aapko malum padey to bataiyega
@shivamchaurasiya20042 жыл бұрын
Bhaiyaa DevOps par ek video banaiye isme career kaise banaye
@YashTalks_YT2 жыл бұрын
many teachers can't even accept their mistakes
@madetolaugh34762 жыл бұрын
Largest BST
@sumitchakraborty94512 жыл бұрын
what is the time complexity of this solution
@ImranKhan-mc6vf2 жыл бұрын
Not sure if it is the correct logic for bottom view. Consider this example. 7(0) / \ 6 (-1) 2 (1) / \ / \ 5 ( -2 ) 1(0) 8(0) 2 (2) We have 2 0s at bottom, but the map would hold just 1 zero. So your logic would give -> 5, 8, 2 instead of 5,1,8,2. Or am I missing something?
@kumarrohit83112 жыл бұрын
See the video at 1:07. He talks about when two elements with same distance are met, we pick the right side one. Hence, 8 is picked up!
@pulkitchausali13542 жыл бұрын
Output will like -> 5, 6, 8, 2, 2
@kanaramjangid85634 ай бұрын
❤❤❤
@mohakarora87128 ай бұрын
can somebody tell me why are we using level order only?
@rahulji8822 жыл бұрын
22nd link
@wizardiors2 жыл бұрын
did u have a computer science degree??
@mastimazawithnature67492 жыл бұрын
Is dsa course me kya sikhne ko milega
@AnujBhaiya2 жыл бұрын
You'll learn almost anything there's to learn about Data Structures & Algorithms so that you can crack Top companies technical interviews easily. Many of you have already done it. Best of Luck 🤗
@shaileshtiwari9570 Жыл бұрын
why we don't take preorder traversal for bottom view , kindly give a tree example where preorder traversal gives wrong answer.
@worldpuzzle10312 жыл бұрын
❤️❤️
@harishlodha87942 жыл бұрын
Sir background video recorder app se user Jo video record karta hai kya vo video app Wale ke pass bhi store hota hai kya Kya ye possible hai ki Jo video hum record karte hain vo app Wale ke pass bhi store hota hai kya
@akashmishra33692 жыл бұрын
Bhaiya, TreeMap nahi use karke, Map ko sort kardein end me to kaam nahi banega ? :( (Not sure how to implement Treemap in javascript)
@AnujBhaiya2 жыл бұрын
Ho jaega usse bhi
@harshit41902 жыл бұрын
time complexity?
@antibarcelona21232 жыл бұрын
O(no. of nodes i guess)
@lakhanshanker61052 жыл бұрын
static ArrayList topView(Node root) { Map map = new TreeMap(); int i=0; util(root,i,map); ArrayList ans = new ArrayList(); for(Map.Entry m : map.entrySet()){ int x = m.getValue(); ans.add(x); } public static void util(Node root, int i, Map map){ if(root==null) return; if(!map.containsKey(i)){ map.put(i,root.data); } util(root.left,i-1,map); util(root.right,i+1,map); } isme kya galti hai anyone ?
@pratikvishwakarma15992 жыл бұрын
ans.add(x); } } you need to close extra } , :P Otherwise check the video again on 04:05, where Anuj Bhaiya explains why normal traversal (preorder) will fail
@lakhanshanker61052 жыл бұрын
@@pratikvishwakarma1599 bhai wo to thek h pr sare test cases pass nhi ho rhe
@mastimazawithnature67492 жыл бұрын
Binary code kya hota hai Kya isse me kya kr sakta hu
@harsh_choudhary59402 жыл бұрын
@Kumar Chitransh abe😂😂
@yhlive8023 Жыл бұрын
@Kumar Chitransh 😂
@RajatGupta-lq3cb2 жыл бұрын
Can someone help me. What if we solve it in this way using DFS? class Solution { static int min=0, max=0; static ArrayList topView(Node root) { ArrayList res=new ArrayList(); Map mp=new HashMap(); helper(root, mp, 0, 0); for(int i=min;i vd) { mp.put(hd, new Pair(root.data, vd)); } } else { mp.put(hd, new Pair(root.data, vd)); } helper(root.left, mp, hd-1, vd+1); helper(root.right, mp, hd+1, vd+1); } } class Pair { int val, vd;// vd represents vertical distance from root AKA depth. public Pair(int a, int b) { val=a; vd=b; } }
@yhlive8023 Жыл бұрын
It will be complicated bro but it's your choice how you want to do 😊