Vertical Order Traversal of a Binary Tree - Google Interview Question

  Рет қаралды 7,789

Kunal Kushwaha

Kunal Kushwaha

6 ай бұрын

Learn how to solve the Vertical Order Traversal LeetCode problem frequently asked in Google interviews with this easy-to-understand, step-by-step tutorial.
Take part in the learning in public initiative! Share your learnings on LinkedIn and Twitter with #DSAwithKunal & don't forget to tag us!
👉 Resources
- Join Replit: join.replit.com/kunal-kushwaha
- Lecture code: replit.com/@KunalsReplit/Adva...
- Complete Java DSA playlist: • Java + DSA + Interview...
- Code, Assignments, & Notes: github.com/kunal-kushwaha/DSA...
➡️ Connect with me: kunalkushwaha.com
👨‍💻 Join WeMakeDevs: wemakedevs.org
#dsa #placement #leetcode

Пікірлер: 24
@KunalKushwaha
@KunalKushwaha 6 ай бұрын
👉 Resources - Join Replit: join.replit.com/kunal-kushwaha - Lecture code: replit.com/@KunalsReplit/AdvanceTreeQuestions
@varunsalian3909
@varunsalian3909 5 ай бұрын
Hi thanks for your efforts, have learnt a lot from your playlist, in this particular question you seem to have missed a use case, quoting from leetcode "There may be multiple nodes in the same row and same column. In such a case, sort these nodes by their values." Your code fails in leetcode for this particular use case.
@Sranju23
@Sranju23 4 ай бұрын
yeah looks like solution is for the LC # 314 instead
@sohansingh2022
@sohansingh2022 6 ай бұрын
Thanks. Hope you are well😊
@supunherath4808
@supunherath4808 6 ай бұрын
thanks a lot for doing this ❤
@NareshNaresh-cl8rn
@NareshNaresh-cl8rn Ай бұрын
Sir i am thankful for dsa playlist please complete the course sir
@vakeelsaab5323
@vakeelsaab5323 6 ай бұрын
Thanks Kunal
@erenyeager3659
@erenyeager3659 6 ай бұрын
hey @kunalKushwaha does learning spring help in my career is there any future for java devoloper
@DurgeshChauhan-lq8wq
@DurgeshChauhan-lq8wq 6 ай бұрын
Bhaiya dec end TK course complete ho jayega na please reply
@SiliO_
@SiliO_ 6 ай бұрын
bro please suggest me graphs and dp best resource
@karthik_macharla
@karthik_macharla 27 күн бұрын
Hi Kunal, we're waiting for DP and Graphs playlist
@preetichib2254
@preetichib2254 5 ай бұрын
great explaination
@veerendrasaikumar1008
@veerendrasaikumar1008 4 ай бұрын
Thanks for the great explanation, as per leet code description, Kunal, you missed to sort the elements with the same row and same column while adding it into the ans arraylist
@SarcasticAI-wh3mf
@SarcasticAI-wh3mf 2 ай бұрын
below code works class Solution { class Tuple{ TreeNode node; Integer col; Integer row; Tuple(TreeNode n,Integer c,Integer r){ node = n; col = c; row = r; } } public List verticalTraversal(TreeNode node) { List ans = new ArrayList(); if (node == null) { return ans; } int col = 0; int row = 0; Queue queue = new ArrayDeque(); TreeMap map = new TreeMap(); queue.offer(new Tuple(node, col,row)); int min = 0; int max = 0; while(!queue.isEmpty()) { Tuple removed = queue.poll(); node = removed.node; col = removed.col; row = removed.row; if(node != null) { map.putIfAbsent(col, new TreeMap()); map.get(col).putIfAbsent(row, new PriorityQueue()); map.get(col).get(row).add(node.val); min = Math.min(min, col); max = Math.max(max, col); queue.offer(new Tuple(node.left, col-1,row+1)); queue.offer(new Tuple(node.right, col+1,row+1)); } } // Loop through the map and add the values. // x -> key, (y, nodes) -> values. for (TreeMap yn : map.values()) { // Create a sublist to store node values in each vertical. List sublist = new ArrayList(); // Iterate over the PriorityQueue and add nodes to the sublist. for (PriorityQueue nodes : yn.values()) { while (!nodes.isEmpty()) { sublist.add(nodes.poll()); } } // Add the sublist to the ans list. ans.add(sublist); } return ans; } }
@upsidedown6204
@upsidedown6204 4 ай бұрын
well explained bhaiya
@jnayehsirine6222
@jnayehsirine6222 5 ай бұрын
Iam proud of myself i got the answer is less than 20min !!
@IndianKing97
@IndianKing97 6 ай бұрын
KUNAL OP❤
@pavan305
@pavan305 6 ай бұрын
Thumbnails?! 🤔
@HeyMr.OO7
@HeyMr.OO7 6 ай бұрын
Yeah... Thumbnails revised to match the earlier videos like binary search tutorial one ...
@user-cd2sg2sr1r
@user-cd2sg2sr1r 4 ай бұрын
@kunal bhai i think BFS and DFS didn't cover in these course ?
@sufiserious798
@sufiserious798 2 күн бұрын
Covered, in the 5hr tree questions video.
@arulkumar998
@arulkumar998 4 ай бұрын
face freeze sometimes
@ramanshrivastava1407
@ramanshrivastava1407 13 күн бұрын
nice explanation sir . watching from 2024 🫡
Word Ladder - LeetCode Hard - Google Phone Screen Interview Question
17:45
Eccentric clown jack #short #angel #clown
00:33
Super Beauty team
Рет қаралды 26 МЛН
La final estuvo difícil
00:34
Juan De Dios Pantoja
Рет қаралды 29 МЛН
OMG 😨 Era o tênis dela 🤬
00:19
Polar em português
Рет қаралды 12 МЛН
Chips evolution !! 😔😔
00:23
Tibo InShape
Рет қаралды 43 МЛН
Vertical order traversal of a binary tree | Leetcode #987
18:03
Binary tree: Level Order Traversal
11:23
mycodeschool
Рет қаралды 597 М.
LOWEST COMMON ANCESTOR OF A BINARY TREE III [PYTHON]
16:38
Cracking FAANG
Рет қаралды 8 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 591 М.
Introduction to HashMap & HashTable in Java
1:39:46
Kunal Kushwaha
Рет қаралды 65 М.
N-Queens, N-Knights, Sudoku Solver (LeetCode) - Backtracking Questions
1:19:26
Nokia 3310 versus Red Hot Ball
0:37
PressTube
Рет қаралды 3,8 МЛН
iphone fold ? #spongebob #spongebobsquarepants
0:15
Si pamer 😏
Рет қаралды 401 М.
cool watercooled mobile phone radiator #tech #cooler #ytfeed
0:14
Stark Edition
Рет қаралды 7 МЛН
😱НОУТБУК СОСЕДКИ😱
0:30
OMG DEN
Рет қаралды 2,8 МЛН
МОЖНО ЛИ заряжать AirPods в чехле 🧐😱🧐 #airpods #applewatch #dyson
0:22
Apple_calls РЕПЛИКА №1 В РФ
Рет қаралды 22 М.
What percentage of charge is on your phone now? #entertainment
0:14