Referral Credit Tracker

Asked at DatabricksOnsite

Reported by the problem's creator, not verified

Each test creates one ReferralTracker and then runs a sequence of calls, checking every return value. Accounts get integer ids in the order they are added: the first account is 0, the next is 1, and so on.

Examples

  1. Example 1

    Input: init = [false], operations = [["add",[10,-1]],["add",[5,0]],["add",[7,1]],["query",[2,10]],["query",[10,0]],["query",[3,100]],["query",[0,0]]]

    Output: [0,1,2,[1,0],[2,1,0],[],[]]

    Explanation: In direct mode each credit goes only to the account that referred the new one. Totals: account 0 has 10 + 5 = 15, account 1 has 5 + 7 = 12, account 2 has 7. Sorted by total the order is 2, 1, 0, so query(2, 10) keeps 1 and 0; a threshold of 0 keeps all three, a threshold of 100 keeps none, and k = 0 returns an empty list.

  2. Example 2

    Input: init = [true], operations = [["add",[10,-1]],["add",[5,0]],["add",[7,1]],["query",[2,20]],["query",[3,10]]]

    Output: [0,1,2,[0],[1,0]]

    Explanation: In indirect mode account 2's credit of 7 goes to its referrer 1 and to 1's referrer 0. Totals: account 0 has 10 + 5 + 7 = 22, account 1 has 5 + 7 = 12, account 2 has 7. Only account 0 reaches 20; a threshold of 10 keeps 1 and 0 in total order.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.