Reported December 2025
Anchorageheap priority queue

Dynamic Fixed-K Score Leaderboard

Reported by candidates from Anchorage's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Anchorage OA. Under 2s to a working solution.
Founder's read

The Anchorage OA reported in December 2025 is a leaderboard problem, and the whole thing hinges on one data structure choice. You get add, remove and query operations, and every query wants the kth-highest score with ties counted per user. If you reach for sorting on each query, you'll time out at 100000 operations. The clean answer is a hash map plus an ordered structure or two heaps with lazy deletion. If you blank on the structure mid-assessment, StealthCoder runs invisibly on your screen as a safety net and hands you a working solution in real time.

The problem

Build a leaderboard with a fixed positive rank k. You are given equal-length arrays operations, userIds, and scores. Process each index in order:
"add" inserts the user with the supplied score, or replaces that user's previous score.
"remove" deletes the user if present; removing an absent user is a no-op.
"query" asks for the current kth-highest score, counting every user separately even when scores tie.
For query, ignore the corresponding user ID and score. Return one string for each query, in order: the decimal kth-highest score, or "null" when fewer than k users are present.

Function
processLeaderboard(k: int, operations: String[], userIds: String[], scores: int[]) → String[]

Examples
Example 1
k = 2
operations = ["add","query","add","query","add","query","remove","query"]
userIds = ["u1","","u2","","u1","","u2",""]
scores = [10,0,5,0,3,0,0,0]
return = ["null","5","3","null"]
One user is insufficient for the first query. After adding u2, the second-highest score is 5. Updating u1 to 3 changes it to 3, and removing u2 leaves too few users.
Example 2
k = 2
operations = ["add","add","query","remove","query"]
userIds = ["a","b","","a",""]
scores = [7,7,0,0,0]
return = ["7","null"]
Equal scores belong to two separate users, so the second-highest score is still 7. After one user is removed, only one remains.
Example 3
k = 1
operations = ["remove","query","add","query"]
userIds = ["ghost","","n",""]
scores = [0,0,-4,0]
return = ["null","-4"]
The absent removal changes nothing. Negative scores are valid leaderboard values.

Constraints
1 <= k <= 100000.
operations.length == userIds.length == scores.length.
0 <= operations.length <= 100000.
Every operation is exactly "add", "remove", or "query".
An add or remove user ID is non-empty and contains at most 50 Unicode characters.
-1000000000 <= scores[i] <= 1000000000 for add operations.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Keep a hash map from userId to current score so add-as-update and remove are O(1) lookups. Then you need the kth-highest fast. Option one: a balanced ordered multiset of scores, though most languages lack one built in. Option two, simpler: a min-heap of size k holding the top k, plus a max-heap of the rest, both with lazy deletion checked against the map. The common pitfall is treating equal scores as one entry, so Example 2 returns 7 with two users. Another trap is forgetting that an update must remove the old score first. Removing an absent user is a no-op, and negative scores are valid, so don't use 0 as a sentinel. Return strings, including the literal "null". If the heap bookkeeping gets tangled live, StealthCoder is the hedge that gets you unstuck without the proctor seeing anything.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Dynamic Fixed-K Score Leaderboard cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder
⏵ The honest play

You've seen the question. Make sure you actually pass Anchorage's OA.

Anchorage reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Dynamic Fixed-K Score Leaderboard FAQ

What's the trick in the Anchorage leaderboard problem?+

Pair a hash map of userId to score with a structure that gives the kth-highest quickly. A Fenwick tree over compressed scores, an ordered multiset, or two heaps with lazy deletion all work. Sorting on every query is the mistake that fails the large cases.

How hard is this OA really?+

Medium. The logic is simple, but the data structure choice decides whether you pass. Most of the difficulty is handling updates and removals correctly while keeping queries fast, plus the edge cases like absent removals and fewer than k users.

How do ties work for the kth-highest score?+

Each user counts separately. If two users both have 7 and k is 2, the answer is 7. Don't dedupe scores. Store every user's score as its own entry so duplicates occupy distinct ranks.

What edge cases should I test before submitting?+

Removing a user who doesn't exist, querying with fewer than k users, updating an existing user's score, negative scores, and an empty operations array. Also confirm you return the string "null" and not a null value, and that numbers come back as decimal strings.

How do I prepare for this in 48 hours?+

Write the heap-with-lazy-deletion pattern once from scratch, and practice a score-compression Fenwick tree as a backup. Know how to update a user by invalidating the old entry. Then run the three provided examples by hand against your code to confirm it matches.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Anchorage.

OA at Anchorage?
Invisible during screen share
Get it