## Amazon Interview Question for Development Support Engineers

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

use a hash table keeping count of the elements occurring( most common) Now find the element with maximum count and find sum as
number of occurrence * value.

O(n) time , O(n) space

hope it helps

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

another solution for the problem. O(nlgn) time, O(1) space

use four variable curMax,curVal, max, val.
sort the arry.
curVal = A[0];
curMax = 1;
for (i=1;i<n;i++) {
if (A[i] == curVal)
curMax++;
else {
if (curMax > max) {
max = curMax;
val = curVal;
}
curMax = 1;
curVal = A[i];
}

}

if (curMax > max) {
max = curMax;
val = curVal;
}

return max*val;

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

Hi,
What is the team that you interviewed for? Is it AWS?

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

if the highest element is not significantly very large then this solution will work in O(L).L is largest element in the array.
declare an array of the size of L and keep incrementing Arr[i] if i is found. find the max element in Arr. the ans will be "max element * arr[max]"

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

haven't tested out the code, but this should work.

my \$biggest = 0;
my %hash = ();
foreach my \$num (@A) {
if ( \$hash{\$num} ) {
\$hash{\$num}++;
} else {
\$hash{\$num} = 1;
}
if (\$hash{\$num} > \$biggest) {
\$biggest = \$num;
}
}

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

oh, forgot to tally the highest guy... here's the full code:

<pre>
my \$biggest = 0;
my %hash = ();
foreach my \$num (@A) {
if ( \$hash{\$num} ) {
\$hash{\$num}++;
} else {
\$hash{\$num} = 1;
}
if (\$hash{\$num} > \$biggest) {
\$biggest = \$num;
}
}

return \$biggest * \$hash{\$biggest};
</pre>

also, this would take O(n) time, as it only needs iterate through the array once...

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

cristo, your solution finds the sum but it does that in O(n) + O(n) = O(n)
once for going through the list putting the numbers in the hash table and the second one for going through the hash to find the number that occurs maximum number of times, right?
One Question:
What if we have a scenario like this:
2,3,4,5,6,4,6,7,
what is the output in this case?
ans = 4+4 or 6+6 or 4+4+6+6 ???

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

I think nickNack has a point.
guys whats the answer for his Question ?

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.

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

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