Re: searching for missing element in an array
- From: Ico <usenet@xxxxxxx>
- Date: 29 May 2008 11:50:12 GMT
rossum <rossum48@xxxxxxxxxxxx> wrote:
On Thu, 29 May 2008 03:10:32 -0700 (PDT), srk <kumarsr@xxxxxxxxx>
wrote:
Hi,Total all the numbers in the array.
Suppose we have n numbers(from 1 to n) and there is an array of size
n-1. How can we find, which number is missing from the array if
numbers 1 to n are being placed in array randomly.
Thanks
SRK
The numbers from 1 to n add up to (n * (n + 1)) / 2.
The difference is the missing number.
Yes, now we all know you know the trick. Thanks for doing his homework,
I guess he really learned something today :)
--
:wq
^X^Cy^K^X^C^C^C^C
.
- References:
- searching for missing element in an array
- From: srk
- Re: searching for missing element in an array
- From: rossum
- searching for missing element in an array
- Prev by Date: Re: searching for missing element in an array
- Next by Date: Re: searching for missing element in an array
- Previous by thread: Re: searching for missing element in an array
- Next by thread: Re: searching for missing element in an array
- Index(es):
Relevant Pages
|