An arcade game shows a leaderboard with dense ranking: players with equal scores share a rank, and the next lower score gets the next rank with no gaps. Scores 100, 100, 50, 40 have ranks 1, 1, 2, 3.
A new player plays several games. After each game, the screen shows where that game's score would place on the current leaderboard. The player's own games are not added to the board.
Write denseRanks(leaderboard, attempts):
leaderboard is an array of safe integers sorted from highest to lowest; it may contain duplicates.
attempts is an array of safe integers in any order.
Return an array with, for each attempt, its dense rank: 1 + the number of distinct leaderboard scores strictly greater than it.
Rules:
A score equal to an existing score shares its rank.
If either argument is not an array of safe integers, throw a TypeError. If leaderboard is not sorted from highest to lowest, throw a RangeError.
An empty leaderboard gives rank 1 for every attempt; no attempts give [].
Both arrays can hold 200,000 scores. Scanning the board for each attempt will not finish in time.