Company: Uber_SDE-2__
Difficulty: medium
A disk stores hierarchical data in an undirected tree with tree_nodes nodes numbered from 0 to tree_nodes - 1 , rooted at node 0. Each node has a character value represented by an array named arr , where arr[i] is the character on the ith node. You are given an array queries of length m . For each query queries[i] , determine how many nodes v (including queries[i] ) exist on the path from queries[i] to the root, such that the letters on the nodes from queries[i] to v can be arranged to form a palindrome. Return an integer array of size m with the answer to each query. Note: A palindrome is a string that reads the same backward as forward. Examples of palindromes include "z", "aaa", "aba", and "abccba". Example tree_nodes = 4 arr = ['z', 'a', 'a', 'a'] tree_from = [0, 0, 1] tree_to = [1, 2, 3] m = 1 queries = [3] Consider: v = 3 : We can form the palindrome "a" v = 1 : We can form the palindrome "aa" v = 0 : We can form the palindrome "aza" Hence the answer is [3] . Function Description