Interview Question

Software Design Engineer Interview(Student Candidate) Seattle, WA

Given an array of 100 integers where every integer from

  1-101 occurs once, except for one. Find the missing integer.

Interview Answer

2 Answers


sum of number from 1 to n is n(n+1)/2

So Sum from 1 to 101 = (101*102)/2 = 5151

So missing number is 5151 - (sum of all elements in the given array)

Anonymous on Dec 3, 2010

Let a = XOR of all elements in array and b = XOR of all numbers from 1 to 100. The final result is a XOR b

Anonymous on Jun 14, 2012

Add Answers or Comments

To comment on this question, Sign In with Facebook or Sign Up