All Posts

Leetcode 565: Array Nesting

You are given an array nums, a permutation of numbers from [0, n-1], and for each index k, you need to build a set s[k] by repeatedly selecting elements based on the rule nums[k] -> nums[nums[k]] -> nums[nums[nums[k]]], stopping when a duplicate is found. Return the longest length of any such set s[k].

Leetcode 572: Subtree of Another Tree

Given the roots of two binary trees, root and subRoot, return true if there is a subtree of root with the same structure and node values of subRoot and false otherwise. A subtree of a binary tree consists of a node in the tree and all of this node’s descendants.

Leetcode 589: N-ary Tree Preorder Traversal

Given the root of an n-ary tree, return the preorder traversal of its nodes’ values. In one step, the node is visited first, followed by its children from left to right. The input is serialized in a level order format where each group of children is separated by a null value.

Leetcode 606: Construct String from Binary Tree

Given the root node of a binary tree, generate a string representation of the tree following specific formatting rules based on a preorder traversal.

Leetcode 617: Merge Two Binary Trees

Given two binary trees, merge them into a new binary tree where overlapping nodes are summed, and non-overlapping nodes are retained as they are.

Leetcode 623: Add One Row to Tree

You are given the root of a binary tree, and two integers val and depth. You need to add a row of nodes with value val at the given depth depth. The root node is considered to be at depth 1.