Facebook Interview Question for Software Engineer / Developers






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

This is one of the best puzzles i had seen uptill date

- CUNOMAD May 18, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Isn't this the unbounded knapsack problem, which is NP Hard?

There are greedy (approximation) algorithms: eg: just use the sku with least cost per unit weight, but that won't give optimal (hence an approximation algorithm).

A lot of literature on these problems exists, just look it up on the web.

- LOler May 18, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Of course, the assumption is that you can pick only an integer numnber of SKUs to be chucked and the input gives the weight and cost of 1 such unit.

- Loler May 18, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Someone has added this to the "Request for Help" Section. Why? LOLer post's answer this. How much spoon feeding do you need?

- Anonymous May 19, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Yes. Bounded knapsack suits this. Do some looking up on the web.

- T June 14, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Dynamic programming.

- Anonymous August 06, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Dynamic programming. I've passed the Facebook robot.

- Anonymous August 06, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I also think it is NP-Complete. Integer linear programming?

- Anonymous September 17, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

any hints on approaches to take? Sort the SKUs by cost first? by weight?

- Anonymous November 22, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

They asked me to discuss about how to solve this problem ..

- :P March 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

Dude !!!

With the way you have described the question and specs, I don't think this was ASKED in an interview. Furthermore if this WAS asked (by any chance) then they might not be in the mood of hiring :P

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

All these lengthy description points to knapsack problem I guess :)

- arnab.banerjee.82@gmail.com March 24, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

sounds like it too. Weird, you don't usually ask NP complete questions in an interview. Is there a trick that makes this NOT NP-complete ?

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

Dynamic Programming

- Kritik March 25, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Awesome!! This is valid question in linux world :-)

called out of memory problem .. google for it (oom killer)

- Initrd March 25, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can we drop partial items or we have to drop the complete item?
Because if we are allowed to drop partial item this problem becomes
a variant of fractional knapsack, which can be solved by greedy algorithm.

- newcomer March 25, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I had some very similar question at my Amazon on-site interview too.

static int minDump(Cargo[] set, int weight, int value, int currentMin)
    {
	if (value > currentMin)
	{
	    return currentMin;
	}
	
	if (weight < 0)
	{
	    return value;
	}

	int min = currentMin;

	for (Cargo cargo : set)
	{
	    min = java.lang.Math.min(min, minDump(set, weight-cargo.weight, value + cargo.value, min));
	}

	return min;
    }

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

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <climits>

using namespace std;

int main(){
int W;
cin>>W;
int n;
cin>>n;
int c[n+1], w[n+1];
int s=0;
for(int i=1;i<=n;++i){
cin>>w[i]>>c[i];
s+=w[i];
}
long long int dp[s+1][n+1];
for(int i=0;i<=n;++i){
dp[0][i]=0;
}
for(int i=1;i<=s;++i){
dp[i][0]=INT_MAX;
}
int f=0;
long long int ans=INT_MAX;
for(int i=1;i<=s;++i){
for(int j=1;j<=n;++j){
dp[i][j]=min(dp[i-w[j]][j]+c[j], dp[i][j-1]);
}
if(i>=W && dp[i][n]!=INT_MAX){
f=1;
ans=min(ans, dp[i][n]);
//break;
}
}
cout<<ans<<endl;
return 0;
}

- elektron July 01, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Its a modification of Knapsack problem, where,

1250 = total capcity of knasack
Item 1 :
w = 1300 , v = 10500
Item 2 :
w = somevalue , v = some value

now have to select subset of items whose total weight is less than the capacity and have min value. ( in Knapsack we select items having max value)

- vivekh July 29, 2015 | 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