We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
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!
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Find the Runner-Up Score!
You are viewing a single comment's thread. Return to all comments →
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!