Vertical order traversal of a binary tree | Leetcode

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 พ.ย. 2024

ความคิดเห็น • 122

  • @pranayreddy6337
    @pranayreddy6337 3 ปีที่แล้ว +33

    The solution is really good, but I would like to point out that using set doesn't handle duplicate values. So to pass all the cases use multiset!

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว +2

      👍

    • @neversettlejay
      @neversettlejay 2 ปีที่แล้ว +3

      wait set doesn't handle duplicate values means!!!!? Set is meant to take just unique values right?

    • @dineshsaini6051
      @dineshsaini6051 2 ปีที่แล้ว

      @@neversettlejay yes, hence you'll end up missing duplicate values.

    • @pranavsharma7479
      @pranavsharma7479 2 ปีที่แล้ว

      use multiset

    • @commentator2407
      @commentator2407 2 ปีที่แล้ว

      @@neversettlejay ya

  • @raihanmdsiqbal9097
    @raihanmdsiqbal9097 3 ปีที่แล้ว +2

    Please keep this series on going and free of cost. Please

  • @dsacppracticequestion1123
    @dsacppracticequestion1123 2 ปีที่แล้ว +4

    Your teaching style is rock solid thanks for this wonderful explanation of the topic I stumbled upon.

    • @techdose4u
      @techdose4u  2 ปีที่แล้ว +1

      Thanks 👍🏼

  • @mayankgupta8715
    @mayankgupta8715 4 ปีที่แล้ว +1

    Ye tech ki dose bahut imp h.Ye sab coders ko leni chaiye.....

  • @okeyD90232
    @okeyD90232 3 ปีที่แล้ว +1

    wonderful explanation, solved this leetcode problem in one go just by following your explanation .

  • @ankitkumar-ih8qo
    @ankitkumar-ih8qo 3 ปีที่แล้ว +3

    Your intuition to explain is so good , and I have a doubt on for loop.... Would you please explain how the for loop work.?
    It really helpful to me

  • @pranavsharma7479
    @pranavsharma7479 2 ปีที่แล้ว

    best explaination for this problem and dfs is easier than bfs in this tbh

  • @code_life4835
    @code_life4835 4 ปีที่แล้ว +4

    I was getting runtime Error, but you solved my doubt. Thanks a lot for your Awesome Explanation!!

  • @mrmrigank7154
    @mrmrigank7154 3 ปีที่แล้ว +2

    thank you sir , your lectures help very much I just watched little of it and understood what to do next, thank you

  • @yitingg7942
    @yitingg7942 3 ปีที่แล้ว +6

    Solved it one try within 20 mins using treemap of treemap of priorityQueue. I must say I learned well from you lol. Thank you so much legend!!!

  • @ankitkumar-ih8qo
    @ankitkumar-ih8qo 3 ปีที่แล้ว +3

    great explanation, ans.push_back(vector()) , I dont understand what is these and why we use "vector()" ? Would you please explain me

  • @easycodingwithsumit
    @easycodingwithsumit 2 ปีที่แล้ว +1

    Too good explaination.This video is really good and all contents are easily understable .

  • @mayurganatra112
    @mayurganatra112 4 ปีที่แล้ว +2

    I was not able to solve the problem due to 1st constraint, thank you for the solution.

  • @princeakhil208
    @princeakhil208 4 ปีที่แล้ว +4

    The content of this channel is growing exponentially surely this will become a repository to crack faang interviews thanks for your effort tech dose

    • @techdose4u
      @techdose4u  4 ปีที่แล้ว +1

      Thanks for your appreciation. I hope it helps every student preparing for programming interviews.

  • @kunalsoni7681
    @kunalsoni7681 4 ปีที่แล้ว +3

    Seriously very amazing solutions of this problem you provide 😊.. thanking you so much sir

  • @CodeBrownie739
    @CodeBrownie739 ปีที่แล้ว

    finally understood the problem lots of the Thank you!!❤❤

  • @SHASHANKRUSTAGII
    @SHASHANKRUSTAGII 2 ปีที่แล้ว +1

    Better than striver! But you could have used unordered map and mutilset instead of map and set.

  • @santoshreddy3
    @santoshreddy3 4 ปีที่แล้ว +9

    Nice explanation. One finding though, Set will remove duplicates. For example if we have same values for given (x, y) coordinates, we will endup missing one value in output. Am I missing something?

    • @ratankumar1399
      @ratankumar1399 3 ปีที่แล้ว

      But it is assumed that there is no duplicates in Tree,if there is duplicates then go for multiset

    • @harshbokan6874
      @harshbokan6874 2 ปีที่แล้ว

      Use multiset

  • @vbalas9214
    @vbalas9214 3 ปีที่แล้ว

    what does iterating over m1.second and m2.second actually mean? Is m2.second having the values of the tree in the ascending order? And we are pushing a vector() into the ans 2d vector, is it just to create some space in the answer vector?

  • @infidarkstudios2066
    @infidarkstudios2066 4 ปีที่แล้ว +2

    Awesome solution dude. Hats off to you.

  • @milenitrivedi7561
    @milenitrivedi7561 2 ปีที่แล้ว

    Instead of using set using multiset will solve the problem of having duplicates in same row and col.

  • @vijayjayaram606
    @vijayjayaram606 3 ปีที่แล้ว +1

    Thay asked the same today in my interview
    Lucky me
    I watched this video after the interview
    Thank you youtube
    Ur recommendation algo sucks!

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว

      How does youtube know that you want to see this 😂 Google knows about your interview too!!

    • @vijayjayaram606
      @vijayjayaram606 3 ปีที่แล้ว +1

      @@techdose4u scary. My meeting invite 😱

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว +1

      @@vijayjayaram606 Haha :P

  • @VenkatIyer
    @VenkatIyer 3 ปีที่แล้ว

    Inside the first for loop, the first statement of pushing the vector() means are we pushing the entire vector?? I am confused with the representation.

  • @Apoorvpandey
    @Apoorvpandey 2 ปีที่แล้ว

    For duplicate values in Python simply use List and make sorting arrangements accordingly (DFS approach)

  • @adishijha8365
    @adishijha8365 4 ปีที่แล้ว +3

    Thank you so much! I was stuck at this question.. you made it clear.

  • @tusharbhatia9930
    @tusharbhatia9930 2 ปีที่แล้ว

    Can someone tell why "ans.push_back(vector())" is used in 1st approach);

  • @amitavamozumder73
    @amitavamozumder73 3 ปีที่แล้ว +1

    i don't think we have similar DS in nodeJS, map and set both follow insertion order here, so we manually need to sort the keys/values.

  • @nandanpabolu1787
    @nandanpabolu1787 12 วันที่ผ่านมา

    everything is good but you have named the coordinates of node values wrong, provided the root is the origin (0,0). Go to timestamp 12:43 for your reference.

  • @ajitshiva9193
    @ajitshiva9193 4 ปีที่แล้ว +2

    Brilliant approach.

  • @dollyakshaya7535
    @dollyakshaya7535 ปีที่แล้ว

    bhaiya explanation is awsm

  • @priyankanagaraju7590
    @priyankanagaraju7590 3 ปีที่แล้ว +1

    Really good explanation !

  • @praveenprakash6336
    @praveenprakash6336 4 ปีที่แล้ว +1

    Bro your explanation is truly good. Bro could you please make a video for 1st year students in order to get into product based companies.

    • @praveenprakash6336
      @praveenprakash6336 4 ปีที่แล้ว

      For students from tier 3 college.

    • @techdose4u
      @techdose4u  4 ปีที่แล้ว +1

      I will try to make it.

    • @praveenprakash6336
      @praveenprakash6336 4 ปีที่แล้ว

      @@techdose4u we will be waiting
      ..

    • @depression_plusplus6120
      @depression_plusplus6120 3 ปีที่แล้ว

      @@praveenprakash6336 forget bro...we NITS IITANS deserve them..you go for TCS🤣

    • @praveenprakash6336
      @praveenprakash6336 3 ปีที่แล้ว

      @@depression_plusplus6120 Don't judge a guy by his college okay.....

  • @varunnadipudi2257
    @varunnadipudi2257 4 ปีที่แล้ว +3

    Nicely explained🙌..keep up with this awesome work.👍

  • @JohnWick-kh7ow
    @JohnWick-kh7ow 3 ปีที่แล้ว +4

    Striver said that the time complexity is O(N*logN). You are saying that time complexity is O(N*logN*logN*logN). Which one is right?

    • @techdose4u
      @techdose4u  3 ปีที่แล้ว

      In the Map Map Set, if you use Unordered_map then time will be NlogN in total. If you use Map then NlogNlogNLogN. 2 extra logs for ordered map key search. So. It depends on your choice of DS.

    • @JohnWick-kh7ow
      @JohnWick-kh7ow 3 ปีที่แล้ว

      @@techdose4u I asked him he agreed that time complexity will be O(N*LogN*LogN*LogN). He told the time complexity of java code which is O(N*logN)

  • @sakthim7160
    @sakthim7160 4 ปีที่แล้ว +1

    Will you able to make videos on binary lifting? Which will be very helpful to solve problems like lowest common ancestor of given two nodes and kth ancestors of a given node in a tree.

    • @techdose4u
      @techdose4u  4 ปีที่แล้ว

      Its difficult to accomodate with graph videos as many of them are pending as well. So, I will try after graph.

    • @sakthim7160
      @sakthim7160 4 ปีที่แล้ว

      @@techdose4u thank you!

  • @dhanashreegodase4445
    @dhanashreegodase4445 2 ปีที่แล้ว +1

    Huge thanks💜

  • @AbhishekKumar-zs8zt
    @AbhishekKumar-zs8zt 4 ปีที่แล้ว +1

    awesome explanation

  • @prakharprakash4227
    @prakharprakash4227 2 ปีที่แล้ว +1

    Excellent explanation sir

  • @humble.660
    @humble.660 2 ปีที่แล้ว

    Code in Python for DFS(It becomes helpful with sorted function):
    class Solution:
    def helper(self, placement,level, root, dic):
    if(not root):
    return
    dic[placement].append((level, root.val))
    self.helper(placement-1, level+1, root.left, dic)
    self.helper(placement+1, level+1, root.right, dic)

    def verticalTraversal(self, root: TreeNode) -> List[List[int]]:
    dic = defaultdict(list)
    self.helper(0,0, root, dic)
    result = []
    for i in sorted(dic.keys()):
    temp = []
    for j in sorted(dic[i]):
    temp.append(j[1])
    result.append(temp)
    return result

  • @ShaliniNegi24
    @ShaliniNegi24 4 ปีที่แล้ว +1

    Nice explanation!

  • @sixth_sense_working
    @sixth_sense_working 2 ปีที่แล้ว

    can you let me know why we have inserting value on basis of col * row and not in row * col.

  • @ashwinvarma9349
    @ashwinvarma9349 4 ปีที่แล้ว +2

    That was epic explanation!

  • @sagnikroy4018
    @sagnikroy4018 3 ปีที่แล้ว +1

    Thank you so much

  • @sunilthind3257
    @sunilthind3257 4 ปีที่แล้ว +2

    Hello,
    Could you please help how to solve this question using JavaScript?
    Because map and set are little different in JS.

    • @techdose4u
      @techdose4u  4 ปีที่แล้ว +1

      I will ask people to share their code in comment in different languages. It will be much more helpful.

  • @motivationdaily37
    @motivationdaily37 ปีที่แล้ว

    Which will run faster BFS or DFS?

  • @sudinjana4402
    @sudinjana4402 3 ปีที่แล้ว

    but if we have duplicates elements in same row and column and set will not work it would be better to use vector instead of set

  • @bitrish34
    @bitrish34 3 ปีที่แล้ว

    What should be the space complexity?

  • @gauravshukla6675
    @gauravshukla6675 3 ปีที่แล้ว +1

    what is the time complexity of this code?

  • @md.giashuddin3083
    @md.giashuddin3083 2 ปีที่แล้ว

    This problem can be solved using HashMap & PriorityQueue in Java.
    `class Solution {
    public List verticalTraversal(TreeNode root) {
    Map map = new HashMap();
    int[] width = {0, 0};
    verticalTraversal(root, 0, 0, map, width);
    List result = new ArrayList();
    for (int i = width[0]; i

  • @deepjyotkaurbindra
    @deepjyotkaurbindra 3 ปีที่แล้ว +1

    BRILLIANT

  • @vijayjayaram606
    @vijayjayaram606 3 ปีที่แล้ว +1

    Approach = 🤘

  • @AdityaPratapSingh-ss8wg
    @AdityaPratapSingh-ss8wg 4 ปีที่แล้ว +1

    How to print top view of bi art tree in o(n)

  • @hemanthram4369
    @hemanthram4369 4 ปีที่แล้ว

    good problem

  • @AINeptune
    @AINeptune 3 ปีที่แล้ว

    how were we supposed to figure this out on ur own without looking at the solution?

  • @noobninja4882
    @noobninja4882 4 ปีที่แล้ว +1

    Thanks sir

  • @abhisheksuryavanshi9675
    @abhisheksuryavanshi9675 3 ปีที่แล้ว

    Not working for test case->
    [1,2,3,4,5,6,null,null,7,8,null,null,9,null,10,null,11,10],hence instead of set I took vector in map

  • @harshraj57
    @harshraj57 4 ปีที่แล้ว

    can we solve it recursively??

  • @CodeSuccessChronicle
    @CodeSuccessChronicle 3 ปีที่แล้ว +1

    Saviour!!

  • @aneeshreddy1534
    @aneeshreddy1534 4 ปีที่แล้ว +1

    what is the difficulty level of this one

  • @rohitkumaram
    @rohitkumaram 2 ปีที่แล้ว

    where you work Google or Meta?

  • @bhushanb8339
    @bhushanb8339 3 ปีที่แล้ว +1

    Code link is not reachable..

  • @neversettlejay
    @neversettlejay 2 ปีที่แล้ว

    TreeMap

  • @sase1017
    @sase1017 4 ปีที่แล้ว +1

    Hard to understand

    • @techdose4u
      @techdose4u  4 ปีที่แล้ว

      Please watch it again

    • @sase1017
      @sase1017 4 ปีที่แล้ว

      @@techdose4u Thank you so much, I understand pretty well and be able to code out by myself now, your visualization and explanation helped tremendously

  • @AsifKhan-fn2cy
    @AsifKhan-fn2cy 4 ปีที่แล้ว +1

    Nice explanation !