All Posts

Leetcode 1530: Number of Good Leaf Nodes Pairs

You are given the root of a binary tree and an integer distance. A pair of two different leaf nodes is considered good if the shortest path between them is less than or equal to the given distance. The task is to return the number of such good leaf node pairs in the tree.

Leetcode 1609: Even Odd Tree

A binary tree is called Even-Odd if the values in each level of the tree follow certain rules. For every even-indexed level, all nodes must contain odd integers in strictly increasing order. For every odd-indexed level, all nodes must contain even integers in strictly decreasing order. Given the root of a binary tree, return true if the tree is Even-Odd, otherwise return false.

Leetcode 2049: Count Nodes With the Highest Score

You are given a binary tree with n nodes, where each node is labeled from 0 to n-1. The tree is represented by a 0-indexed array parents, where parents[i] indicates the parent of node i. The root node has no parent, so parents[0] == -1.

Each node has a score, calculated as follows:

  1. If the node and the edges connected to it are removed, the tree splits into one or more non-empty subtrees.
  2. The score of a node is the product of the sizes of all resulting subtrees.

Return the number of nodes with the highest score in the tree.

Leetcode 2096: Step-By-Step Directions From a Binary Tree Node to Another

You are given a binary tree where each node has a unique value between 1 and n. You are also given a start node and a destination node, each represented by their values. Your task is to find the shortest path from the start node to the destination node in terms of directions. The directions should be represented by a string using the characters ‘L’, ‘R’, and ‘U’, where ‘L’ means left child, ‘R’ means right child, and ‘U’ means moving to the parent node.

Leetcode 2196: Create Binary Tree From Descriptions

You are given a list of triplets representing the structure of a binary tree. Each triplet [parent, child, isLeft] indicates that parent is the parent of child, and if isLeft is 1, child is the left child of parent, otherwise, it’s the right child. Your task is to reconstruct the binary tree and return the root node.

Leetcode 2236: Root Equals Sum of Children

You are given a binary tree with three nodes: the root, its left child, and its right child. Determine whether the value of the root node is equal to the sum of the values of its two children.