## 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

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

Awesome is the word...

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

Awesome is the word

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;

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

Why not use Hashtable?

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

Why not use Hashtable?

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

Why not use Hashtable?

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.

### 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.