Scaler OA | Times Internet | SDE

Got this question in Scaler OA for times Internet

Question:

Tree with N nodes (1 to N)
Bi-directional traversal possible

Every node has a color =>
int[] A denotes the color of each node
A -> zero indexed

Q queries
Int[][] C denotes the queries
C[i][0] => start node for traversal
C[i][1] => end node for traversal

Node Connections:
Int[][] B
B[i][0] connected with B[i][1]

Requirement:
Return the minOccuring (non-zero) color for each simple path represented by each query Q.
*if there are multiple colors of same min. Frequence then return the smallest color.

Return:
array of size Q, where each index of array represents the minColor for the respective color

TC Constraints:
Q <= 10^5
A <= 10^3
B <= 10^3

Example
A : [2, 2, 11]
B: [
[1, 2]
[2, 3]
]
C: [[1, 3], [2, 3]]

ans: [11, 2]

Comments (0)