Panda Guru LogoPanda
Guru

Nutanix | OA | MTS2 | Competitive Gaming

Round 1

Questions:

  1. Question 1: Work Schedule
    Link to Question

  2. Question 2
    A group of friends are playing a video game together. During the game, each player earns a number of points. At the end of a round, players who achieve at least a certain rank k get to "level up" their characters to gain increased abilities. Given the scores of the players at the end of a round, how many players will be able to level up?

    Note: Players with equal scores will have equal ranks, but the player with the next lower score will be ranked based on the position within the list of all players' scores. For example, if there are four players, and three of them tie for first place, their ranks are 1, 1, 1, and 4.

    Note: No player with a score of 0 can level up, regardless of rank.

    Example:
    n = 4
    k = 3
    scores = [100, 50, 50, 25]

    These players' ranks are [1, 2, 2, 4]. Because the players need to have a rank of at least k = 3 to level up, only the first three players qualify. Therefore, the answer is 3.

    Function Description
    Complete the function numPlayers in the editor below.

    numPlayers has the following parameters:

    • int k: the cutoff rank to level up a player's character
    • int scores[n]: the players' scores

    Returns:
    int: the number of players who can level up after this round

    Constraints

    • 1 ≤ n ≤ 10^5
    • 0 ≤ scores[i] ≤ 100
    • kn

    Sample Case 0
    Sample Input

    STDIN Function ----- ----- 4 → k = 4 5 → scores[] size n = 5 20 → scores = [20, 40, 60, 80, 100] 40 60 80 100

    Sample Output

    4
    

    Explanation
    The players achieve the ranks [5, 4, 3, 2, 1] in order. Since the cutoff, k, is rank >= 4, there are 4 players who can level up.

    Sample Case 1
    Sample Input

    STDIN Function ----- ----- 4 → k = 4 5 → scores[] size n = 5 2 → scores = [2, 2, 3, 4, 5] 2 3 4 5

    Sample Output

    5
    

    Explanation
    The players achieve the ranks [4, 4, 3, 2, 1] in order. Since the cutoff rank is 4, all 5 players can level up.

    Working Solution

    public static int countLevelUpPlayers(int n, int k, int[] scores) { // Check for invalid input if (n <= 0 || k <= 0 || scores == null || scores.length == 0) { return 0; } // Create a list of scores and sort it in descending order Integer[] sortedScores = Arrays.stream(scores).boxed().toArray(Integer[]::new); Arrays.sort(sortedScores, Collections.reverseOrder()); // Determine the rank of each player int rank = 1; int currentRank = 1; int lastScore = sortedScores[0]; Map<Integer, Integer> rankMap = new HashMap<>(); for (int score : sortedScores) { if (score != lastScore) { rank = currentRank; lastScore = score; } rankMap.put(score, rank); currentRank++; } // Count how many players can level up int levelUpCount = 0; for (int score : scores) { if (score > 0 && rankMap.get(score) <= k) { levelUpCount++; } } return levelUpCount; }
Candidate's Approach

No approach provided.

Interviewer's Feedback

No feedback provided.