All Posts

Leetcode 841: Keys and Rooms

You are in a building with multiple rooms, each containing a set of keys to unlock other rooms. Initially, only the first room (room 0) is unlocked. You are tasked with determining whether you can visit all the rooms, starting from room 0. To enter a locked room, you must have its corresponding key, which can only be obtained by visiting other rooms.

Leetcode 851: Loud and Rich

You are given a group of n people, each with a unique amount of money and quietness. An array richer specifies the relationships between people where richer[i] = [ai, bi] indicates that person ai has more money than person bi. You are also given an array quiet where quiet[i] represents the quietness of person i. Your task is to return an array answer where answer[x] is the person y who has the least quietness among all people who have equal or more money than person x.

Leetcode 863: All Nodes Distance K in Binary Tree

Given a binary tree, a target node within the tree, and a non-negative integer k, determine all the nodes that are exactly k edges away from the target node. Return these node values as a list in any order.

Leetcode 865: Smallest Subtree with all the Deepest Nodes

Given the root of a binary tree, return the smallest subtree that contains all the nodes with the maximum depth in the tree. A node is considered the deepest if it has the greatest distance to the root among all nodes. The subtree of a node consists of the node itself and all its descendants.

Leetcode 872: Leaf-Similar Trees

Given two binary trees, determine if their leaf value sequences are identical. A binary tree’s leaf value sequence is the sequence of values of its leaves, from left to right, following the in-order traversal. Two trees are considered leaf-similar if the leaf values in both trees appear in the same order.

Leetcode 886: Possible Bipartition

You are given a group of n people, labeled from 1 to n. Each person may dislike other people, and they should not be placed in the same group. Your task is to determine if it is possible to split the group of people into two subgroups, such that no one in the same group dislikes each other. Each pair of dislikes is represented by an array of two people who cannot be in the same group. Return true if such a split is possible, otherwise return false.