0
Explain,how to find out the missing number in given array with programming
I need an explanation
7 Respuestas
+ 4
55 - sum of all elements in the array = missing number (credit for this idea goes to Schindlabua)
+ 3
You haven't given enough information in your question to really answer that. What're the specifications? What determines that it's a number that's missing? Depending upon the specifications, there are many ways to figure out if there is a number missing, but a number missing is completely subjective to whatever rule you're imposing upon the data set.
+ 3
Credit goes to some random guy on IRC which is where I got it from :P
Anway this is the post Anna was talking about:
https://www.sololearn.com/discuss/1784886/?ref=app
+ 3
Playing off what Jackson O'Donnell said:
https://code.sololearn.com/ci6Btrt4612h/#java
public class Program
{
public static void main(String[] args) {
boolean validationArr[] = new boolean[10];
int numberSetArr[] = {1,5,3,8,2,6,9,7,4};
for(int i = 0; i < numberSetArr.length; ++i)
{
validationArr[numberSetArr[i]-1] = true;
}
for(int i = 0; i < validationArr.length; ++i){
if(validationArr[i] == false){
System.out.println("Missing Number: " + (i+1));
}
}
}
}
:::: Array Input ::::
{1,5,3,8,2,6,9,7,4}
:::: OUTPUT :::::
Missing Number: 10
:::: Array Input ::::
{1,5,3,8,2,6,10,7,4}
:::: OUTPUT :::::
Missing Number: 9
:::: Array Input ::::
{1,5,9,8,2,6,10,7,4}
:::: OUTPUT :::::
Missing Number: 3
You can also use it to find multiple missing numbers:
:::: Array Input ::::::
{1,5,9,8,10,7,4}
::: OUTPUT ::::
Missing Number: 2
Missing Number: 3
Missing Number: 6
+ 2
If you just need to find the missing number and there are only 10 numbers, the easiest thing would be to make an array of booleans size 10. When going through the array of numbers, set to "true" the index of the corresponing number-1. (so if 1 is found, set 0 to true etc.)
+ 1
Between 1 to 10
+ 1
Thank you for answering