Amazon Interview Question for Software Engineer / Developers


Country: United States
Interview Type: In-Person




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

#include<stdio.h>
int main()
{
        int num1,num2;
        printf("enter no. of elements in array1=");
        scanf("%d",&num1);
        int arr1[num1];
        int i;
        for(i=0;i<num1;i++)
                scanf("%d",&arr1[i]);
        printf("enter no. of elements in array2=");
        scanf("%d",&num2);
        int arrmerge[num1+num2];
        int arr2[num2];
        for(i=0;i<num2;i++)
                scanf("%d",&arr2[i]);
        int str1=0,str2=0,count=0;
        int strlm1=num1-1,strlm2=num2-1,flag=1;
        for(count=0;str1<=strlm1+1&&str2<=strlm2+1;count++)
        {
                if(arr1[strlm1]<arr2[strlm2]){
                if(arr1[str1]<arr2[str2]&&str1<=strlm1){
                        arrmerge[count]=arr1[str1];
                        str1=str1+1;

                        }

                else  {
                arrmerge[count]=arr2[str2];
                str2=str2+1;
                }
                }
                if(arr1[strlm1]>arr2[strlm2]){
                if(arr1[str1]>arr2[str2]&&str2<=strlm2){
                        arrmerge[count]=arr2[str2];
                        str2=str2+1;

                        }

                else  {
                arrmerge[count]=arr1[str1];
                str1=str1+1;
                }
                }
        }
        for(i=0;i<num1+num2;i++)
                printf("%d ",arrmerge[i]);
        return 0;
}

- mrmastikhorchandan October 31, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

merge sort.

- Anonymous October 31, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Did you attend interview in CMU?

- Vasim October 31, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@ASU

- eyeonu.imtiyaz November 01, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class MergeArrays {

	public int[] merge(int[] a, int[] b) {
		
		int[] c = new int[a.length + b.length];
		
		int i = 0, j = 0, index = 0;
		
		while (i < a.length && j < b.length)
			c[index++] = a[i] < b[j]? a[i++]: b[j++];
		
		if (i == a.length)
			while (j < b.length)
				c[index++] = b[j++];
		else
			while (i < a.length)
				c[index++] = a[i++];
		return c;
	}
}

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

A simple 2 way merge should do ! running time will be O(m+n)

- Rahul Arakeri November 27, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

private static int[] merge(int arr1[], int arr2[]) {
int result[] = new int[arr1.length + arr2.length];
int firstCounter = 0;
int second = 0;
for (int i = 0; i < result.length; i++) {
if (firstCounter < arr1.length && second < arr2.length
&& arr1[firstCounter] < arr2[second]) {
result[i] = arr1[firstCounter];
firstCounter++;

} else if (second < arr2.length) {
result[i] = arr2[second];
second++;

} else if (firstCounter < arr1.length) {
result[i] = arr1[firstCounter];
firstCounter++;

} else if (arr1[firstCounter] == arr2[second]) {
result[i] = arr1[firstCounter];
result[i++] = arr1[second];
second++;

firstCounter++;

}

}
return result;
}

- Anonymous April 26, 2014 | 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