All Posts

Leetcode 1519: Number of Nodes in the Sub-Tree With the Same Label

You are given a tree with n nodes, where each node has a label, and your task is to find the number of nodes in the subtree rooted at each node that have the same label as that node.

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 1559: Detect Cycles in 2D Grid

Given a 2D grid of characters, find if there exists a cycle where the same character repeats in the grid. A cycle is defined as a path where a character appears 4 or more times, forming a loop that starts and ends at the same cell. The cycle must consist of adjacent cells, and you are not allowed to revisit the previous cell.

Leetcode 1600: Throne Inheritance

In a kingdom, there is a well-defined hierarchy of inheritance, starting with the king. The inheritance order depends on the family’s birth and death events. Implement a class to keep track of the order, excluding the dead members.

Leetcode 1625: Lexicographically Smallest String After Applying Operations

Given a string s of even length consisting of digits from 0 to 9, and two integers a and b, return the lexicographically smallest string that can be obtained by applying two operations any number of times: adding a to all odd indices of s (with wrapping) and rotating s to the right by b positions.

Leetcode 1631: Path With Minimum Effort

You are a hiker navigating a terrain represented by a 2D grid of heights. Your goal is to find the path from the top-left corner to the bottom-right corner that minimizes the maximum height difference between any two consecutive cells.