Longest Path With Different Adjacent Characters
Problem Overview
- Find the length of the longest path in a rooted tree where adjacent nodes have different characters.
- Inputs: 0-indexed parent array and string s of length n; output: the maximum path length.
- Constraints: n == parent.length == s.length, 1 <= n <= 1e5, valid tree with parent[0] = -1, lowercase letters.
- Domain: graph/tree path evaluation with character labels.
- From Microsoft interviews; a coding interview problem and common interview question on trees and strings.
Example
Unlock to view complete problem details
and practice with sample input/output
Was this article helpful?
View Test Cases & Run Code requires membership
Input Variables
Execution Result:
