Climbing the leaderboard

Given a leaderboard of a game with the following ranking pattern:

The player with the highest score is ranked number 1 on the leaderboard.

Players who have equal scores receive the same ranking number, and the next player(s) receive the immediately following ranking number.

You are given game scores of a player of ‘M’ rounds. Your task is to return the position obtained in each round.

Note:
The leaderboard scores are in descending order.
The game scores are given in ascending order.
Input format:
The first line of input contains an integer ‘T’ denoting the number of test cases.
The next ‘4*T’ lines represent the ‘T’ test cases.

The first line of each test case contains an integer ‘N’ denoting the number of players on the leaderboard.

The second line of each test case contains ‘N’ space-separated integers denoting the leaderboard scores in decreasing order.

The third line of each test case contains an integer ‘M’ denoting the number of rounds of the game.

The last line contains ‘M’ space-separated integers denoting the game scores, for each round, in ascending order.
Output format:
For each test case, return the ranks of the player corresponding to the game scores obtained.

Note:

You are not required to print the expected output, it has already been taken care of. Just implement the function.
Constraints:
1 <= T <= 50
1 <= N <= 10^4
1 <= M <= 10^3
0 <= LEADERBOARD_SCORE[i] <= 10^9
0 <= PLAYER_SCORE[i] <= 10^9

Time limit: 1 second
CodingNinjas
author
2y

First of all I removed the duplicates from the given leader board scores.
In each iteration say i, I kept the track of current score by taking the maximum of scores till ith attempt.
Then, I searched fo...read more

CodingNinjas
author
2y
Brute force approach

For the score of the player for each round, we will be finding the appropriate position in the leaderboard by comparing it with the scores in the leaderboard.

  1. Store the leaderboar...read more
CodingNinjas
author
2y
Using Binary Search

For the score of the player for each round, we will be finding the appropriate position in the leaderboard by comparing it with the scores in the leaderboard.

  1. Store the unique eleme...read more
CodingNinjas
author
2y
Optimised solution

For the score of the player for each round, we will be finding the appropriate position in the leaderboard by comparing it with the scores in the leaderboard.

  1. Count all the unique el...read more
Add answer anonymously...
Goldman Sachs Software Analyst Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter