Algorithm · Google · Medium
Problem: Check a Tree Represented by Parent Indices You receive an array named parent with n entries, where parent[i] specifies the index of node i's parent. A value of -1 in parent[i] marks node i as the root. Nodes are numbered from 0 through n - 1. Decide whether the given parent links describe a valid rooted tree. Print true or false. For the structure to be a valid rooted tree, all of the following must hold: One and only one node is a root, meaning there is exactly one…
Checking your access…