Design an account credit tracker. Accounts receive unique integer IDs starting from 0 in creation order.
Implement the AccountCreditTracker class:
AccountCreditTracker()initializes an empty tracker.int addAccount(double credit)creates an account with the given initial credit and returns its assigned ID.int addAccountWithReferral(double credit, int referrerId)creates an account with the given initial credit, adds the same credit amount to its direct referrer's total credit, and returns the new account's assigned ID.referrerIdis guaranteed to identify an account created earlier.
List<Integer> getLowestK(int k, double minTotalCredit)returns up tokaccount IDs whose total credit is at leastminTotalCredit.- Order qualifying accounts by increasing total credit. If two accounts have the same credit, order by increasing account ID.
- If fewer than
kaccounts qualify, return all of them.
Referral credit is applied only to the direct referrer and does not propagate further up the referral chain.
Constraints:
creditandminTotalCreditare non-negative.- 1 ≤
k≤ 105. - At most 105 total method calls will be made.
Example:
Input: ["AccountCreditTracker", "addAccount", "addAccountWithReferral", "addAccountWithReferral", "getLowestK", "getLowestK"] [[], [10], [30, 0], [50, 1], [1, 45], [2, 45]]
Output: [null, 0, 1, 2, [2], [2, 1]]
Explanation:
tracker = new AccountCreditTracker();tracker.addAccount(10);// Returns 0. Account 0 starts with total credit 10.tracker.addAccountWithReferral(30, 0);// Returns 1. Account 1 starts at 30, and account 0 increases to 40.tracker.addAccountWithReferral(50, 1);// Returns 2. Account 2 starts at 50, and account 1 increases to 80.tracker.getLowestK(1, 45);// Returns [2]. Account 2 has the lowest qualifying total credit.tracker.getLowestK(2, 45);// Returns [2, 1]. The qualifying totals are 50 for account 2 and 80 for account 1.
Accepted
523/1.8k
Acceptance Rate29.5%
Ask AI Assistant

Ask AI Assistant
Ask me anything about this coding question!
Test Cases
Input
Output
Expected