Amazon Interview Question for Software Engineer / Developers






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

any constraint given... like o(n) Time complexity and o(1) or o(n) space complexity

- asetech February 10, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

A = given array.
Ab = ASCII of A % no need to initialize
Initialize B with size max(Ab)
Go thru Ab one by one, get the number 'n' and add 1 to the nth index B.
Finally get the max(B).

Time:2*o(n)
Space:2*o(n)

- shekhar2010us February 10, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Rather I would say initialize an array of size 27 to zero
int a[27];
after that for every character encountered in the given array update the count in initialized array and maintain a counter max and maxChar which will be updated any time u found a new max.

This method is = O(n) , space complexity is constant because irrespective of how many characters in the array the size will be same.( I am assuming input to be lower case characters only.)

- surebh February 10, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

if no contraints on space then use a hashmap with alphabets as key and count as value. After traversing the array just return the largest count.
There are better solutions like some mentioned above.

- compmanic February 10, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

if no contraints on space then use a hashmap with alphabets as key and count as value. After traversing the array just return the largest count.
There are better solutions like some mentioned above.

- compmanic February 10, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

if no contraints on space then use a hashmap with alphabets as key and count as value. After traversing the array just return the largest count.
There are better solutions like some mentioned above.

- compmanic February 10, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I was expected to give a time and space efficient solution. There weren't any constraints given.
Using O(n) extra space is one option. That would be O(n) time.
You can sort the array in O(nlogn) time and get the result with one traversal and O(1) space.
I can't think of any better solution.

- Jam February 11, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1) Use an array of size = No. of alphabets in language = 26 (English)
2) Traverse the character array and increment the corresponding index. ---> O(n)
3) Find index of largest value and print corresponding alphabet ---> O(n)

- ac February 11, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

My solution
1. Use HashMap<alphabet, count> and find the alphabet with maximum count.
2. Quick Sort the alphabets in O(nlogn) and find the maximum in one traversal.

- Karthik February 15, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Take a array of size 26 ,each representing one alphabet.

Initilize all array elements by zero.

Scan array and increase count in the corresponding index.

you are done now.

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

//Voting algorithm
List<int> li16 = new List<int>();
li16.Add(1);
li16.Add(2);
li16.Add(2);
li16.Add(2);
li16.Add(1);
li16.Add(1);
li16.Add(2);
li16.Add(3);
li16.Add(2);
li16.Add(3);
int candidate16 = li16[0];
int count16 = 1;
for (int i = 1; i < li16.Count; i++)
{
if (li16[i] == candidate16)
count16++;
else count16--;
if (count16 == 0)
{
candidate16 = li16[i];
count16++;
}
}

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

char a[5]={'a','a','a','b','e'};
int num=0;
int hash[256]={0,};
for(int i=0;i<5;i++)
hash[a[i]]++;
int big=hash[0];

for(int i=1;i<256;i++)
{
if(hash[i]>big)
{
big=hash[i];
num=i;
}


}
cout<<endl<<big<<endl<<(char)num;

This is the perfect code which i have tested....

- Nikhil February 24, 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