Longest Path With Different Adjacent Characters
Given a tree represented by parent array and a string s where s[i] is the character assigned to node i, return the length of the longest path where adjacent nodes have different characters.
Longest Path With Different Adjacent Characters

Given a tree represented by parent array and a string s where s[i] is the character assigned to node i, return the length of the longest path where adjacent nodes have different characters.

Example 1:
Input: {"parent":[-1,0,0,1,1,2],"s":"abacbe"}
Output: 3
Input
arr ={"parent":[-1,0,0,1,1,2],"s":"abacbe"}

Tree with 6 nodes, s="abacbe"

Tree with Character Labels

a0b1a2c3b4e5

Longest Path:

1

Current Node

In Path

Variables
No variables to display
DepthFunction Call
Stack empty
0/1