tags:

views:

106

answers:

2

i have one problem for example we have array

int a[]=new int[]{a1,a2,a3,a4,..........an}:

task is fill the same array by elements which are not in the array for example a={1,3,4,5,6,7} should be filled by any numbers {2,8,9,12,13,90}or others but not by elements which are in array this must not be{1,12,13,14,110} because 1 is in the array a thanks

A: 

Just get the highest and lowest number in the array, create a new array with elements from your lower bound value to n.

Obtaining the highest and lowest number can be done in the same loop.

Assuming 12,4,3,5,7,8,89, it'll detect 3 as the lowest, 89 as the highest value. It then creates a new array and fills it with 3..89; then discard the old array.

Jan Kuboschek
i want do it without additional array
You *want* or *have to*?
Jan Kuboschek
have to sorry it is constraint
You have to make an additional array because an array is static in size; well, depending on the language. Assuming that it's not static in size like in PHP, obtain the highest and lowest value, and simply overwrite your existing array. If that's what the bounds are. You still haven't clarified that.
Jan Kuboschek
+2  A: 
Moron
Nice solution, but why are you adding multiples of `n` to the negative numbers? Why `n`?
IVlad
@IVlad: Err... I meant n+1 :) To keep the remainder the same.
Moron
Yeah, I thought it should be `n+1` too :). Nice job.
IVlad