Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: Phone Interview




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

function findMostConsecutiveElement(x){

        var length = x.length;
        var mostConsecElement, currElement, currCount, mostConsecEleCount;
        
        //Corner cases x = [] & x = [z]

        if (x.length < 2) {
                (length == 0) ? mostConsecElement = undefined : mostConsecElement = x[0];
                return mostConsecElement;
        }
        
        mostConsecElement = currElement = x[0];
        mostConsecEleCount = currCount = 1;

        for (var i = 1; i < length; ++i){
                if (currElement == x[i]) {
                        currCount++;
                        if (currCount > length - i-1) {  //If the currCount > remaining length of the array, no way anything can be longer than this, check if its longer than previous mostConsecEleCount and return the mostConsecElement
                                if (currCount > mostConsecEleCount) {
                                        mostConsecElement = currElement
                                }
                                return mostConsecElement;
                        }
                } else {
                        if (currCount > mostConsecEleCount){
                                mostConsecElement = currElement;
                                mostConsecEleCount = currCount;
                        }
                        currCount= 1;
                        currElement = x[i];
                }
        }
        //Last time through...don't forget to check.


        if (currCount > mostConsecEleCount) {
                mostConsecElement = currElement;
        }
        return mostConsecElement;
}

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

Howz this ?

#include <iostream>

using namespace std;

int main (int argc, const char * argv[])
{
    int n;
    cin >> n;
    
    int num, count = 0, prev_num, max_num, max_count = 0;
    
    for(int i = 0;i < n; i++)
    {
        cin >> num;
        
        if(i == 0)
        {
            count++;
        }
        else
        {
            if(num == prev_num)
            {
                count++;
                
            }
            else
            {
                count = 1;
            }
                
        }
        
        prev_num = num;
        if(count > max_count)
        {
            max_num = num;
            max_count = count;
        }
       
    }
    
    cout << max_num << max_count;
    
    return 0;
}

- Srikant Aggarwal January 28, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

void maxCount(int a[], int len) {
    int i = 0;
    int maxNum, maxCount = 0, curr_num, curr_count = 0;
    for(i = 0; i < len; i++) {
        if(a[i] == curr_num) curr_count++;
        else {
            if(curr_count > max_count) {
                max_count = curr_count;
                max_num = curr_num;
            }
            curr_count = 1;
            curr_num = a[i];
        }
    }
    printf("%d has maximum count of %d", max_num, max_count);
}

- cooldaa January 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class MaxContinousRepeatChar {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(getMaxContinuosRepeatedChar("1122333344556677777".toCharArray()));
}

public static char getMaxContinuosRepeatedChar(char[] ch){

if(ch == null || ch.length==0)
return '\0';

if(ch.length==1)
return ch[0];

char maxCh = ch[0];
int countMaxCh = 1;

char prevCh = ch[0];
int countPrevCh = 1;

for(int i=1; i < ch.length ; i++){

if(prevCh != ch[i]){

if(countMaxCh < countPrevCh){
maxCh = prevCh;
countMaxCh = countPrevCh;
}

prevCh = ch[i];
countPrevCh = 1;

}else{
countPrevCh++;
}
}

//for the last char
if(countMaxCh < countPrevCh){
maxCh = prevCh;
countMaxCh = countPrevCh;
}

return maxCh;
}

}

- Navneel January 29, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static int getMaxOccurrance(int array[])
	{
		int currCount = 0, maxCount = 0, currElement = 0, maxElement = 0;
		currElement = maxElement = array[0];
		for(int i = 0; i < array.length; i++)
		{
			if(array[i] == currElement)
			{
				currCount++;
				if(maxCount < currCount)
				{
					maxCount = currCount;
					maxElement = array[i];
				}
			}
			else
			{
				currCount = 1;
				currElement = array[i];
			}
		}
		return maxElement;
	}

- hello world February 02, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

#include<stdio.h>
int main()
{
int n,a[100],i,count=1,count1=1,item;
printf("Enter the no of item\n");
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
{
if(a[i]==a[i+1])
{count++;}
else
{
if(count>=count1)
{
item=a[i];
count1=count;
}count=1;
}
}
printf("The most repeated(consecutive) item is %d and repeated %d times\n",item,count1);
return 0;
}

- narayan kunal March 05, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int maxNoTimes(int arr[], int len)
{
    int count=0;
    int count2=1;
    int max_count=0;
    
    if(len < 1)
        return 0;
    if(len < 2)
        return 1;
    
    while(count2<len)
    {
        while(arr[count2]==arr[count] && count2 < len)
        {
            count2++;
        }
        if((count2-count) > max_count)
            max_count = count2-count;
        
        if(count2<len)
        {
            count = count2;
            count2++;
        }
    }
    
    return max_count;
}

- anon May 11, 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