Back to problems

Minimum Distance in N-ary Tree

Algorithm · Scale AI · Medium

You are given the root of an N-ary tree where every node holds a unique integer val and a list of its children. The tree is provided via its root node root. Each node has two properties: val – a distinct integer identifier for the node. children – a list of the node's immediate child nodes. You are also given two integers, a and b, which correspond to the values of two nodes in the tree. Your job is to compute the shortest distance between these two nodes. The distance is…

Checking your access…