Amazon Interview Question for Software Engineer / Developers






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

whats the Q and how is it related to median ? as anon says.

- funny July 28, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 0 vote

1.sort
2.get the sum of the distinct numbers sum2.
3.get the sum of all the numbers sum3.
4. the result is mod (sum3,sum2)

- Jackie July 28, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

If you sort the numbers then the other steps are unnecessary. Just have a pass over them and count the number of occurrences. If it happens to be odd.. thats it :-)

- Anand August 03, 2008 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

How about doing the first steps of the count sort? Use an array to keep the count of the numbers. Array size can be (max of the numbers - minimum of the numbers) and update the count of the number at the appropriate index. Wherever the count is odd, that will be the number. You don't even need to sort the array

- anonymous August 05, 2008 | Flag
Comment hidden because of low score. Click to expand.
1
of 0 vote

I am not sure, if it is optimam solution. It goes as.
Step 1 : Make an array of unique number(Say tempArray) from given array (Say OriArray)
Step 2 : Get Sum1 = 2n * sum of all numbers in tempArray
Setp 3 : Get Sum2 = sum of all numbers in OriArray
Setp 4 : get diffNum = Sum2 - Sum1
Setp 5 : DiffNum is the one which has occurances 2n+1 times in OriArray.

- Ravi August 19, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

to find the median of the array. O(n)

- Anonymous July 25, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@Ravi
Your solution works and seems reasonably efficient. My only qualm is how would you make an unique array of elements (step 1). You have to check all the elements in your temp array for every element of the original array. Then I guess it would be n^2.

An alternative approach if the range of the numbers is known is to use a bit vector of the size of that range. On seeing a number, we would increment that corresponding bit in the vector.
Finally we would do one more iteration to find out the extra number.

- prolificcoder August 24, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

hash table, count the number.

- Anonymous August 27, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@prolificcoder
If we know the range of numbers, ( say if the numbers are from 1-100), then we can use hash technique to prepare a tempArr of unique elements.

- Sadineni.Venkat February 14, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@prolificcoder
If we know the range of numbers, ( say if the numbers are from 1-100), then we can use hash technique to prepare a tempArr of unique elements in linear time O(n).

- Sadineni.Venkat February 14, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1) go through the array once, find out the occurrence O of array[0]
   Also while traverse, calculate the sum of the array S, multiplication of the array M.
   if O % 2 == 1
      return arra[0] (you are lucky)

2) else
      solve this equation:
      X*(2*O) + Y*(2*O+1) = S
      X^(2*O) * Y^(2*O+1) = M

      (Y is the number witch appear (2N+1) times

- Anonymous April 15, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@Anonymous on April 15, 2009:
WTF those equations are supposed to mean ?

- Anonymous October 08, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package com;

import java.util.HashSet;
import java.util.Set;

public class General {
static char findx(char[] arr,int length){
HashSet s=new HashSet();
for (int i = 0; i < arr.length; i++) {
if(s.add(arr[i]) == false)
s.remove(arr[i]);
}
return (Character)s.iterator().next();
}

public static void main(String[] args) {
char[] arr={'a','b','c','d','a','b','c','d','e','a'};
System.out.println(findx(arr,10));
}

}

- mrvishalg@rediffmail.com January 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

package com;

import java.util.HashSet;
import java.util.Set;

public class General {
static char findx(char[] arr,int length){
HashSet s=new HashSet();
for (int i = 0; i < arr.length; i++) {
if(s.add(arr[i]) == false)
s.remove(arr[i]);
}
return (Character)s.iterator().next();
}

public static void main(String[] args) {
char[] arr={'a','b','c','d','a','b','c','d','e','a'};
System.out.println(findx(arr,10));
}

}

- mrvishalg@rediffmail.com January 04, 2010 | 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