Amazon Interview Question for Applications Developers


Country: India




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

Take two pointers pointing to first and second half ..Compare the elements present..in them
..Output/ print the one which is smallest and increment its index pointer..and keep the other index pointer as it is ..run the loop till the all the elements are Exhausted / printed :)

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

like a merge

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

what if we need to sort the array in O(1) Space Complexity?

- Sid November 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

can do inplace merge , but that is very non trivial so dont expect it in interview
other way is normal sorting i.e nlogn can do better then it in O(1) space

- Geek December 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 2 vote

The mid point of the array is known. Use a merge sort on the two halves and put the sorted content in the 3rd array.

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

public static void main(String args[]) {
	int[] a = {1,3,4,7,11,18,0,2,5,8,21,25};
	int mid = a.length/2;
	int i = 0, j = mid;
	
	while (i < mid && j < a.length) {
		System.out.println(a[i] < a[j]? a[i++]: a[j++]);
	}
	if (i == mid)
		while (j < a.length)
			System.out.println(a[j++]);
	else
		while(i < mid)
			System.out.println(a[i++]);
}

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

merge sort

- peter tang October 31, 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