All Posts

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 2101: Detonate the Maximum Bombs

You are given a list of bombs represented by a 2D array ‘bombs’ where each bomb is described by three integers: [xi, yi, ri]. xi and yi denote the X and Y coordinates of the bomb, while ri is its blast radius. Your task is to find the maximum number of bombs that can be detonated by initiating a detonation of one bomb.

Leetcode 2192: All Ancestors of a Node in a Directed Acyclic Graph

You are given a directed acyclic graph (DAG) with n nodes, numbered from 0 to n-1. Along with this, you are given a list of directed edges where each edge [fromi, toi] indicates a directed edge from node fromi to node toi. For each node in the graph, you need to determine the list of all its ancestors. A node u is an ancestor of node v if there is a path from u to v through one or more directed edges. Return a list answer where answer[i] contains the sorted list of ancestors of the i-th node.

Leetcode 2265: Count Nodes Equal to Average of Subtree

You are given the root of a binary tree. Your task is to return the number of nodes where the value of the node is equal to the average of the values in its entire subtree (including the node itself). The average of a set of values is the sum of the values divided by the number of values, rounded down to the nearest integer.

Leetcode 2316: Count Unreachable Pairs of Nodes in an Undirected Graph

You are given an undirected graph with n nodes and a list of edges connecting the nodes. The goal is to find the number of pairs of distinct nodes that are unreachable from each other.