Bloomberg LP Interview Question for Software Engineer / Developers






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

This is a simple dynamic programming question. Recursion is very bad in this case ( you repeatedly compute the same things).

arr[0] = 0;
arr[1] = 1;

for(int i=2; i<=n; i++)
{
	arr[i] = arr[i-2] + arr[i-1];
	printf("%d\n", arr[i]);
}

will print all f()s till n.

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

Based on the original, what it f(2)? Or am I missing something obvious

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

Actually we need one more initial condition that is f(-1)..or there is a typing error in the question

- Musheka May 27, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

sorry the condition should be

f(x+2) = f(x) - f(x+1)

- thefourthmusketeer June 02, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I guess the reason why he modified the question is that your recursive solution did not keep those f(x) that have been calculated before, instead, you calculate all f(x) again and again. Then he gave you a hint that you can improve your recursive solution. I just have a guess.

- chenming831@gmail.com May 29, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Or just that the interviewer is a stupid moron who wants you to code in his style.. or just giving you
a hard time because bloombies are full of arrogancies

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

Here is the solution! ;)

int funcb(int x)
{
if (x == 0)
return 1;
else if (x == 1)
return 0;
else if(x>1)
return funcb(x-2)-funcb(x-3);
else
return 0;
}

- Waqas Ahmed June 04, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

That does not look like the solution

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

do some simple algebra
f(x+2)=f(x)-f(x-1) => f(x)=f(x+2)+f(x-1)
int f(x)
{
if x=0 return 1;
else if x=1 return 0
else return f(x+2)+f(x-1)
}

- nestlie July 01, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

crap... do you think this will ever terminate?

- Anonymous July 02, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Yes ofcourse dear

when the stack overflows

- Tariq October 14, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Fibonacci numbers .. but with -ve and +ve sequence

- $dF::rON August 12, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

<pre lang="c++" line="1" title="CodeMonkey53228" class="run-this">#include <iostream>

using namespace std;
int funcb(int x)
{
if (x == 0)
return 1;
else if (x == 1)
return 0;
else if(x>1)
return (funcb(x-2)-funcb(x-1));
}
int main()
{
int no;
cout<<"Enter the no ";
cin>>no;
cout<<"func of %d is %d\n",no,funcb(no));
return 0;

}
</pre><pre title="CodeMonkey53228" input="yes">5
</pre>

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

<pre lang="c++" line="1" title="CodeMonkey56226" class="run-this">#include <iostream>

using namespace std;
int funcb(int x)
{
if (x == 0)
return 1;
else if (x == 1)
return 0;
else if(x>1)
return (funcb(x-2)-funcb(x-1));
}
int main()
{
cout<<"func of "<<5<<"is "<<funcb(5);
return 0;
}
</pre><pre title="CodeMonkey56226" input="yes">
</pre>

- Anonymous August 12, 2010 | 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