Amazon Interview Question for Software Engineer / Developers


Country: India




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

I found an awesome Algo for the same on the Internet:

1. So as usual find the XOR of all the @n+2 numbers
2. Next find in th XOR result find any bit which has been set. Like say if XOR result is number '5' then we know that 0th bit (LSB) in 5 (0101) is set
3. Divide the array into two parts A and B. A will contain those elements in which that bit is set and B will contain those elements in which that bit is not set
4. Finally XOR all the elements of A and all the elements of B.
- Result of XOR on A gives us the first element and Result of XOR on B gives the second element

- Mandar February 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Awesome is the word...

- Saurabh February 24, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Awesome is the word

- Saurabh February 24, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use combination of XOR and (n*n-1)/2 operations.


int nValue=0;
int nMinusOneValue=0;
int n=arr.length-1;
int XOR = 0;

for(int i=0;i<=n;i++){

XOR = XOR ^ arr[i];
nValue=nValue+arr[i];

if(i < n){
nMinusOneValue=nMinusOneValue+arr[i];
}


}

int oneValue=Math.abs(nValue-nMinusOneValue);

int otherValue=oneValue ^ XOR;

- analog76 February 11, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Why not use Hashtable?

- David February 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Why not use Hashtable?

- David February 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Why not use Hashtable?

- David February 16, 2012 | 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