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].
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.
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.
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.