Re: searching for missing element in an array
- From: user923005 <dcorbit@xxxxxxxxx>
- Date: Thu, 29 May 2008 15:32:08 -0700 (PDT)
On May 29, 4:39 am, rossum <rossu...@xxxxxxxxxxxx> wrote:
On Thu, 29 May 2008 03:10:32 -0700 (PDT), srk <kuma...@xxxxxxxxx>
wrote:
Hi,
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
Total all the numbers in the array.
The numbers from 1 to n add up to (n * (n + 1)) / 2.
The difference is the missing number.
What happens if you have some number twice?
e.g.: 1,2,2,4,5
What happens if the array was initialized to all -1 values?
Do we know that a zero is stored in the slot of the missing number?
.
- Follow-Ups:
- Re: searching for missing element in an array
- From: CBFalconer
- Re: searching for missing element in an array
- 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: In-place algorithm
- Next by Date: Re: In-place algorithm
- 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
|