Amazon Interview Question for Software Engineer in Tests






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

for(int i=0; i<n; i++)
{
 if(a[i] % 2 !=0 )
 { 
   printf("%d", a[i]);
   break;
 }
}

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

@Anonymous: I think you got the question wrong.

The array has numbers which are repeated even no of times expect one.
ex: {1,1,2,2,2,2,3,3,3,7,7,7,7}

The best way to find out the odd repetition is to do a XOR.

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

read each array element.
Add element into a hashtable and remove it when u encounter it in the array again.
the elements left in hastable after u are done reading the entire array are the odd elements.

- bob March 05, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

just use XOR. numbers that show up an even number of times will cancel. the value of final will reflect the odd element.

int final = 0;
for (int i=0; i<n; i++)
  final ^= a[i];

- woohoo March 05, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

bingo

- airfang613 March 05, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

check a[0] value with remaining values. if equal increment x. similarly check a[1],a[2]........... . if x value remains odd we can find out the odd repeated value

- prudhvi illindraparti March 06, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

What if there is no odd element? Example, [1,1,2,2,3,3,4,4] - XORing all this together will give you 0, the same answer you would get by XORing an array where 0 is the odd element.

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

sort the array.
then push the element in stack. If u encounter the same element , then pop it from the stack.Keep repeating it. The elements that are present even no. of times will be finally removed from the stack and only element present odd no. of times be left in stack

- Anonymous April 14, 2011 | 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