A game's lobby shows the score you need to reach the top k: the k-th highest score so far, counting equal scores separately. New scores keep arriving.
Write a class LeaderboardCutoff with:
constructor(k, scores): scores holds the scores so far.add(score): records a new score and returns the current k-th highest score. There will always be at least k scores after each add.Each example lists the calls in order, then each call's arguments. The first call creates the object with new LeaderboardCutoff(…); the output lists what each call returns (null for the constructor and for methods that return nothing).
Input: ["LeaderboardCutoff","add","add","add"] [[3,[40,50,20,80]],[30],[90],[60]] Output: [null,40,50,60]
Top 3 after adding 30: 80, 50, 40. After 90: 90, 80, 50. After 60: 90, 80, 60.
Input: ["LeaderboardCutoff","add","add"] [[1,[]],[5],[3]] Output: [null,5,5]
With k = 1, the cutoff is the best score so far.
1 <= k <= 10^40 <= scores.length <= 10^410^4 calls to add.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 #382 Live Leaderboard Cutoff. 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.