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.

That's exactly what I did. Of course, I'm a C programmer with just a basic understanding of Python, so I simply coded it like I would in C, not knowing how to use set and sort, etc. (Until I read the other comments).

## 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?

That's exactly what I did. Of course, I'm a C programmer with just a basic understanding of Python, so I simply coded it like I would in C, not knowing how to use set and sort, etc. (Until I read the other comments).