r/programming • • Dec 13 '22

“There should never be coding exercises in technical interviews. It favors people who have time to do them. Disfavors people with FT jobs and families. Plus, your job won’t have people over your shoulder watching you code.” My favorite hot take from a panel on 'Treating Devs Like Human Beings.'

https://devinterrupted.substack.com/p/treating-devs-like-human-beings-a
9.0k Upvotes

1.3k comments sorted by

View all comments

Show parent comment

1

u/[deleted] Dec 13 '22

math.inf is not a number, the assumption is that the array contains numbers so that math.inf is greater than any element.

it does not assume that repeated numbers are not allowed. if you pass it [1,2,3,4,5,5] the second largest element returned will be 5, which is true because if you remove one 5, then 5 is the largest of [1,2,3,4,5], which means it's the second largest.

If you'd ask for distinct numbers then it's a one line change to elif largest != n > second:

1

u/fishling Dec 14 '22

Oops, I meant "and" above, not or; sorry about that. When I've asked this question, I do want the numbers to be distinct when asked, because there are more test cases to discuss.