All Posts

Leetcode 1042: Flower Planting With No Adjacent

You are given n gardens labeled from 1 to n, and an array paths where paths[i] = [xi, yi] describes a bidirectional path between garden xi and garden yi. Each garden needs to be assigned one of 4 types of flowers. You need to ensure that for any two gardens connected by a path, they have different types of flowers. Your task is to return any valid flower assignment for all gardens such that no two adjacent gardens share the same flower type.

Leetcode 1080: Insufficient Nodes in Root to Leaf Paths

You are given the root of a binary tree and an integer limit. Your task is to delete all nodes in the tree that are considered insufficient. A node is insufficient if every root-to-leaf path passing through that node has a sum strictly less than the given limit. A leaf is defined as a node with no children. Return the root of the resulting binary tree after the deletions.

Leetcode 1110: Delete Nodes And Return Forest

Given the root of a binary tree, and a list of values to delete, your task is to remove the nodes with the given values. The resulting tree will become a forest, where each tree is a disjoint set of nodes. Return the roots of the trees in the remaining forest.

Leetcode 1123: Lowest Common Ancestor of Deepest Leaves

Given the root of a binary tree, your task is to return the lowest common ancestor (LCA) of its deepest leaf nodes. The LCA of a set of nodes is the deepest node that is an ancestor of all the nodes in the set. A leaf node is one that does not have any children.

Leetcode 1145: Binary Tree Coloring Game

Two players play a turn-based game on a binary tree. We are given the root of the tree and the number of nodes, n, where n is odd, and each node has a distinct value from 1 to n. Player 1 selects a value x and colors the corresponding node red, while Player 2 selects a value y (where yx) and colors the corresponding node blue. Players take turns coloring neighboring nodes. The game ends when both players pass their turns, and the winner is the player who colored more nodes. Your task is to determine if Player 2 can guarantee a win by choosing a value y.

Leetcode 1161: Maximum Level Sum of a Binary Tree

Given the root of a binary tree, find the smallest level x (1-indexed) such that the sum of the values of nodes at level x is maximal. Each level of the tree corresponds to the distance from the root, with the root being level 1.