2764. is Array a Preorder of Some Binary Tree
Given a 0-indexed integer 2D array
nodes, your task is to determine if the given array represents the preorder traversal of some binary tree.For each index
i,nodes[i] = [id, parentId], whereidis the id of the node at the indexiandparentIdis the id of its parent in the tree (if the node has no parent, thenparentId = -1).Return
trueif the given array represents the preorder traversal of some tree, andfalseotherwise.Note: the preorder traversal of a tree is a recursive way to traverse a tree in which we first visit the current node, then we do the preorder traversal for the left child, and finally, we do it for the right child.
2773. Height of Special Binary Tree
You are given a
root``nnodes. The nodes of the special binary tree are numbered from1ton. Suppose the tree haskleaves in the following order:b1 < b2 < ... < bk.
bi, the following conditions hold:
- The right child of
biisbi + 1ifi < k, andb1otherwise.- The left child of
biisbi - 1ifi > 1, andbkotherwise.Return the height of the given tree.
Note: The height of a binary tree is the length of the longest path from the root to any other node.
2792. Count Nodes That Are Great Enough
You are given a
rootto a binary tree and an integerk. A node of this tree is called great enough if the followings hold:
- Its subtree has at least
knodes.- Its value is greater than the value of at least
knodes in its subtree.Return the number of nodes in this tree that are great enough.
The node
uis in the subtree of the nodev, ifu == vorvis an ancestor ofu.
2782. Number of Unique Categories
You are given an integer
nand an objectcategoryHandlerof classCategoryHandler.There are
nelements, numbered from0ton - 1. Each element has a category, and your task is to find the number of unique categories.The class
CategoryHandlercontains the following function, which may help you:
boolean haveSameCategory(integer a, integer b): Returnstrueifaandbare in the same category andfalseotherwise. Also, if eitheraorbis not a valid number (i.e. it’s greater than or equal tonor less than0), it returnsfalse.Return the number of unique categories.
2814. Minimum Time Takes to Reach Destination Without Drowning
You are given an
n * m0-indexed grid of stringland. Right now, you are standing at the cell that contains"S", and you want to get to the cell containing"D". There are three other types of cells in this land:
".": These cells are empty."X": These cells are stone."*": These cells are flooded.At each second, you can move to a cell that shares a side with your current cell (if it exists). Also, at each second, every empty cell that shares a side with a flooded cell becomes flooded as well.
There are two problems ahead of your journey:
- You can’t step on stone cells.
- You can’t step on flooded cells since you will drown (also, you can’t step on a cell that will be flooded at the same time as you step on it).
Return the minimum time it takes you to reach the destination in seconds, or
-1if it is impossible.Note that the destination will never be flooded.