Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

#include<iostream>

using namespace std;

int main()
{
    int arr[] = { 1,2,1,2,5,3,4,3,4,1,2,1,2};

    int v = 0;

    for(int i=0;i<(sizeof(arr)/sizeof(int));i++)
    {
        v ^= arr[i];
    }

    cout << v << endl;

    return 0;
}

- NotThatBad January 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@ NotThatBad: ≈≈≈Ω©√ç∂∂©ƒ∂©ƒ∂©ƒ∂√熃©ƒ©ƒ†ƒ''

Yeah! Just splitting code without explaining what the heck ran in your mind and how you came to this solution makes your interviewer or any reader who drops in here fell like above. Next time, remember, people dont care to just read some random code but to read some explanation!

- AmzFAILFacebookFailMSFTFail January 17, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@NotThatBad: Thats the perfect way to go with this problem.
The otherway is using boolean hash table if the space constraint is relaxed.

- Suriya January 19, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

@AmzFAILFacebookFailMSFTFail: please accept my apologies for not providing the explanation.
xor'ing a number with itself even number of times will results in a 0 and xor'ing the number with itself odd number of times will results in the number itself. I have used this nature of xor operation to reach to this result.

- NotThatBad January 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void findOdd(int *a ,int n)
{
//sort array with O(nlogn)
int count=0; int x=a[0];
for(int i=0;i<n;i++)
{
if(a[i]!=x)
{
if((count%2)!=0)
{cout<<a[i]; return;}
else
{x=a[i]; count=1;}
}
else
count++;
}

- Ali_BABA January 17, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

doing XOR operation will get the number which has been repeated odd number of times.XOR cancels the even repetetions

- Anonymous January 21, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Again, how about a hashmap.
Add each of the elements to the hashmap on its first occurrence and remove it from the hashmap on its second occurrence. This way at the end only the object of our interest remains in the hashmap and can be found easily.

Time Complexity:O(n)
Space Complexity:O(n)

- Pavan Dittakavi May 08, 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