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.

Following all of the constraints of the problem statement, I was able to get all of the test cases to pass with this solution that avoids using the max() built in function and from modifying the original arr map list.

Jason, I did something similar to yours but took the sorted function and used it to avoid the same pitfall I found tried doing your method (Having a pre defined veeeery low number. Have you thought about using - inf ?)

Very nice. I like your way more of sorting it first. I would do largest = arrSorted[0] and second_largest = arrSorted[1]. I will use for future scenarios, thanks.

## Find the Runner-Up Score!

You are viewing a single comment's thread. Return to all comments →

Following all of the constraints of the problem statement, I was able to get all of the test cases to pass with this solution that avoids using the max() built in function and from modifying the original arr map list.

Jason, I did something similar to yours but took the sorted function and used it to avoid the same pitfall I found tried doing your method (Having a pre defined veeeery low number. Have you thought about using - inf ?)

Very nice. I like your way more of sorting it first. I would do largest = arrSorted[0] and second_largest = arrSorted[1]. I will use for future scenarios, thanks.

Sorting it first, although elegant, will increase the time complexity. Your original solution is more efficient, don't you think?

if i > largest: second_largest = largest largest = i

Can you explain this part?