+ 5

How to find the missing element (number) in an Array?

20th Feb 2017, 10:43 PM
Bukuru Henry
Bukuru Henry - avatar
11 Antworten
+ 4
i searched the answer on different references an i got, YOU CAN FIND THE MISSING ELEMENT OF AN ARRAY BY IND THE SUM OF ALL ELEMENTS THEN FIND THE DIFFERENT OF THE SUM YOU GOT WITH AN EXPECTED OUTPUT,
21st Feb 2017, 10:04 PM
Bukuru Henry
Bukuru Henry - avatar
+ 3
no .. just any number which may be the among of. elements of ana array @liam keegan
21st Feb 2017, 12:07 AM
Bukuru Henry
Bukuru Henry - avatar
+ 3
but the number is unknown... how can you assume that it is 0 or any other number???
21st Feb 2017, 6:49 AM
Bukuru Henry
Bukuru Henry - avatar
+ 3
no assumption should be taken into consideration
21st Feb 2017, 7:01 PM
Bukuru Henry
Bukuru Henry - avatar
+ 3
your welcome Justin
22nd Feb 2017, 6:24 AM
Bukuru Henry
Bukuru Henry - avatar
+ 1
your right Bukuru. I wrote a 4 loop to check it and it works. now I know how to tell what is missing. thanks numbers=[1,2,4,5,6,7,8,9] goal=45 total=0 for i in numbers: total=total+i print(goal-total) Python, but proof of concept anyway. (that's what I use python for)
22nd Feb 2017, 12:03 AM
LordHill
LordHill - avatar
0
Do you mean a value of zero?
20th Feb 2017, 11:21 PM
Liam Keegan
Liam Keegan - avatar
0
a for loop?
21st Feb 2017, 2:48 AM
LordHill
LordHill - avatar
0
if you're looking for example for 0, loop through the array using enhanced for loop. This code will return the index of the element that is 0 on the array. for(int currentNumber : myIntArray){ if(currentNumber == 0){ return currentNumber; } }
21st Feb 2017, 5:04 AM
David Koplik
David Koplik - avatar
0
so I assume you would know which numbers are suppose to be present in the array?
21st Feb 2017, 2:04 PM
LordHill
LordHill - avatar
0
If it's an int array, it only contains numbers. What do you call "missing number"? If you mean null, just change the code I give you and check if it's null instead of zero.
21st Feb 2017, 9:28 PM
David Koplik
David Koplik - avatar