Amazon Interview Question for Software Engineer / Developers

• 0

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...

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

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

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...

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);
}``````

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

Use the Dutch flag sort method to solve this

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

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

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

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

My solution takes O(1) extra space.

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.

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.