All Posts

Leetcode 1302: Deepest Leaves Sum

Given the root of a binary tree, return the sum of values of its deepest leaves. The deepest leaves are the nodes found at the lowest level of the tree.

Leetcode 1305: All Elements in Two Binary Search Trees

Given two binary search trees, root1 and root2, return a list containing all the integers from both trees, sorted in ascending order.

Leetcode 1315: Sum of Nodes with Even-Valued Grandparent

Given the root of a binary tree, return the sum of the values of the nodes that have an even-valued grandparent. If there are no nodes with an even-valued grandparent, return 0. A grandparent is defined as the parent of a node’s parent, if it exists.

Leetcode 1325: Delete Leaves With a Given Value

You are given the root of a binary tree and an integer target. Your task is to remove all leaf nodes that have the value equal to the target. Once you remove a leaf node with the target value, if its parent node becomes a leaf node and has the same value, it should also be removed. This process should continue until no more leaf nodes with the target value are present.

Leetcode 1339: Maximum Product of Splitted Binary Tree

Given the root of a binary tree, you need to split the tree into two subtrees by removing one edge. The goal is to maximize the product of the sums of these two subtrees. Return the maximum product of the sums of the two subtrees, modulo 10^9 + 7.

Leetcode 1361: Validate Binary Tree Nodes

You are given n nodes in a binary tree, numbered from 0 to n-1. Each node i has two children: leftChild[i] and rightChild[i]. If a node has no left child, its value will be -1. Similarly, if a node has no right child, its value will also be -1. Your task is to return true if and only if these nodes form exactly one valid binary tree.