Loading problem...
In a corporate organization, there are n employees labeled from 0 to n - 1. Each employee possesses a unique wealth level and a distinct noise level (how disruptive they are in the office).
You are provided with:
Important: All wealth relationships are logically consistent—there are no circular wealth dependencies (i.e., if A is wealthier than B, then B cannot be wealthier than A directly or transitively).
For each employee x, you need to determine which person y has the minimum noise level among all people who are definitely at least as wealthy as employee x. This includes employee x themselves and anyone who is wealthier than x either directly or through a chain of wealthier relationships.
Return an integer array answer where answer[x] = y indicates that employee y is the quietest (lowest noise level) among all employees who are certainly as wealthy or wealthier than employee x.
wealthier = [[1,0],[2,1],[3,1],[3,7],[4,3],[5,3],[6,3]]
noiseLevels = [3,2,5,4,6,1,7,0][5,5,2,5,4,5,6,7]For employee 0: Employees wealthier than 0 include 1 (directly), and then 2, 3, 4, 5, 6 (transitively through 1 and 3). Employee 5 has the lowest noise level (1) among all these, so answer[0] = 5.
For employee 7: Employees definitely wealthier than 7 include 3, and then 4, 5, 6 (through 3). However, employee 7 has noise level 0 which is the minimum, so answer[7] = 7.
The remaining answers follow similar logic by tracing wealth relationships.
wealthier = []
noiseLevels = [0][0]With only one employee and no wealth comparisons, employee 0 is the only person at least as wealthy as themselves. Thus, answer[0] = 0.
wealthier = [[0,1],[1,2],[2,3]]
noiseLevels = [2,0,3,1][0,1,1,1]This forms a linear chain: 0 is wealthier than 1, 1 is wealthier than 2, and 2 is wealthier than 3.
For employee 0: Only employee 0 is at least as wealthy as themselves. answer[0] = 0. For employee 1: Employees 0 and 1 are at least as wealthy. Employee 1 has noise level 0 (minimum). answer[1] = 1. For employee 2: Employees 0, 1, 2 are at least as wealthy. Employee 1 has noise level 0 (minimum). answer[2] = 1. For employee 3: All employees are at least as wealthy. Employee 1 has noise level 0 (minimum). answer[3] = 1.
Constraints