Facebook Interview Question for SDE1s


Country: United States




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

please provide some hints about the desired time and space complexity. There were answers with exponential run time on your previous post with the same question.

- Chris July 27, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Are you only supposed to use each number once? And since it's using integers, is the / operator used with truncation (e.g. 7/2 = 3)?

- JennaC August 01, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Assume 1) no overflow, 2) the / operator is used with truncation. This is with exponential complexity. Is there a way to make it faster?

class Solution {
private:
    bool bt(vector<int>& v, int n, int i, int left, int right){
        if(i==(int)v.size())return left+right==n;
        return bt(v,n,i+1,left+right,v[i])
            || bt(v,n,i+1,left+right,0-v[i])
            || bt(v,n,i+1,left,right*v[i])
            || bt(v,n,i+1,left,right/v[i]);
    }
public:
    bool getTarget(vector<int>& v, int n){
        return v.size() && (bt(v,n, 0, 0, v[0]) || bt(v, n, 0, 0, 0-v[0]));
    }
};

TEST(x, y) {
    vector<int> v={7,2,4};
	Solution sol;
	EXPECT_EQ(true, sol.getTarget(v,7));
}

- BruceL August 13, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

we should check nums[i] != 0, or we cannot use "/"
and check if the value != 0, so need not to do "*" and "/" anymore

- Anonymous November 18, 2017 | 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