Design a Customer Revenue Tracker with Referral Influence

Difficulty: EASYCategory: LLDFrequency: 1Asked On 2025-02-12

Problem Statement

Design and implement a system to track customers, their revenue, and referral relationships. Each customer has a unique ID and contributes revenue to the system. If a customer was referred by another, the revenue of the referring customer is increased by the revenue of the new customer.

The system must allow for adding customers and querying high-revenue customers efficiently.

🎯 Functional Requirements

Implement the following 3 methods:

1. addCustomer(String customerId, double revenue)

•Adds a new customer with the given customerId and associated revenue.
•Throws error if the customer already exists.

2. addCustomer(String customerId, double revenue, String referredBy)

•Adds a new customer with a given revenue and a reference to an existing referring customerId.
•Also increases the revenue of the referring customer by the revenue of the new customer.
•Throws error if:
•customerId already exists, or
•referredBy does not exist

3. List<String> getKCustomersWithRevenueGreaterThanValue(int k, double value)

•Returns the IDs of the first k customers (any order is fine unless otherwise stated) whose total revenue (including referral gains) is greater than value.


Solution

Comments