Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

celia

macrumors newbie
Original poster
Jun 24, 2007
8
0
Hi,

Here is a problem.

1. A Array has 100 elements. {say, int a[100]}
2. Each of it is filled with a random number. {say, a[1] =99, a[2] = 8, .......}
3. Only one element is filled with zero.

Question: What should be the random number in place of which zero is present?

How to solve this problem? What is the logic? :eek:

Thanks
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
Unless there are some other rules then the element can contain any number. Did you, perhaps, forget to tell us something important, like, say that each number 1...100 must appear once in one element?

Also this sound more than a little like a homework assignment that you should be figuring out on your own...
 

4409723

Suspended
Jun 22, 2001
2,221
0
Definitely sounds like some sort of information is missing. Assuming Robbie's idea is the missing information.

An easy way that would (although probably not the fastest) solve the problem:

1. Take your array and sort it using quicksort or something like that.
2. Traverse it looking for the jump of 2 numbers (or the duplicate).
3. Return the missing/duplicated number.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.