Amazon Interview Question for Software Engineer / Developers


Team: SDE
Country: India
Interview Type: In-Person




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

1st take the array as a1a2...b1b2... only dont take c1c2...
then divide the array into 4 parts as
part 1 : a1a2..a(n/2)
part 2 : a(n/2+1)....an
part 3 : b1 b2... b(n/2)
part 4 : b(n/2+1)....bn
now swap p1 p3 and p2 p4 then

repeat from above

so problem is divided into sub problems . Use recursion
think in the same way for a1b1a2b2... with c1c2...

- kasireddi February 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

It is grouping P1,P3 and P2,p4 right not swapping
after rearragement it should look like p1,p3,p2,p4

- SecretAgent February 11, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

1st take the array as a1a2...b1b2... only dont take c1c2...
then divide the array into 4 parts as
part 1 : a1a2..a(n/2)
part 2 : a(n/2+1)....an
part 3 : b1 b2... b(n/2)
part 4 : b(n/2+1)....bn
now swap p1 p3 and p2 p4 then

repeat from above

so problem is divided into sub problems . Use recursion
think in the same way for a1b1a2b2... with c1c2...

- kasireddi February 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

public void merge(int[] a, int begin, int n) {
        if (n == 1) return;
        int p1 = begin;
        int p2 = p1 + n;
        int p3 = p2 + n;
        int b = a[p2];
        int c = a[p3];
        
        for (int i = p3-1; i > p2; i--) {
            a[i + 1] = a[i];
        }
        for (int i = p2-1; i > begin; i--) {
            a[i + 2] = a[i];
        }
        a[begin + 1] = b;
        a[begin + 2] = c;
        merge(a, begin + 3, n - 1);
    }

- syeedibnfaiz February 07, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use the Dutch flag sort method to solve this

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

nope that's not about sorting [1,2,3] numbers: use in-place matrix transpose algorithm

- Anonymous February 03, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

what about O(1)?

- vlad February 07, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

My solution takes O(1) extra space.

- syeedibnfaiz February 07, 2012 | Flag


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