Amazon Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

Check whether A[i] is already put into into A[A[i]].
If yes -> duplicate.
If no, swap(A[i], A[A[i]])

- Silence February 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

take the xor for 1 to n-1.....lets say x=(1^2^....^n-1)
now xor x with all elements from 1 to n in the array...
the result is the required no...

- sg February 05, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

sum all the numbers
subtract the sum of n-1 numbers from the above sum
u get the duplicate

- a February 05, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

nice solution for sum up all numbers.

- yj February 17, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

How does adding the numbers help? Are you confusing the qus with the "one is missing" problem?

- aquila.25 March 04, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

((n-1) +1)/2 is the average value of the "proper" array.
Average * (n - 1) is the sum of 1..(n - 1).
Sum the elements in the array. The difference between these two sums is the extra.
Example:
1,2,3,3,4 (n = 5)
average = 2.5; sum = 10
sum of the given array is 13.
13 - 10 = 3, the extra value.

The indexing method works, but using math takes constant memory, instead of linear.

- Jason March 13, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

void main()
{
int a[] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,13};

int x =a[0];

for (int i=1;i<17;i++)
x^=(i^a[i]);

cout<<x<<endl;

char c =getchar();
while( c!=32) c=getchar();

}

- Anonymous February 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Try to construct a binary tree from N numbers, on course you can find the duplicate.

- Anonymous March 01, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

One of the best algorithms to solve the above problem statement is to use the concept of bit manipulation, we will first xor all the numbers from 1 to n - 1 and we will then xor all the array elements and store them in a separate variable and at the end, we will xor both of them together and finally we will get the duplicate element in the array.

Implementation:

int findrepeating(int arr[], int n){
	int xor_numbers = 1;
	int xor_array = arr[0];
	for(int i = 2; i <= n - 1; i++)
		xor_numbers = xor_numbers ^ i;
	for(int i = 1; i < n; i++)
		xor_array = xor_array ^ arr[i];
	return xor_numbers ^ xor_array;
}

- swapnilkant11 July 27, 2019 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More