menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Data Science News

>

LeetCode 9...
source image

Dev

2w

read

222

img
dot

Image Credit: Dev

LeetCode 993: Cousins in Binary Tree – DFS and BFS Approaches Explained (Python)

  • LeetCode 993: Cousins in Binary Tree – DFS and BFS Explained (Python)
  • Two nodes of a binary tree are cousins if they have the same depth but different parents.
  • DFS approach: Defines a helper function to find the depth and parent of the given node recursively.
  • BFS approach: Uses a queue to traverse the tree level-wise and checks if the given nodes have the same depth and different parents.

Read Full Article

like

13 Likes

For uninterrupted reading, download the app