Amazon Interview Question for Software Engineer / Developers


Team: Kindle-Periodicals
Country: India
Interview Type: In-Person




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

int multiply(int *a, int fwdProduct, int indx) {
    int revProduct = 1;
    if (indx < N) {
       revProduct = multiply(a, fwdProduct*a[indx], indx+1);
       int cur = a[indx];
       a[indx] = fwdProduct * revProduct;
       revProduct *= cur;
    }
    return revProduct;
}

- mohit March 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Use 2 arrays : fill ist array with cumulative product starting from the first element
fill 2nd array with cumulative product starting from the last array

for ( i = 0; i < n ;i ++)
{
   Result[i] = FirstArray[i-1] * SecondArray[i+1]; 
}

- Harish March 18, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

first multiply forward, so that b[i] contains the product of a[0]*a[1]*...*a[i-1]

b[0] = 1;
    for(int j = 1; j < b.size(); ++j) {
        b[j] = b[j - 1] * a[j - 1];
    }

and then multiply backwards and multiply every b[i] by the product of all a[i+1]*...*a[n]

int back_mult = a[a.size() - 1];
    for(int k = b.size() - 2; k >= 0; --k) {
        b[k] = b[k] * back_mult;
        back_mult *= a[k];
    }

- just_passing_through March 19, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

product = a(0)*a(1)*.....*a(n)

b(0) = product / a(0)
b(1) = product/a(1)

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

import java.util.*;


public class Test {
    
    public static int foo(int[] A, int[] B, int index, int lp) {
        if (index == A.length)
            return 1;
        int rp = foo(A,B,index+1,lp*A[index]);
        B[index] = lp * rp;
        return A[index] * rp;
    }

    public static void main(String[] args) {
        int[] A = {1,2,3};
	int[] B = new int[A.length];
	foo(A,B,0,1);
	for (int i=0; i < B.length; i++) {
            System.out.print(B[i] + " ");
        }
        System.out.println();	
    }
}

- Sanil March 20, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

For the solution that does not use division, is the solution O(n^2) or is it better than this

- Anand_friendly January 22, 2013 | 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