Amazon.com
3.4 of 5
www.amazon.com Seattle, WA 5000+ Employees

# Amazon.comSoftware Development Engineer Interview Question

I interviewed in Seattle, WA and was asked:
"Given a random array with integers, find every pair that sum up to a certain number."

Part of a Software Development Engineer Interview Review - one of 3,486 Amazon.com Interview Reviews

3
of 7
public static void helper(int[] a, int m){
int tmp[] = new int[m];

for(int i=0; i<a.length; i++){
if(tmp[a[i]-1] == 1){
int result = m - a[i];
System.out.println(a[i] +" "+ result);
}
else tmp[m-1-a[i]] = 1;
}
}
- Anonymous on Mar 1, 2012 Flag Response
2
of 2
// find all the pairs that sum up to a given number
int* findPair(int a[], int size, int sum)
{
unordered_map<int, int> numMap;
int *pairs = new int [size*2];
for ( int i = 0; i < size; i++ )
{
numMap.insert(unordered_map<int, int>::value_type(a[i], i));
}
for ( int j = 0; j < size; j++ )
{
if ( numMap.find(sum-a[j]) != numMap.end() )
{
pairs[2*j] = a[j];
pairs[2*j+1] = numMap.find(sum-a[j])->first;
numMap.erase(a[j]);
printf("%d + %d = %d\n", pairs[2*j], pairs[2*j+1], sum);
}
}
return pairs;
}
- Nina on Mar 13, 2012 Flag Response
0
of 0
void findPairs(int[] nums, sum){
Set<Integer> numSet = new HashSet<Integer>();
for(int num : nums){
}
for(int num : nums){
if(numSet.contains(sum-num){
System.out.println("Pair: "+num+" - "+(sum-num));
}
}
}
- Badal Shah on Oct 21, 2012 Flag Response
0
of 0
There is just one little improvement if you sum=30 and you have 1,20, 10 , 15. when you found that for 20 , 10 exists. You shouldn't check for 10. This will bring down iteration size.
- Rahul on Mar 21, 2013 Flag Response

### Amazon.com – Why Work for Us?

At Amazon, we believe that everyone is a leader—it's part of what makes us 100% Peculiar. Whether you are a Software Development Engineer, Product Manager, Fulfillment Associate, or Customer Service Representative, you…

Provided by employer [?]

### Salaries by Company

Tags are like keywords that help categorize interview questions that have something in common.

Glassdoor is your free inside look at Amazon.com interview questions and advice. All interview reviews posted anonymously by Amazon.com employees and interview candidates.