Загрузка...

Cousins in Binary Tree II | LeetCode 2641 in java | top DSA interview question | Must do Binary Tree

Question Link:- https://leetcode.com/problems/cousins-in-binary-tree-ii/description/

Cousins in Binary Tree II
2641. Cousins in Binary Tree II

leetcode daily problem today
leetcode daily problem today

daily leetcode problem today
daily leetcode problem today
daily leetcode problem today
leetcode daily problem today
leetcode daily problem today

daily leetcode problem today
daily leetcode problem today
daily leetcode problem today

today leetcode daily problem
today leetcode daily problem
today leetcode daily problem

Cousins in Binary Tree II
2641. Cousins in Binary Tree II

Given the root of a binary tree, replace the value of each node in the tree with the sum of all its cousins' values.
Two nodes of a binary tree are cousins if they have the same depth with different parents. Return the root of the modified tree.
Note that the depth of a node is the number of edges in the path from the root node to it.

my approach is simple i am using a Queue of Tree Nodes and keeping a variable for previous sum, initially i am adding the root node and previous vale as the root value.
after this we will keep on modifying every node value as the sum of its sibling nodes. and then we will keep on pop out the Node from list for the size taken times and push the children.
at every node we will keep track the sum of all the left right sum and assign this to previous variable for next level.
Usage Of Counting sort :- https://youtu.be/rszLo7LgwvE?si=Ly1u_QdBn9waMW0Q
DSA Algorithms :-
https://youtu.be/jF3bcJx5ppg?si=5ofIAuMKjvBDkrJ6
Design HLD:-
https://youtu.be/Q3Jfx0RJzrw

#coding #helpajobseeker #easyrecipes #leetcode #leetcodequestionandanswers #leetcodesolution #leetcodedailychallenge #leetcodequestions #leetcodechallenge #hindi #india #hindiexplanation #hindiexplained #easyexplaination #interview #interviewtips
#interviewpreparation #interview_ds_algo #hinglish

Видео Cousins in Binary Tree II | LeetCode 2641 in java | top DSA interview question | Must do Binary Tree канала Code Thoughts
Яндекс.Метрика
Все заметки Новая заметка Страницу в заметки
Страницу в закладки Мои закладки
На информационно-развлекательном портале SALDA.WS применяются cookie-файлы. Нажимая кнопку Принять, вы подтверждаете свое согласие на их использование.
О CookiesНапомнить позжеПринять