Campbell Ritchie wrote:[code=java]long expectedSum = ((long)summary.getMax() + summary.getMin()) * summary.getCount() / 2;
I had forgotten that the minimum was 0. In that case the simpler technique of adding 1 to the size of the list give the maximum andBrian Tkatch wrote:. . . the minimum, per the question, is 0 (unless that is the missing number). . . .
Campbell Ritchie wrote:In that case the simpler technique of adding 1 to the size of the list give the maximum and
n*(n+1)÷2 gives the expected total.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
fred rosenberger wrote:Does the problem state that ALL integers are present between 0 and n?
I hate signatures!
Tim Cooke wrote:Good analysis of the question and you have highlighted a point of ambiguity. Is every number between 0 and n present? Yes, the question would be better phrased "Given an ordered list of sequential integers ranging from 0 to n ...".
e.g. [0,1,2,3,4,5,...,n]
The "very large" part of the question was to discourage algorithms that walked the list multiple times or generated new similarly huge lists.
Ahmed Bin S wrote:if a number is randomly removed, find it".
Ahmed Bin S wrote:"Given [0..P | P ∈ N] and P is very large, if a number is randomly removed, find it"
Brian Tkatch wrote:
Ahmed Bin S wrote:if a number is randomly removed, find it".
There's are so many fun ways to break apart formulation of this instruction.
Tim Cooke wrote:
Ahmed Bin S wrote:"Given [0..P | P ∈ N] and P is very large, if a number is randomly removed, find it"
Is it down the back of the sofa?
Ahmed Bin S wrote:
Tim Cooke wrote:
Ahmed Bin S wrote:"Given [0..P | P ∈ N] and P is very large, if a number is randomly removed, find it"
Is it down the back of the sofa?
Only if it's the final number that wins me the lottery!
Don't get me started about those stupid light bulbs. |