Loud and Rich

Try to solve the Loud and Rich problem.

Statement

You’re given a group of people where everyone has a specific amount of money and a different level of quietness. Additionally, you’re given an array richer = [xix_{i}, yiy_{i}], so that xix_{i} has more money than yiy_{i}. The quietness level of each person is represented using an array named quiet.

Return an integer array res, where res[i] = y if y has the lowest value in quiet[y] among all people who have equal or more money than the person i.

Constraints:

  • n=n = quiet.length
  • 11 \leq nn 500\leq 500
  • 00 \leq quiet[i] << nn
  • All the values of quiet are unique.
  • 00 \leq richer.length n(n1)/2\leq n * (n - 1) / 2
  • 00 \leq x[i], y[i] << n
  • xix_{i} !=!= yiy_{i}
  • All the pairs of richer are unique.
  • The observations in richer are all logically consistent.

Example

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.