Cousins in a binary tree | Leetcode #993

preview_player
Показать описание
This video shows a very important programming interview question based on binary tree data structure which is to find if two given nodes are cousins or not. This problem has frequently been asked in MNCs interviews both in college and off-campus and also asked for internship. I have explained the intuition for solving this problem and have taken proper examples and handled the boundary cases while explanation. I have also shown the CODE at the end of the video and the CODE LINK is given below as usual. I have also given link to some similar problems as well. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)

SIMILAR PROBLEMS:-
Рекомендации по теме
Комментарии
Автор

Just got this question in an interview and choked😭😭😭 Thank you for your video brother

BruceyBit
Автор

I really appreciate how precise you are about definitions of Height and Depth.
Your Leetcode walkthroughs convey the importance of using terms properly.
Well done, Sir!

CostaKazistov
Автор

It can be made simpler by getting level of both the nodes, if level is same return true and check for parent of both the nodes if parent is same return true and then check for both conditions that if the level of both nodes is same and they are siblings then they cant be cousins.

arshneetkathuria
Автор

first thought : preorder traversal and for each node check if left and right are x and y (order not imp)

utkarshgupta
Автор

That problem is not easy. At least medium IMO

cloud
Автор

Why did u update parent separately for both left and right calls?

BurlaSaikrishna
Автор

we can find LCA (lowest common ancestor) of the two given nodes and can be checked

anonymous-skpr
Автор

We can use a map to store height and parent of every root and then compare the parent and height of the given nodes accordingly.

cyruspassi
Автор

Didn't understand "root = x or y then part, can you explain it more. what is x and y at any given point of time?

KiranKumar-cnpm
Автор

do you use external mic to record your videos?

arpitkhandelwal
Автор

What do you use to create videos? And editing on the screen? I am a newbie. Thinking of acquiring some skills on video making during this corona time. Could you suggest how I can start with? Which tools?

algorithmimplementer
Автор

Why do we need line 24? I dont quite understand that since we already declared that on line 20. Thanks!

dayal
Автор

Good effort

making this video understandable and simple

md_aaqil
Автор

Hi brother, i just a beginner in java, what are the steps i have to follow to solve leetcode problems
Plz explain sir

gudlagudla
Автор

Sir why you have used the codes ios base and 2 more lines next to it when the data is coming as parameters of the function??

aniruddhabhattacharya
Автор

Hi, thanks so much for the explanation. I always wait for your video, can you please also make more videos on graphs?

abhinavminocha
Автор

Can you provide me the level order traversal code for this. I'm finding it hard to implement it in a code :(

chinmaypareek
Автор

what is the reason behind taking the reference of parent and not the value...plz explain!!

RaviYadav-xghy
Автор

We can also apply bfs if shortest path from root are equal with different predecessor then it will be cousin

Navneetkumar-oscl
Автор

Can we do better. I created an pair array storing parent and depth of each node, then checked for condition. But I think there could be done something better.

Amit_Kumar_
welcome to shbcf.ru