Skip to content
Discussion options

You must be logged in to vote

We need to recover the values of a contaminated binary tree and efficiently check if a target value exists in the recovered tree. The tree's structure is preserved, but all node values are set to -1. The original tree follows specific rules where each node's value determines its children's values. We need to recover these values and provide an efficient way to check for the existence of a target value.

Approach

  1. Recover the Tree: Use a Breadth-First Search (BFS) traversal starting from the root. The root value is set to 0. For each node, compute its left and right children's values based on the rules provided (left child: 2 * parent's value + 1, right child: 2 * parent's value + 2).
  2. Store…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Feb 21, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Feb 21, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants