## Morgan Stanley Interview Question for Software Engineer / Developers

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

``````stack a;
Fibonacci(n){ // to produce a n level Fibonacci sequence
int a=0,b=1;
a.push(a);
a.push(b);
print a;
while(n!=0){
a = a.pop();
b = a.pop();
print b;
a.push(b);
a.push(a+b);
n--;
}``````

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

``````{
// Without Recursion
int Fibonacci(int n)
{
int prev1 = 1, prev2 = 1;
int cur = 0;

if (n <= 2)
return 1;
else
{
for (int i = 3; i <= n; i++, prev2 = prev1, prev1 = cur)
{
cur = prev2 + prev1;
}
return cur;
}
}``````

}

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

int fibonacci(int n)
{
int fib0 = 0, fib1 = 1, i, temp;

if (n == 0) return fib0;
else if (n == 1) return fib1;

/* After each iteration, fib0 and fib1 are
* the ith and (i-1)st fibonacci numbers
*/
for (i = 2; i <= n; ++i)
{
temp = fib1;
fib1 = fib0 + fib1;
fib0 = temp;
}

return fib1;
}

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

int fibonacci(int i){
if((i==1)||(i==2))
return 1;
else
return (fibonacci(i-1)+fibonacci(i-2));
}

void main(){

cout << fibonacci(6);

}

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

"code up a Fibonacci function with the one constraint being that I COULDN'T write a RECURSIVE function"

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

use DP solution

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.

### 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.

### 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.

### 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.