FastPrepFastPrep
Problem Brief

Racing Results

FULLTIMEINTERNOA

Unfortunately, the database containing all this year's racing results has crashed. The only thing left is a backup of database records and results for each race. We urgently need to know who is the winner!

Your program will receive input as a list of elements in the form of [race, racer_name, position], where all elements are integers:

  • race is a database record number between 2001 and 2000+N where N is the total number of races in the championship.
  • racer_name is a database record number between 1001 and 1000+R where R is the total number of racers participating.
  • position is a value between 1 (won the race) and R (arrived last).
  • Points are given according to the racers' position in a race: the 1st position is worth 10 points, 2nd is worth 6 points, 3rd is 4 points, 4th is 3 points, 5th is 2 points and 6th is worth 1 point. Positions further down earn no points.

    In case of an equal number of points at the end of the championship, the winner is the racer with the lowest record number. There are at most 100 racers, and at most 100 races in the championship.

    Your program is expected to output the record number of the winner, followed by how many points he or she got.

    Function Description

    Complete the function findWinner in the editor.

    findWinner has the following parameter:

    1. int[][] results: a 2D array of integers where each element is an array of the form [race, racer_name, position]

    Returns

    int[]: an array of two integers where the first element is the record number of the winner and the second element is the number of points they got

    1Example 1

    Input
    results = [[2001, 1001, 3], [2001, 1002, 2], [2002, 1003, 1], [2002, 1001, 2], [2002, 1002, 3], [2001, 1003, 1]]
    Output
    [1003, 20]
    Explanation

    The two races are coded 2001 and 2002. The racers with records 1001, 1002 and 1003 competed. Based on the raw results, they have the following points:

    • Racer 1001: 4+6=10 (3rd and 2nd positions)
    • Racer 1002: 6+4=10 (2nd and 3rd positions)
    • Racer 1003: 10+10=20 (1st in both races)

    Your program is expected to output the following line in that case:

    1003 20

    public int[] findWinner(int[][] results) {
      // write your code here
    }
    
    Input

    results

    [[2001, 1001, 3], [2001, 1002, 2], [2002, 1003, 1], [2002, 1001, 2], [2002, 1002, 3], [2001, 1003, 1]]

    Output

    [1003, 20]

    Sign in to submit your solution.