Back to problems

Count Paths Matching Every Prefix in a Labeled Tree

Algorithm · Google · Hard

Tree Prefix Path Matching Hard · Topics · Company Tags · Hints You are given a tree with n nodes numbered from 0 to n-1. Every node i carries a single lowercase English letter given by label[i]. You are also provided a target string s. Consider all directed simple paths in the tree. A directed simple path visits a sequence of distinct vertices, traversing edges in order. The string formed by concatenating the node labels along the path is called the path's label sequence.…

Checking your access…