Google Interview Question
1,223 Interview Reviews |
Back to all Google Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Software Engineer at Google:
If you have an unsorted array of numbers from 1-100, except 1 of those numbers is missing, how do you determine which number is missing
Helpful Question?
Yes |
No
Inappropriate?
Answers & Comments (7)
2 of 3 people found this helpful
Helpful Answer?
Yes |
No
Inappropriate?
0 of 3 people found this helpful
if(values.length == 0 || values == null)
return -1;
for(int 1 : values){
for(int x = 1; x <= 100; x++){
if(!values.contains(x))
return x;
}
}
return 0;
}
Helpful Answer?
Yes |
No
Inappropriate?
0 of 2 people found this helpful
{
int missingNum = 0,i;
for(i =1;i<=array.length+1;i++)
{
missingNum = missingNum^i;
}
for(i =0;i<array.length;i++)
{
missingNum = missingNum^array[i];
}
return missingNum;
}
Helpful Answer?
Yes |
No
Inappropriate?
4 of 4 people found this helpful
Helpful Answer?
Yes |
No
Inappropriate?
1 of 1 people found this helpful
Helpful Answer?
Yes |
No
Inappropriate?
def find_missing_number(arr):
bits = len(arr)+1
for i, v in enumerate(arr):
bits ^= v ^ i+1
return bits
numbers = range(1, 101)
random.shuffle(numbers)
print find_missing_number(numbers[:-1]), "==", numbers[-1]
Helpful Answer?
Yes |
No
Inappropriate?
To comment on this
question,
Sign In with Facebook or
Sign Up
6 of 6 people found this helpful
by Interview Candidate: