Amazon Interview Question for SDE-2s


Country: India
Interview Type: In-Person




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

geeksforgeeks.org/dynamic-programming-set-10-0-1-knapsack-problem/

- Mohit March 23, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Looks like you are trying to peddle the geeksforgeek site.

- Anonymous March 24, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

int max(int a,int b)
{
    if(a>b)
      return a;
    return b;
}

int maxvalue(int val[],int wt[],int W,int n)
{
    if(W==0 || n==0)
       return 0;
    if(wt[n-1]>W)
       return maxvalue(val,wt,W,n-1);
    return max(val[n-1]+maxvalue(val,wt,W-wt[n-1],n),maxvalue(val,wt,W,n-1));
}

- Nitin April 02, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{{
int knapsack(int n,int val[], int W, int w[])
{
int i,j;
for(i=0;i<=n;i++)
{
for(j=0;j<=W;j++)
{
if(i==0 || j==0)
dp[i][j]=0;
else{
if(w[i-1]<=j) dp[i][j]=dp[i-1][j-w[i-1])+val[i-1];
else dp[i][j]=0;
dp[i][j]=max(dp[i][j],dp[i-1][j]);
}
}
}
return dp[n][W];
}
}}

- Anonymous February 03, 2016 | 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