← 返回 uber 的题目列表Customer Revenue and Referral Tracking: Get Lowest K by Total Revenue Threshold
类型:online_judge
Problem: Customer Revenue and Referral Tracking (Lowest K above a threshold)
Design a data structure to manage customers and their revenue, with an optional referrer relationship.
Implement the following APIs:
int insertNewCustomer(double revenue)
Insert a new customer with initial spending revenue.
Return a unique customerId.
int insertNewCustomer(double revenue, int referrerId)
Insert a new customer with initial spending revenue and a given referrerId.
Return a unique customerId.
Set<Integer> getLowestK(int k, double minTotalRevenue)
Return up to k customer IDs whose total revenue contribution satisfies:
totalRevenue >= minTotalRevenue
among all customers meeting the threshold, they have the smallest totalRevenue (take the first k in ascending order)
Return type is a Set<Integer>.
Note: The interview notes do not specify what exactly totalRevenue means or whether referrals change revenue accumulation (e.g., referral commission along the chain). Clarify with the interviewer.
Example
insertNewCustomer(10) -> 0
insertNewCustomer(30, 0) -> 1
insertNewCustomer(50, 1) -> 2
getLowestK(1, 45) -> {2}
getLowestK(2, 45) -> {1, 2}
Example
Input
insertNewCustomer(10)
insertNewCustomer(30,0)
insertNewCustomer(50,1)
getLowestK(1,45)
Output
{2}