Longest Path With Different Adjacent Characters
Try to solve the Longest Path With Different Adjacent Characters problem.
We'll cover the following
Statement
You are given a rooted tree with parent
of size parent[i]
is the parent of node parent[0]
Additionally, you are provided a string s
of length s[i]
represents the character assigned to node
Your task is to find the length of the longest path in the tree where no two consecutive nodes on the path share the same character. Return the length of this path.
Constraints:
parent.length
s.length
parent[i]
 for all parent[0]
parent
 represents a valid tree.s
 consists of only lowercase English letters.
Examples
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.