A game's leaderboard gives bonus points to ranges of players: "everyone ranked 3 to 9 gets 50 points". Players often check their own bonus total. Write a class BonusBoard:
new BonusBoard(n) creates players 0 to n - 1 with 0 bonus.bonus(left, right, amount) adds amount to every player from left to right, inclusive.score(index) returns player index's bonus total.Both methods should be O(log n).
Each example lists the calls in order, then each call's arguments. The first call creates the object with new BonusBoard(…); the output lists what each call returns (null for the constructor and for methods that return nothing).
Input: ["BonusBoard","bonus","bonus","score","score","score"] [[6],[1,3,10],[2,5,5],[0],[2],[5]] Output: [null,null,null,0,15,5]
Player 0 got nothing, player 2 got both bonuses (10 + 5), and player 5 got only the second.
Input: ["BonusBoard","score"] [[1],[0]] Output: [null,0]
No bonus yet.
1 <= n <= 10^50 <= left <= right < n-1000 <= amount <= 100010^5 calls.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #688 Range Bonus, Point Lookup. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.