Propagate the Quietest Known Richer Person

Quick Overview

Propagate the Quietest Known Richer Person. People have distinct wealth and distinct quiet values. richer rows [a,b] assert that a is wealthier than b, and all assertions are logically consistent.

Propagate the Quietest Known Richer Person

Company: Flipkart

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem People have distinct wealth and distinct quiet values. richer rows [a,b] assert that a is wealthier than b, and all assertions are logically consistent. For each person x, return the label with the smallest quiet value among x and everyone provably richer through these assertions. Do not infer comparisons that are not established. ```cpp class Solution { public: vector<int> loudAndRich(vector<vector<int>>& richer, vector<int>& quiet); }; ``` ### Examples **Example 1:** ```text richer = [[0,1],[1,2]], quiet = [2,0,1] Output: [0,1,1] Explanation: Person1 is the quietest known candidate for people1 and2. ``` **Example 2:** ```text richer = [], quiet = [1,0] Output: [0,1] Explanation: With no wealth observations, each person can use only their own label. ``` ### Constraints - Person count n equals quiet.length and lies in [1,500]. - Quiet values are distinct integers in [0,n-1]. - There are 0 through n*(n-1)/2 distinct richer pairs. - Each pair contains different labels in [0,n-1], and all wealth assertions are consistent. ### Contract considerations Preserve logically consistent wealth direction and unique quiet values. ```hint Read the boundary condition Which candidate labels can a richer vertex pass to a poorer one? ``` ### Boundary reminders Preserve logically consistent wealth direction and unique quiet values.

Overview: Propagate the Quietest Known Richer Person. People have distinct wealth and distinct quiet values. richer rows [a,b] assert that a is wealthier than b, and all assertions are logically consistent.

Flipkart logo
Flipkart
Source window: 0–6 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
0
0

Problem

People have distinct wealth and distinct quiet values. richer rows [a,b] assert that a is wealthier than b, and all assertions are logically consistent. For each person x, return the label with the smallest quiet value among x and everyone provably richer through these assertions. Do not infer comparisons that are not established.

class Solution {
public:
    vector<int> loudAndRich(vector<vector<int>>& richer, vector<int>& quiet);
};

Examples

Example 1:

richer = [[0,1],[1,2]], quiet = [2,0,1]
Output: [0,1,1]
Explanation: Person1 is the quietest known candidate for people1 and2.

Example 2:

richer = [], quiet = [1,0]
Output: [0,1]
Explanation: With no wealth observations, each person can use only their own label.

Constraints

  • Person count n equals quiet.length and lies in [1,500].
  • Quiet values are distinct integers in [0,n-1].
  • There are 0 through n*(n-1)/2 distinct richer pairs.
  • Each pair contains different labels in [0,n-1], and all wealth assertions are consistent.

Contract considerations

Preserve logically consistent wealth direction and unique quiet values.

Boundary reminders

Preserve logically consistent wealth direction and unique quiet values.