Apple Interview Question
967 Interview Reviews |
Back to all Apple Interview Questions & Reviews
Interview questions and reviews posted anonymously by interview candidates
Interview Question for Senior Software Engineer at Apple:
In a stream of integers from 1 to n, only one number will be repeated. How can you tell what that number is?
Helpful Question?
Yes |
No
Inappropriate?
Answers & Comments (5)
7 of 8 people found this helpful
Helpful Answer?
Yes |
No
Inappropriate?
0 of 3 people found this helpful
Helpful Answer?
Yes |
No
Inappropriate?
0 of 3 people found this helpful
int xorSum = 0;
for(int i =0 ; i < n; i++)
{
sum += input[i];
xorSum ^= input[i]
}
return (sum - xorSum)/2;
Helpful Answer?
Yes |
No
Inappropriate?
1+2+2+3= 8
1^2^2^3= 2
(8-2)/2=3?2
Helpful Answer?
Yes |
No
Inappropriate?
To comment on this
question,
Sign In with Facebook or
Sign Up
0 of 2 people found this helpful
by Interview Candidate: