Find the Runner-Up Score!

  • + 1 comment

    The problem to be solved here is to find the second highest score in the given list of scores.

    I have first converted the input array of scores to a set in order to get the unique values present in the input array. Next, I use the max() function to determine the highest value present in this set.

    The range for scores is defined in the problem as -100 <= A[i] <= 100. So, the initial value for runner up score has been set to -101.

    Next I go iterate through all the scores in the input array and check if the individual is equal to the maximum score value I found above. If it's equal, the value of runner_up_score does not change. In case it is not, then I calculate the maximum of the values: runner_up_score and the score value in the array iteration.

    Basically, I am finding the next highest value in the array after excluding the first highest value.

    Hope this helps!