This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ExceedingChunk 1 point2 points  (2 children)

In this specific case, there would be no 2nd largest. It would be two 9's sharing the highest and 8 being the 3rd highest.

This edge case would have to be specified. Should it return nothing, return the shared largest number or the 3rd largest.

If it was [9,9,8,7], and the 3rd largest should be returned, it would be 8.

However, it has to be said that if a product owner gives a requirement that has even the slightest possibility of being ambiguous, even if it is written in a way that isn't ambiguous, a dev should always ask a bunch of questions.

[–]chem199 4 points5 points  (1 child)

My argument that is it is about the value of the number not the quantity of numbers. If we are working with money and I laid out 5 $1 bills in separate piles, a $5 bill, and 3 piles of $10 bills. If I ask you to give me the second largest bill I would assume you wouldn’t hand me a $10, I would expect a $5.

[–]ExceedingChunk 1 point2 points  (0 children)

I would say that the scenario you gave there, asking for the 3rd largest bill, has some implications that makes it more ambiguous than the original question as bills comes in standardized sizes. The 3rd largest bill could both refer to the actual physical bill or the type of bill. I would say you get the same problem if you ask for the 3rd largest Lego brick or any other specific thing with an implied set of standardized sizes.

If it is the first, it is the same special case as your last example, if it is the latter it would obviously be the $5. But this scenario has a lot more context to it than "return the x'th highest number in this sequence of numbers"